From acd2cef276745cfcb40311134253f22905ed94fd Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Thu, 19 Oct 2023 17:21:53 +1100 Subject: [PATCH] Merge podjango.apps.cast into main podjango module It's much simpler if "podjango" is the name of the Django app with a single urls.py etc. The reason this is required is because podjango was originally a fully-blown Django website and now it's become a Django app within the Conservancy website. --- www/conservancy/settings.py | 3 +- www/podjango/{apps/cast => }/admin.py | 0 www/podjango/apps/cast/migrations/__init__.py | 0 .../apps/cast/templatetags/__init__.py | 0 www/podjango/apps/cast/urls.py | 83 ------------------- www/podjango/feeds.py | 11 ++- www/podjango/frontpage.py | 3 +- .../cast => }/migrations/0001_initial.py | 0 www/podjango/{apps => migrations}/__init__.py | 0 www/podjango/{apps/cast => }/models.py | 0 .../{apps/cast => templatetags}/__init__.py | 0 .../cast => }/templatetags/date_within.py | 0 www/podjango/urls.py | 59 +++++++++++-- www/podjango/{apps/cast => }/views.py | 0 14 files changed, 60 insertions(+), 99 deletions(-) rename www/podjango/{apps/cast => }/admin.py (100%) delete mode 100644 www/podjango/apps/cast/migrations/__init__.py delete mode 100644 www/podjango/apps/cast/templatetags/__init__.py delete mode 100644 www/podjango/apps/cast/urls.py rename www/podjango/{apps/cast => }/migrations/0001_initial.py (100%) rename www/podjango/{apps => migrations}/__init__.py (100%) rename www/podjango/{apps/cast => }/models.py (100%) rename www/podjango/{apps/cast => templatetags}/__init__.py (100%) rename www/podjango/{apps/cast => }/templatetags/date_within.py (100%) rename www/podjango/{apps/cast => }/views.py (100%) diff --git a/www/conservancy/settings.py b/www/conservancy/settings.py index 3585feb3..3da89373 100644 --- a/www/conservancy/settings.py +++ b/www/conservancy/settings.py @@ -97,8 +97,7 @@ INSTALLED_APPS = [ 'conservancy.apps.fundgoal', 'conservancy.apps.assignment', 'conservancy.apps.fossy', - 'podjango', # Here so that the templates are found - 'podjango.apps.cast', + 'podjango', ] DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' diff --git a/www/podjango/apps/cast/admin.py b/www/podjango/admin.py similarity index 100% rename from www/podjango/apps/cast/admin.py rename to www/podjango/admin.py diff --git a/www/podjango/apps/cast/migrations/__init__.py b/www/podjango/apps/cast/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/www/podjango/apps/cast/templatetags/__init__.py b/www/podjango/apps/cast/templatetags/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/www/podjango/apps/cast/urls.py b/www/podjango/apps/cast/urls.py deleted file mode 100644 index 5ccb5643..00000000 --- a/www/podjango/apps/cast/urls.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (C) 2008 Bradley M. Kuhn -# Copyright (C) 2006, 2007 Software Freedom Law Center, Inc. -# -# This software's license gives you freedom; you can copy, convey, -# propogate, redistribute and/or modify 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 . -# -from datetime import datetime - -from django.conf.urls import url -from django.views.generic.dates import DateDetailView, DayArchiveView, MonthArchiveView, YearArchiveView - -from .models import Cast, CastTag -from .views import custom_index, query - -extra_context = {} - -info_dict = { - 'queryset': Cast.objects.all(), - 'date_field': 'pub_date', - 'extra_context': extra_context, - 'template_name': 'podjango/cast/cast_detail.html', -} - -urlpatterns = [ - url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', DateDetailView.as_view(**info_dict), name='detail'), - url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', DayArchiveView.as_view(**info_dict), name='day-archive'), - url(r'^(?P\d{4})/(?P[a-z]{3})/$', MonthArchiveView.as_view(**info_dict), name='month-archive'), - url(r'^(?P\d{4})/$', YearArchiveView.as_view(**info_dict), name='year-archive'), -# FIXME HOW DO I MAKE THE SLUG WORK WITH NO DATES IN IT. -# (r'^(?P[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')), -] - -urlpatterns += [ - url(r'^all/$', custom_index, dict(info_dict, paginate_by=20), name='cast'), - url(r'^query/$', query, name='query'), -] - -# Code to display authors and tags on each blog page - - -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 diff --git a/www/podjango/feeds.py b/www/podjango/feeds.py index 71bb73b3..7d674b28 100644 --- a/www/podjango/feeds.py +++ b/www/podjango/feeds.py @@ -17,18 +17,17 @@ # "AGPLv3". If not, see . # +from datetime import datetime +import itertools +import operator + from django.contrib.sites.shortcuts import get_current_site from django.contrib.syndication.views import add_domain, Feed from django.utils.feedgenerator import Rss201rev2Feed -#from podjango.apps.staff.models import Person -from podjango.apps.cast.models import Cast - from django.shortcuts import render from django.conf import settings -from datetime import datetime -import itertools -import operator +from .models import Cast # FIXME: Settings here should not be hard-coded for given casts, but # should instead have settings from the main screen. diff --git a/www/podjango/frontpage.py b/www/podjango/frontpage.py index 5b3e6d58..d0faa3fd 100644 --- a/www/podjango/frontpage.py +++ b/www/podjango/frontpage.py @@ -18,9 +18,10 @@ # "AGPLv3". If not, see . from django.shortcuts import render -from podjango.apps.cast.models import Cast from datetime import datetime, timedelta +from .models import Cast + def view(request): """Cast front page view Performs all object queries necessary to render the front page. diff --git a/www/podjango/apps/cast/migrations/0001_initial.py b/www/podjango/migrations/0001_initial.py similarity index 100% rename from www/podjango/apps/cast/migrations/0001_initial.py rename to www/podjango/migrations/0001_initial.py diff --git a/www/podjango/apps/__init__.py b/www/podjango/migrations/__init__.py similarity index 100% rename from www/podjango/apps/__init__.py rename to www/podjango/migrations/__init__.py diff --git a/www/podjango/apps/cast/models.py b/www/podjango/models.py similarity index 100% rename from www/podjango/apps/cast/models.py rename to www/podjango/models.py diff --git a/www/podjango/apps/cast/__init__.py b/www/podjango/templatetags/__init__.py similarity index 100% rename from www/podjango/apps/cast/__init__.py rename to www/podjango/templatetags/__init__.py diff --git a/www/podjango/apps/cast/templatetags/date_within.py b/www/podjango/templatetags/date_within.py similarity index 100% rename from www/podjango/apps/cast/templatetags/date_within.py rename to www/podjango/templatetags/date_within.py diff --git a/www/podjango/urls.py b/www/podjango/urls.py index 0cfa8ab6..1bb70209 100644 --- a/www/podjango/urls.py +++ b/www/podjango/urls.py @@ -21,18 +21,31 @@ from django.conf import settings from django.conf.urls import url, include from django.contrib import admin from django.contrib.syndication.views import Feed +from django.views.generic.dates import DateDetailView, DayArchiveView, MonthArchiveView, YearArchiveView -from podjango.feeds import feed_dict, view, Mp3CastFeed, OggCastFeed -from podjango import frontpage - -#handler404 = 'modpythoncustom.view404' - -admin.autodiscover() +from . import frontpage +from .feeds import feed_dict, view, Mp3CastFeed, OggCastFeed +from .models import Cast, CastTag +from .views import custom_index, query app_name = 'podjango' + +extra_context = {} +info_dict = { + 'queryset': Cast.objects.all(), + 'date_field': 'pub_date', + 'extra_context': extra_context, + 'template_name': 'podjango/cast/cast_detail.html', +} + urlpatterns = [ url(r'^$', frontpage.view), - url(r'', include('podjango.apps.cast.urls')), + url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', DateDetailView.as_view(**info_dict), name='detail'), + url(r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', DayArchiveView.as_view(**info_dict), name='day-archive'), + url(r'^(?P\d{4})/(?P[a-z]{3})/$', MonthArchiveView.as_view(**info_dict), name='month-archive'), + url(r'^(?P\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'), url(r'^feeds/cast-ogg/$', OggCastFeed(), name='feed-ogg'), url(r'^feeds/cast-mp3/$', Mp3CastFeed(), name='feed-mp3'), url(r'^feeds/$', view, name='feeds'), @@ -41,3 +54,35 @@ urlpatterns = [ 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 diff --git a/www/podjango/apps/cast/views.py b/www/podjango/views.py similarity index 100% rename from www/podjango/apps/cast/views.py rename to www/podjango/views.py