diff --git a/entries/urls.py b/entries/urls.py index f7b5dfe..162dc9f 100644 --- a/entries/urls.py +++ b/entries/urls.py @@ -1,5 +1,6 @@ from django.conf.urls import url -from . import feeds, kinds, views +from . import kinds +from .views import feeds, lists, perma from lemoncurry import breadcrumbs as crumbs @@ -18,7 +19,7 @@ app_name = 'entries' urlpatterns = [ url('^atom$', feeds.AtomHomeEntries(), name='atom'), url('^rss$', feeds.RssHomeEntries(), name='rss'), - url(to_pat('cats', slug, page), views.cat, name='cat'), + url(to_pat('cats', slug, page), lists.by_cat, name='cat'), ] crumbs.add(prefix('cat'), parent='home:index') @@ -28,11 +29,11 @@ for k in kinds.all: kind = k.plural id = r'/(?P\d+)' urlpatterns += ( - url(to_pat(kind, page), views.index, name=k.index, kwargs={'kind': k}), + url(to_pat(kind, page), lists.by_kind, name=k.index, kwargs={'kind': k}), url(to_pat(kind, '/atom'), feeds.AtomByKind(k), name=k.atom), url(to_pat(kind, '/rss'), feeds.RssByKind(k), name=k.rss), - url(to_pat(kind, id, slug, '/amp'), views.entry_amp, name=k.entry_amp), - url(to_pat(kind, id, slug), views.entry, name=k.entry), + url(to_pat(kind, id, slug, '/amp'), perma.entry_amp, name=k.entry_amp), + url(to_pat(kind, id, slug), perma.entry, name=k.entry), ) crumbs.add(prefix(k.index), label=k.plural, parent='home:index') diff --git a/entries/views/__init__.py b/entries/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/entries/feeds.py b/entries/views/feeds.py similarity index 97% rename from entries/feeds.py rename to entries/views/feeds.py index 3f2cbc4..1c4a2ee 100644 --- a/entries/feeds.py +++ b/entries/views/feeds.py @@ -4,8 +4,8 @@ from django.urls import reverse from django.utils.feedgenerator import Atom1Feed from urllib.parse import urljoin from lemoncurry.templatetags.markdown import markdown -from .kinds import on_home -from .models import Entry +from ..kinds import on_home +from ..models import Entry class EntriesFeed(Feed): diff --git a/entries/views.py b/entries/views/lists.py similarity index 59% rename from entries/views.py rename to entries/views/lists.py index 5678b56..c363b32 100644 --- a/entries/views.py +++ b/entries/views/lists.py @@ -1,12 +1,12 @@ from annoying.decorators import render_to -from django.shortcuts import get_object_or_404, redirect +from django.shortcuts import get_object_or_404 from django.urls import reverse -from .models import Entry, Cat -from .pagination import paginate +from ..models import Entry, Cat +from ..pagination import paginate @render_to('entries/index.html') -def index(request, kind, page): +def by_kind(request, kind, page): def url(page): kwargs = {'page': page} if page > 1 else {} return reverse('entries:' + kind.index, kwargs=kwargs) @@ -25,7 +25,7 @@ def index(request, kind, page): @render_to('entries/index.html') -def cat(request, slug, page): +def by_cat(request, slug, page): def url(page): kwargs = {'slug': slug} if page > 1: @@ -42,23 +42,3 @@ def cat(request, slug, page): 'entries': entries, 'title': '#' + cat.name, } - - -@render_to('entries/entry.html') -def entry(request, id, slug=None): - entry = Entry.objects.get(pk=id) - if request.path != entry.url: - return redirect(entry.url, permanent=True) - return { - 'entry': entry, - 'title': entry.title, - 'meta': entry.as_meta(request) - } - - -@render_to('entries/entry_amp.html') -def entry_amp(request, id, slug=None): - entry = Entry.objects.get(pk=id) - if request.path != entry.amp_url: - return redirect(entry.amp_url, permanent=True) - return {'entry': entry} diff --git a/entries/views/perma.py b/entries/views/perma.py new file mode 100644 index 0000000..c3a8442 --- /dev/null +++ b/entries/views/perma.py @@ -0,0 +1,23 @@ +from annoying.decorators import render_to +from django.shortcuts import redirect +from ..models import Entry + + +@render_to('entries/entry.html') +def entry(request, id, slug=None): + entry = Entry.objects.get(pk=id) + if request.path != entry.url: + return redirect(entry.url, permanent=True) + return { + 'entry': entry, + 'title': entry.title, + 'meta': entry.as_meta(request) + } + + +@render_to('entries/entry_amp.html') +def entry_amp(request, id, slug=None): + entry = Entry.objects.get(pk=id) + if request.path != entry.amp_url: + return redirect(entry.amp_url, permanent=True) + return {'entry': entry}