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):
|
2023-08-10 02:52:37 -04:00
|
|
|
kwargs = {"kind": self}
|
2018-03-07 21:49:02 -05:00
|
|
|
if page > 1:
|
2023-08-10 02:52:37 -04:00
|
|
|
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):
|
2023-08-10 02:52:37 -04:00
|
|
|
return self.plural + "_entry"
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2017-10-31 18:29:59 -04:00
|
|
|
@property
|
|
|
|
def atom(self):
|
2023-08-10 02:52:37 -04:00
|
|
|
return reverse("entries:atom_by_kind", kwargs={"kind": self})
|
2017-10-31 18:29:59 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def rss(self):
|
2023-08-10 02:52:37 -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(
|
2023-08-10 02:52:37 -04:00
|
|
|
id="note",
|
|
|
|
icon="fas fa-paper-plane",
|
|
|
|
plural="notes",
|
2017-10-25 18:01:36 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
Article = Entry(
|
2023-08-10 02:52:37 -04:00
|
|
|
id="article",
|
|
|
|
icon="fas fa-file-alt",
|
|
|
|
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(
|
2023-08-10 02:52:37 -04:00
|
|
|
id="photo",
|
|
|
|
icon="fas fa-camera",
|
|
|
|
plural="photos",
|
2017-10-27 01:04:05 -04:00
|
|
|
)
|
2017-10-24 21:01:52 -04:00
|
|
|
|
2017-11-12 16:42:31 -05:00
|
|
|
Reply = Entry(
|
2023-08-10 02:52:37 -04:00
|
|
|
id="reply",
|
|
|
|
icon="fas fa-comment",
|
|
|
|
plural="replies",
|
2017-11-12 16:54:23 -05:00
|
|
|
on_home=False,
|
2017-11-12 16:42:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
Like = Entry(
|
2023-08-10 02:52:37 -04:00
|
|
|
id="like",
|
|
|
|
icon="fas fa-heart",
|
|
|
|
plural="likes",
|
2017-11-12 16:54:23 -05:00
|
|
|
on_home=False,
|
2017-11-12 16:42:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
Repost = Entry(
|
2023-08-10 02:52:37 -04:00
|
|
|
id="repost",
|
|
|
|
icon="fas fa-retweet",
|
|
|
|
plural="reposts",
|
2017-11-12 16:42:31 -05:00
|
|
|
)
|
|
|
|
|
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:
|
2023-08-10 02:52:37 -04:00
|
|
|
regex = "|".join(k.plural for k in all)
|
2018-05-03 22:13:52 -04:00
|
|
|
|
|
|
|
def to_python(self, plural):
|
|
|
|
return from_plural[plural]
|
|
|
|
|
|
|
|
def to_url(self, k):
|
|
|
|
return k.plural
|