2023-10-05 08:17:55 +00:00
|
|
|
# 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/>.
|
|
|
|
|
2024-02-23 04:02:04 +00:00
|
|
|
import datetime
|
|
|
|
|
2023-10-05 08:17:55 +00:00
|
|
|
from django.conf import settings
|
2024-02-23 04:02:04 +00:00
|
|
|
from django.conf.urls import url
|
2023-10-19 22:52:39 +00:00
|
|
|
from django.views.generic.dates import (
|
|
|
|
DateDetailView,
|
|
|
|
DayArchiveView,
|
|
|
|
MonthArchiveView,
|
|
|
|
YearArchiveView,
|
|
|
|
)
|
2023-10-05 08:17:55 +00:00
|
|
|
|
2023-10-19 06:21:53 +00:00
|
|
|
from . import frontpage
|
2024-02-23 04:02:04 +00:00
|
|
|
from .feeds import Mp3CastFeed, OggCastFeed, view
|
2023-10-19 06:21:53 +00:00
|
|
|
from .models import Cast, CastTag
|
|
|
|
from .views import custom_index, query
|
2023-10-05 08:17:55 +00:00
|
|
|
|
2023-10-19 06:21:53 +00:00
|
|
|
app_name = 'podjango'
|
2023-10-05 08:17:55 +00:00
|
|
|
|
2023-10-19 06:21:53 +00:00
|
|
|
extra_context = {}
|
|
|
|
info_dict = {
|
|
|
|
'queryset': Cast.objects.all(),
|
|
|
|
'date_field': 'pub_date',
|
|
|
|
'extra_context': extra_context,
|
|
|
|
'template_name': 'podjango/cast/cast_detail.html',
|
|
|
|
}
|
2023-10-05 08:17:55 +00:00
|
|
|
|
|
|
|
urlpatterns = [
|
2023-10-19 06:49:57 +00:00
|
|
|
url(r'^$', frontpage.view, name='cast-home'),
|
2023-10-19 06:21:53 +00:00
|
|
|
url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', DateDetailView.as_view(**info_dict), name='detail'),
|
|
|
|
url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', DayArchiveView.as_view(**info_dict), name='day-archive'),
|
|
|
|
url(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', MonthArchiveView.as_view(**info_dict), name='month-archive'),
|
|
|
|
url(r'^(?P<year>\d{4})/$', YearArchiveView.as_view(**info_dict), name='year-archive'),
|
|
|
|
url(r'^all/$', custom_index, dict(info_dict, paginate_by=20), name='cast'),
|
|
|
|
url(r'^query/$', query, name='query'),
|
2024-02-07 03:25:45 +00:00
|
|
|
url(r'^feeds/ogg/$', OggCastFeed(), name='feed-ogg'),
|
|
|
|
url(r'^feeds/mp3/$', Mp3CastFeed(), name='feed-mp3'),
|
2023-10-05 08:17:55 +00:00
|
|
|
url(r'^feeds/$', view, name='feeds'),
|
|
|
|
]
|
|
|
|
|
|
|
|
if settings.DEBUG:
|
2024-02-23 04:06:59 +00:00
|
|
|
from django.conf.urls.static import static
|
|
|
|
urlpatterns += static('/', document_root='podjango/static')
|
2023-10-19 06:21:53 +00:00
|
|
|
|
2024-02-23 04:02:04 +00:00
|
|
|
|
2023-10-19 06:21:53 +00:00
|
|
|
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
|
|
|
|
|
2024-02-23 04:02:04 +00:00
|
|
|
|
2023-10-19 06:21:53 +00:00
|
|
|
# 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
|