Make entry kinds a teeny bit easier to manage by moving some of the smarts into the actual kinds.Entry class
This commit is contained in:
parent
dc99e7a39b
commit
f39782346f
3 changed files with 38 additions and 21 deletions
|
|
@ -1,22 +1,41 @@
|
|||
class Entry:
|
||||
fields = ()
|
||||
|
||||
@classmethod
|
||||
def has(cls, field):
|
||||
return field in cls.fields
|
||||
def has(self, field):
|
||||
return field in self.fields
|
||||
|
||||
def __init__(self, id, plural, icon, fields=()):
|
||||
self.id = id
|
||||
self.plural = plural
|
||||
self.icon = icon
|
||||
self.fields = fields
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self.plural + '_index'
|
||||
|
||||
@property
|
||||
def entry(self):
|
||||
return self.plural + '_entry'
|
||||
|
||||
@property
|
||||
def entry_slug(self):
|
||||
return self.entry + '_slug'
|
||||
|
||||
|
||||
class Note(Entry):
|
||||
id = 'note'
|
||||
icon = 'fa fa-paper-plane'
|
||||
plural = 'notes'
|
||||
Note = Entry(
|
||||
id='note',
|
||||
icon='fa fa-paper-plane',
|
||||
plural='notes',
|
||||
)
|
||||
|
||||
|
||||
class Article(Entry):
|
||||
id = 'article'
|
||||
icon = 'fa fa-file-text'
|
||||
plural = 'articles'
|
||||
fields = ('slug', 'name')
|
||||
Article = Entry(
|
||||
id='article',
|
||||
icon='fa fa-file-text',
|
||||
plural='articles',
|
||||
fields=('slug', 'name'),
|
||||
)
|
||||
|
||||
|
||||
all = (Note, Article)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue