From 827b0c6e50ce147c3ecbc1a3e7c82a6489709d53 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 6 Jun 2020 09:52:35 +0200 Subject: [PATCH] Changed pubdate to timestamp --- cps/db.py | 2 +- cps/jinjia.py | 10 +++------- cps/templates/detail.html | 2 +- cps/ub.py | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cps/db.py b/cps/db.py index 1296c84a..01d50605 100644 --- a/cps/db.py +++ b/cps/db.py @@ -269,7 +269,7 @@ class Books(Base): sort = Column(String(collation='NOCASE')) author_sort = Column(String(collation='NOCASE')) timestamp = Column(TIMESTAMP, default=datetime.utcnow) - pubdate = Column(String) # , default=datetime.utcnow) + pubdate = Column(TIMESTAMP, default=DEFAULT_PUBDATE) series_index = Column(String, nullable=False, default="1.0") last_modified = Column(TIMESTAMP, default=datetime.utcnow) path = Column(String, default="", nullable=False) diff --git a/cps/jinjia.py b/cps/jinjia.py index 28c2621a..b1b42939 100644 --- a/cps/jinjia.py +++ b/cps/jinjia.py @@ -76,22 +76,18 @@ def mimetype_filter(val): @jinjia.app_template_filter('formatdate') def formatdate_filter(val): try: - conformed_timestamp = re.sub(r"[:]|([-](?!((\d{2}[:]\d{2})|(\d{4}))$))", '', val) - formatdate = datetime.datetime.strptime(conformed_timestamp[:15], "%Y%m%d %H%M%S") - return format_date(formatdate, format='medium', locale=get_locale()) + return format_date(val, format='medium', locale=get_locale()) except AttributeError as e: log.error('Babel error: %s, Current user locale: %s, Current User: %s', e, current_user.locale, current_user.nickname ) - return formatdate + return val @jinjia.app_template_filter('formatdateinput') def format_date_input(val): - conformed_timestamp = re.sub(r"[:]|([-](?!((\d{2}[:]\d{2})|(\d{4}))$))", '', val) - date_obj = datetime.datetime.strptime(conformed_timestamp[:15], "%Y%m%d %H%M%S") - input_date = date_obj.isoformat().split('T', 1)[0] # Hack to support dates <1900 + input_date = val.isoformat().split('T', 1)[0] # Hack to support dates <1900 return '' if input_date == "0101-01-01" else input_date diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 6edf1677..4a0fbe02 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -160,7 +160,7 @@ {% endif %} - {% if entry.pubdate[:10] != '0101-01-01' %} + {% if (entry.pubdate|string)[:10] != '0101-01-01' %}

{{_('Published')}}: {{entry.pubdate|formatdate}}

diff --git a/cps/ub.py b/cps/ub.py index 3dfb5347..c39b96a6 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -109,7 +109,7 @@ def get_sidebar_config(kwargs=None): "visibility": constants.SIDEBAR_ARCHIVED, 'public': (not g.user.is_anonymous), "page": "archived", "show_text": _('Show archived books'), "config_show": content}) sidebar.append( - {"glyph": "glyphicon-th-list", "text": _('Books List'), "link": 'web.books_list', "id": "list", + {"glyph": "glyphicon-th-list", "text": _('Books List'), "link": 'web.books_table', "id": "list", "visibility": constants.SIDEBAR_LIST, 'public': (not g.user.is_anonymous), "page": "list", "show_text": _('Show Books List'), "config_show": content})