2018-05-03 22:13:52 -04:00
|
|
|
from django.urls import path, register_converter, reverse
|
2018-03-06 23:46:21 -05:00
|
|
|
from . import kinds
|
|
|
|
from .views import feeds, lists, perma
|
2017-10-27 01:16:08 -04:00
|
|
|
from lemoncurry import breadcrumbs as crumbs
|
|
|
|
|
2018-05-03 22:13:52 -04:00
|
|
|
register_converter(kinds.EntryKindConverter, 'kind')
|
|
|
|
|
2017-10-27 01:16:08 -04:00
|
|
|
|
2017-10-27 23:01:31 -04:00
|
|
|
def to_pat(*args):
|
|
|
|
return '^{0}$'.format(''.join(args))
|
2017-10-27 01:16:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
def prefix(route):
|
|
|
|
return app_name + ':' + route
|
|
|
|
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
id = r'/(?P<id>\d+)'
|
|
|
|
kind = r'(?P<kind>{0})'.format('|'.join(k.plural for k in kinds.all))
|
|
|
|
page = r'(?:/page/(?P<page>\d+))?'
|
2017-12-12 02:35:13 -05:00
|
|
|
slug = r'/(?P<slug>[^/]+)'
|
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
slug_opt = '(?:' + slug + ')?'
|
|
|
|
|
2017-10-24 21:01:52 -04:00
|
|
|
app_name = 'entries'
|
2018-03-07 21:49:02 -05:00
|
|
|
urlpatterns = (
|
2018-05-03 22:13:52 -04:00
|
|
|
path('atom', feeds.AtomHomeEntries(), name='atom'),
|
|
|
|
path('rss', feeds.RssHomeEntries(), name='rss'),
|
|
|
|
path('cats/<slug:slug>', lists.by_cat, name='cat'),
|
|
|
|
path('cats/<slug:slug>/page/<int:page>', lists.by_cat, name='cat'),
|
|
|
|
path('<kind:kind>', lists.by_kind, name='index'),
|
|
|
|
path('<kind:kind>/page/<int:page>', lists.by_kind, name='index'),
|
|
|
|
path('<kind:kind>/atom', feeds.AtomByKind(), name='atom_by_kind'),
|
|
|
|
path('<kind:kind>/rss', feeds.RssByKind(), name='rss_by_kind'),
|
|
|
|
|
|
|
|
path('<kind:kind>/<int:id>', perma.entry, name='entry'),
|
|
|
|
path('<kind:kind>/<int:id>/<slug:slug>', perma.entry, name='entry'),
|
2018-03-07 21:49:02 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class IndexCrumb(crumbs.Crumb):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(prefix('index'), parent='home:index')
|
2017-11-19 18:59:03 -05:00
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
@property
|
2018-05-03 22:13:52 -04:00
|
|
|
def kind(self):
|
2018-03-07 21:49:02 -05:00
|
|
|
return self.match.kwargs['kind']
|
|
|
|
|
2018-05-03 22:13:52 -04:00
|
|
|
@property
|
|
|
|
def label(self):
|
|
|
|
return self.kind.plural
|
|
|
|
|
2018-03-07 21:49:02 -05:00
|
|
|
@property
|
|
|
|
def url(self):
|
2018-05-03 22:13:52 -04:00
|
|
|
return reverse(prefix('index'), kwargs={'kind': self.kind})
|
2018-03-07 21:49:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
crumbs.add(prefix('cat'), parent='home:index')
|
|
|
|
crumbs.add(IndexCrumb())
|
|
|
|
crumbs.add(prefix('entry'), parent=prefix('index'))
|