2018-03-07 21:49:02 -05:00
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
|
2017-10-24 21:31:08 -04:00
|
|
|
class Entry:
|
2017-11-12 16:54:23 -05:00
|
|
|
def __init__(self, id, plural, icon, on_home=True, slug=False):
|
2017-10-25 18:01:36 -04:00
|
|
|
self.id = id
|
|
|
|
self.plural = plural
|
|
|
|
self.icon = icon
|
2017-11-12 16:54:23 -05:00
|
|
|
self.on_home = on_home
|
2017-10-27 01:51:46 -04:00
|
|
|
self.slug = slug
|
2017-10-24 21:31:08 -04:00
|
|
|
|
2017-10-25 18:01:36 -04:00
|
|
|
@property
|
|
|
|
def index(self):
|
2018-03-07 21:49:02 -05:00
|
|
|
return self.index_page()
|
|
|
|
|
|
|
|
def index_page(self, page=0):
|
2018-05-03 22:13:52 -04:00
|
|
|
kwargs = {'kind': self}
|
2018-03-07 21:49:02 -05:00
|
|
|
if page > 1:
|
|
|
|
kwargs['page'] = page
|
|
|
|
return reverse('entries:index', kwargs=kwargs)
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2017-10-25 18:01:36 -04:00
|
|
|
@property
|
|
|
|
def entry(self):
|
|
|
|
return self.plural + '_entry'
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2018-01-12 22:49:38 -05:00
|
|
|
@property
|
|
|
|
def entry_amp(self):
|
|
|
|
return self.entry + '_amp'
|
|
|
|
|
2017-10-31 18:29:59 -04:00
|
|
|
@property
|
|
|
|
def atom(self):
|
2018-05-03 22:13:52 -04:00
|
|
|
return reverse('entries:atom_by_kind', kwargs={'kind': self})
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def rss(self):
|
2018-05-03 22:13:52 -04:00
|
|
|
return reverse('entries:rss_by_kind', kwargs={'kind': self})
|
2017-10-31 18:29:59 -04:00
|
|
|
|
2017-10-25 18:01:36 -04:00
|
|
|
|
|
|
|
Note = Entry(
|
|
|
|
id='note',
|
2017-12-05 22:07:59 -05:00
|
|
|
icon='fas fa-paper-plane',
|
2017-10-25 18:01:36 -04:00
|
|
|
plural='notes',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
Article = Entry(
|
|
|
|
id='article',
|
2017-12-05 22:07:59 -05:00
|
|
|
icon='fas fa-file-alt',
|
2017-10-25 18:01:36 -04:00
|
|
|
plural='articles',
|
2017-10-27 01:51:46 -04:00
|
|
|
slug=True,
|
2017-10-25 18:01:36 -04:00
|
|
|
)
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2017-10-27 01:04:05 -04:00
|
|
|
Photo = Entry(
|
|
|
|
id='photo',
|
2017-12-05 22:07:59 -05:00
|
|
|
icon='fas fa-camera',
|
2017-10-27 01:04:05 -04:00
|
|
|
plural='photos',
|
|
|
|
)
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2017-11-12 16:42:31 -05:00
|
|
|
Reply = Entry(
|
|
|
|
id='reply',
|
2017-12-05 22:07:59 -05:00
|
|
|
icon='fas fa-comment',
|
2017-11-12 16:42:31 -05:00
|
|
|
plural='replies',
|
2017-11-12 16:54:23 -05:00
|
|
|
on_home=False,
|
2017-11-12 16:42:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
Like = Entry(
|
|
|
|
id='like',
|
2017-12-05 22:07:59 -05:00
|
|
|
icon='fas fa-heart',
|
2017-11-12 16:42:31 -05:00
|
|
|
plural='likes',
|
2017-11-12 16:54:23 -05:00
|
|
|
on_home=False,
|
2017-11-12 16:42:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
Repost = Entry(
|
|
|
|
id='repost',
|
2017-12-05 22:07:59 -05:00
|
|
|
icon='fas fa-retweet',
|
2017-11-12 16:42:31 -05:00
|
|
|
plural='reposts',
|
|
|
|
)
|
|
|
|
|
2017-11-19 19:26:15 -05:00
|
|
|
all = (Note, Article, Photo)
|
2017-11-12 16:56:20 -05:00
|
|
|
on_home = {k.id for k in all if k.on_home}
|
2017-10-24 21:01:52 -04:00
|
|
|
from_id = {k.id: k for k in all}
|
|
|
|
from_plural = {k.plural: k for k in all}
|
2018-05-03 22:13:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
class EntryKindConverter:
|
|
|
|
regex = '|'.join(k.plural for k in all)
|
|
|
|
|
|
|
|
def to_python(self, plural):
|
|
|
|
return from_plural[plural]
|
|
|
|
|
|
|
|
def to_url(self, k):
|
|
|
|
return k.plural
|