Files
@ 541f423a3d1c
Branch filter:
Location: website/conservancy/podjango/urls.py - annotation
541f423a3d1c
3.7 KiB
text/x-python
Add transparent background to T-shirt image
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 c0acfde9c303 75e3ab4d35f0 75e3ab4d35f0 c0acfde9c303 956f8c6fdaad 2a99a0c81a5d 956f8c6fdaad c0acfde9c303 acd2cef27674 75e3ab4d35f0 956f8c6fdaad 956f8c6fdaad c0acfde9c303 acd2cef27674 c0acfde9c303 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 c0acfde9c303 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad c0acfde9c303 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad 956f8c6fdaad c0acfde9c303 c0acfde9c303 c0acfde9c303 49e3c43299e8 49e3c43299e8 acd2cef27674 75e3ab4d35f0 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 75e3ab4d35f0 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 acd2cef27674 | # Copyright 2010 Bradley M. Kuhn <bkuhn@ebb.org>
# Copyright 2005-2008 James Garrison
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute, modify and/or redistribute modified versions of
# this program under the terms of the GNU Affero General Public License
# (AGPL) as published by the Free Software Foundation (FSF), either
# version 3 of the License, or (at your option) any later version of the
# AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
import datetime
from django.conf import settings
from django.shortcuts import get_object_or_404
from django.urls import path
from django.views.generic.dates import DateDetailView
from . import frontpage
from .feeds import Mp3CastFeed, OggCastFeed, view
from .models import Cast, CastTag, Podcast
from . import views
app_name = 'podjango'
extra_context = {}
info_dict = {
'date_field': 'pub_date',
'extra_context': extra_context,
}
class PodcastDateDetailView(DateDetailView):
date_field = 'pub_date'
model = Cast
def get(self, request, podcast_slug, *args, **kwargs):
self.podcast = get_object_or_404(Podcast, slug=podcast_slug)
return super().get(request, *args, **kwargs)
def get_queryset(self):
return super().get_queryset().filter(podcast=self.podcast)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['podcast'] = self.podcast
return context
urlpatterns = [
path('', views.podcasts, name='podcasts'),
path('<slug:podcast_slug>/', frontpage.view, name='cast-home'),
path(
'<slug:podcast_slug>/<int:year>/<month>/<int:day>/<slug:slug>/',
PodcastDateDetailView.as_view(
template_name='podjango/cast_detail.html',
),
name='detail'
),
path('<slug:podcast_slug>/all/', views.custom_index, info_dict, name='cast'),
path('<slug:podcast_slug>/feeds/ogg/', OggCastFeed(), name='feed-ogg'),
path('<slug:podcast_slug>/feeds/mp3/', Mp3CastFeed(), name='feed-mp3'),
path('<slug:podcast_slug>/feeds/', view, name='feeds'),
]
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static('/', document_root='podjango/static')
def all_tags_by_use_amount():
"""Returns all tags with an added 'cnt' attribute (how many times used)
Also sorts the tags so most-used tags appear first.
"""
# tally use amount
retval = []
current = None
for obj in CastTag.objects.filter(cast__pub_date__lte=datetime.now(),
cast__isnull=False).order_by('label'):
if current is not None and obj.id == current.id:
current.cnt += 1
else:
if current is not None:
retval.append(current)
current = obj
current.cnt = 1
if current is not None:
retval.append(current)
# sort and return
retval.sort(key=lambda x: -x.cnt)
return retval
# The functions are passed to the context uncalled so they will be
# called for each web request. If we want to only make these database
# queries a single time when a web server process begins, call both
# functions below (i.e. make both lines below end in '()')
extra_context['all_tags'] = all_tags_by_use_amount
|