Refactor how the routing for different kinds of entry works - this will make implementing webmentions easier, hopefully?
This commit is contained in:
parent
c359b7640e
commit
9580068c5b
12 changed files with 136 additions and 73 deletions
|
@ -4,7 +4,7 @@ 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 ..kinds import from_plural, on_home
|
||||
from ..models import Entry
|
||||
|
||||
|
||||
|
@ -36,26 +36,26 @@ class EntriesFeed(Feed):
|
|||
|
||||
|
||||
class RssByKind(EntriesFeed):
|
||||
def __init__(self, kind):
|
||||
self.kind = kind
|
||||
def get_object(self, request, kind):
|
||||
return from_plural[kind]
|
||||
|
||||
def title(self):
|
||||
def title(self, kind):
|
||||
return "{0} ~ {1}".format(
|
||||
self.kind.plural,
|
||||
kind.plural,
|
||||
Site.objects.get_current().name,
|
||||
)
|
||||
|
||||
def link(self):
|
||||
return reverse('entries:' + self.kind.index)
|
||||
def link(self, kind):
|
||||
return kind.index
|
||||
|
||||
def description(self):
|
||||
def description(self, kind):
|
||||
return "all {0} at {1}".format(
|
||||
self.kind.plural,
|
||||
kind.plural,
|
||||
Site.objects.get_current().name,
|
||||
)
|
||||
|
||||
def items(self):
|
||||
return Entry.objects.filter(kind=self.kind.id)
|
||||
def items(self, kind):
|
||||
return Entry.objects.filter(kind=kind.id)
|
||||
|
||||
|
||||
class AtomByKind(RssByKind):
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
from annoying.decorators import render_to
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from .. import kinds
|
||||
from ..models import Entry, Cat
|
||||
from ..pagination import paginate
|
||||
|
||||
|
||||
@render_to('entries/index.html')
|
||||
def by_kind(request, kind, page):
|
||||
def url(page):
|
||||
kwargs = {'page': page} if page > 1 else {}
|
||||
return reverse('entries:' + kind.index, kwargs=kwargs)
|
||||
|
||||
kind = kinds.from_plural[kind]
|
||||
entries = Entry.objects.filter(kind=kind.id)
|
||||
entries = paginate(queryset=entries, reverse=url, page=page)
|
||||
entries = paginate(queryset=entries, reverse=kind.index_page, page=page)
|
||||
if hasattr(entries, 'content'):
|
||||
return entries
|
||||
|
||||
return {
|
||||
'entries': entries,
|
||||
'atom': 'entries:' + kind.atom,
|
||||
'rss': 'entries:' + kind.rss,
|
||||
'atom': kind.atom,
|
||||
'rss': kind.rss,
|
||||
'title': kind.plural,
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from ..models import Entry
|
|||
|
||||
|
||||
@render_to('entries/entry.html')
|
||||
def entry(request, id, slug=None):
|
||||
def entry(request, kind, id, slug=None):
|
||||
entry = Entry.objects.get(pk=id)
|
||||
if request.path != entry.url:
|
||||
return redirect(entry.url, permanent=True)
|
||||
|
@ -16,7 +16,7 @@ def entry(request, id, slug=None):
|
|||
|
||||
|
||||
@render_to('entries/entry_amp.html')
|
||||
def entry_amp(request, id, slug=None):
|
||||
def entry_amp(request, kind, id, slug=None):
|
||||
entry = Entry.objects.get(pk=id)
|
||||
if request.path != entry.amp_url:
|
||||
return redirect(entry.amp_url, permanent=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue