Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions mygpo/directory/templates/directory/trending.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends "base.html" %}

{% load i18n %}
{% load podcasts %}
{% load charts %}
{% load math %}
{% load utils %}
{% load static %}

{% load menu %}
{% block mainmenu %}{{ "/trending/"|main_menu }}{% endblock %}
{% block sectionmenu %}{{ "/trending/"|section_menu }}{% endblock %}

{% block title %}{% trans "Trending Podcasts" %}{% endblock %}

{% block header %}
<h1>{% trans "Trending Podcasts" %}</h1>
{% endblock %}

{% block content %}
<table class="list">
<tr>
<th></th>
<th></th>
<th></th>
<th>{% trans "Podcast" %}</th>
<th>{% trans "Subscribers" %}</th>
</tr>
{% for podcast in podcasts %}
<tr>
<td class="numeric toplist-pos">
{% ifchanged podcast.subscriber_count %}
{{ forloop.counter }}
{% endifchanged %}
</td>
<td class="oldposition">
</td>
<td class="logo">{{ podcast|podcast_logo }}</td>
<td>
{% podcast_group_link podcast %}
</td>
<td>{% vertical_bar podcast.subscriber_count max_subscribers %}</td>
</tr>
{% empty %}
<tr>
<td colspan="5">
{% trans "Currently not available" %}
</td>
</tr>
{% endfor %}
</table>

{% endblock %}


{% block sidebar %}

<div class="well">
<h4>{% trans "Client Access" %}</h4>

<p>Access <a href="{% url "toplist-opml" 30 "opml" %}">http://{{ view.site }}{% url "toplist-opml" 30 "opml" %}</a> for the Top-30.</p>
</div>

{% endblock %}
1 change: 1 addition & 0 deletions mygpo/directory/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

urlpatterns = [
path('toplist/', views.PodcastToplistView.as_view(), name='toplist'),
path('trending/', views.TrendingPodcastsView.as_view(), name='trending'),
path(
'toplist/episodes', views.EpisodeToplistView.as_view(), name='episode-toplist'
),
Expand Down
26 changes: 26 additions & 0 deletions mygpo/directory/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import ceil
from collections import Counter
from datetime import datetime, timedelta

from django.http import HttpResponseNotFound, Http404, HttpResponseRedirect
from django.urls import reverse
Expand Down Expand Up @@ -401,3 +402,28 @@ def licenses(self):

counter = Counter({l['license']: l['id__count'] for l in values})
return counter.most_common()


class TrendingPodcastsView(PodcastListView):
""" Podcast with most recent subscribers """

template_name = 'directory/trending.html'

def get_queryset(self):
starttime = datetime.utcnow() - timedelta(days=7)
max_entries = 20

podcasts = Podcast.objects.annotate(
subscriptions=Sum(
Case(
When(subscription__created__gte=starttime, then=Value(1)),
default=Value(0),
output_field=IntegerField(),
)
)
)

trending = podcasts.exclude(subscriptions__lt=1)
trending = trending.order_by('-subscriptions')

return trending
1 change: 1 addition & 0 deletions mygpo/web/templatetags/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
_('Discover'),
(
('/directory/', _('Directory')),
('/trending/', _('Trending')),
('/podcast/', _('Podcast')),
('/search/', _('Search')),
('/missing/', _('Missing Podcast')),
Expand Down