Forgot file?
parent
45df3bd197
commit
d828ef7d76
@ -0,0 +1,33 @@
|
|||||||
|
from typing import List
|
||||||
|
from datetime import date, datetime
|
||||||
|
|
||||||
|
def find_category (categories, slug):
|
||||||
|
for (category, articles) in categories:
|
||||||
|
if category.slug == slug:
|
||||||
|
return (category, articles)
|
||||||
|
|
||||||
|
return (None, None)
|
||||||
|
|
||||||
|
def get_category_articles (categories, slug):
|
||||||
|
category, articles = find_category(categories, slug)
|
||||||
|
|
||||||
|
if category:
|
||||||
|
return articles
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
def display_if_set (value, label):
|
||||||
|
if value:
|
||||||
|
if isinstance(value, (list, tuple)):
|
||||||
|
value = ', '.join(value)
|
||||||
|
|
||||||
|
if isinstance(value, (date)):
|
||||||
|
value = date.strftime(value, '%d-%m-%Y')
|
||||||
|
|
||||||
|
if isinstance(value, (datetime)):
|
||||||
|
value = date.strftime(value, '%d-%m-%Y %H:%i')
|
||||||
|
|
||||||
|
|
||||||
|
return '<dt>{}</dt><dd>{}</dd>'.format(label, value)
|
||||||
|
else:
|
||||||
|
return ''
|
Loading…
Reference in New Issue