You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
764 B
Python
33 lines
764 B
Python
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 '' |