From e76b80efb00fb08c576ab63cac8c47ba2fd10d0e Mon Sep 17 00:00:00 2001 From: Anselm Bradford Date: Fri, 11 Aug 2017 11:41:37 -0400 Subject: [PATCH 1/5] Fixes #877 - Updates date format --- cfgov/jinja2/v1/_includes/macros/time.html | 5 +++-- cfgov/jinja2/v1/_includes/organisms/post-preview.html | 4 +++- cfgov/jinja2/v1/ask-cfpb/answer-page.html | 6 ++++-- cfgov/unprocessed/css/calendar-icon.less | 2 +- cfgov/unprocessed/css/organisms/item-introduction.less | 2 +- cfgov/unprocessed/css/organisms/post-preview.less | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cfgov/jinja2/v1/_includes/macros/time.html b/cfgov/jinja2/v1/_includes/macros/time.html index 34fb6461183..9fdd35a0fb0 100644 --- a/cfgov/jinja2/v1/_includes/macros/time.html +++ b/cfgov/jinja2/v1/_includes/macros/time.html @@ -20,9 +20,10 @@ {% macro render(datetime, show_value_for={'date':true, 'time':true, 'timezone':true}) %} - {% if show_value_for.date == true %} + {% if show_value_for.date == true %} {% endif %} diff --git a/cfgov/jinja2/v1/_includes/organisms/post-preview.html b/cfgov/jinja2/v1/_includes/organisms/post-preview.html index 80500620e73..0926c6eb8f9 100644 --- a/cfgov/jinja2/v1/_includes/organisms/post-preview.html +++ b/cfgov/jinja2/v1/_includes/organisms/post-preview.html @@ -103,7 +103,9 @@ data-month="{{ event.start_dt | date('%b') }}" data-day="{{ event.start_dt | date('%-d') }}" datetime="{{ event.start_dt | date('%c') }}"> - {{ event.start_dt| date('%b %-d, %Y') }} + + {{'{dt:%b}. {dt.day}, {dt.year}'.format(dt = event.start_dt)}} + {% if event.live_stream_link %} {% if last_edited %} - + {% endif %}

{{ page.question | striptags }}

@@ -97,7 +100,6 @@

{{ ask_search_bar.render( 'left' ) }} - {% endblock %} {% block content_sidebar_modifiers -%} diff --git a/cfgov/unprocessed/css/calendar-icon.less b/cfgov/unprocessed/css/calendar-icon.less index 46d116f21cc..3fa1fa1f9cc 100755 --- a/cfgov/unprocessed/css/calendar-icon.less +++ b/cfgov/unprocessed/css/calendar-icon.less @@ -12,7 +12,7 @@ - name: Calendar Icon markup: | denotes: - | diff --git a/cfgov/unprocessed/css/organisms/item-introduction.less b/cfgov/unprocessed/css/organisms/item-introduction.less index d5bea89c330..1b9777ae5b9 100644 --- a/cfgov/unprocessed/css/organisms/item-introduction.less +++ b/cfgov/unprocessed/css/organisms/item-introduction.less @@ -10,7 +10,7 @@

By AuthorA - - +

[social media molecule] diff --git a/cfgov/unprocessed/css/organisms/post-preview.less b/cfgov/unprocessed/css/organisms/post-preview.less index 9baafcfc458..1c16c3a2149 100644 --- a/cfgov/unprocessed/css/organisms/post-preview.less +++ b/cfgov/unprocessed/css/organisms/post-preview.less @@ -10,7 +10,7 @@ Published From c81d3f1ccd5cdffbbb1aacbaa3498f2ddca363ee Mon Sep 17 00:00:00 2001 From: Anselm Bradford Date: Fri, 11 Aug 2017 11:58:42 -0400 Subject: [PATCH 2/5] Updates jobs table --- cfgov/jobmanager/models/blocks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfgov/jobmanager/models/blocks.py b/cfgov/jobmanager/models/blocks.py index bb7f25f1c9d..f60a5f79419 100644 --- a/cfgov/jobmanager/models/blocks.py +++ b/cfgov/jobmanager/models/blocks.py @@ -77,4 +77,4 @@ def make_grades_value(self, instance, value): return ', '.join(sorted(g.grade.grade for g in value.all())) def make_close_date_value(self, instance, value): - return value.strftime('%b %d, %Y').upper() + return value.strftime('%b. %d, %Y') From 706ea740f7f757c5b3223cd63e877264df203684 Mon Sep 17 00:00:00 2001 From: Anselm Bradford Date: Fri, 11 Aug 2017 14:34:37 -0400 Subject: [PATCH 3/5] Update to handle May and Sept. --- cfgov/jinja2/v1/_includes/macros/time.html | 20 +++++++++++++++++-- .../v1/_includes/organisms/post-preview.html | 2 +- cfgov/jinja2/v1/ask-cfpb/answer-page.html | 3 ++- cfgov/jobmanager/models/blocks.py | 7 ++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cfgov/jinja2/v1/_includes/macros/time.html b/cfgov/jinja2/v1/_includes/macros/time.html index 9fdd35a0fb0..496562ca89e 100644 --- a/cfgov/jinja2/v1/_includes/macros/time.html +++ b/cfgov/jinja2/v1/_includes/macros/time.html @@ -22,8 +22,7 @@ {% if show_value_for.date == true %} {% endif %} @@ -42,3 +41,20 @@ {% endif %} {% endmacro %} + +{% macro render_date_no_markup(datetime, + show_value_for={'date':true, 'time':true, 'timezone':true}) %} + {# TODO: Replace this with a custom Jinja method that uses + https://dateutil.readthedocs.io/ #} + {# Displays the date in the format: MMM. DD, YYYY #} + {% set format_month = '{dt:%b}'.format(dt = datetime) %} + {% if format_month == 'May' %} + {# May doesn't have a period. #} + {{ '{dt:%b} {dt.day}, {dt.year}'.format(dt = datetime) }} + {% elif format_month == 'Sep' %} + {# September is four letters. #} + {{ 'Sept. {dt.day}, {dt.year}'.format(dt = datetime) }} + {% else %} + {{ '{dt:%b}. {dt.day}, {dt.year}'.format(dt = datetime) }} + {% endif %} +{% endmacro %} diff --git a/cfgov/jinja2/v1/_includes/organisms/post-preview.html b/cfgov/jinja2/v1/_includes/organisms/post-preview.html index 0926c6eb8f9..2b2923c6e82 100644 --- a/cfgov/jinja2/v1/_includes/organisms/post-preview.html +++ b/cfgov/jinja2/v1/_includes/organisms/post-preview.html @@ -104,7 +104,7 @@ data-day="{{ event.start_dt | date('%-d') }}" datetime="{{ event.start_dt | date('%c') }}"> - {{'{dt:%b}. {dt.day}, {dt.year}'.format(dt = event.start_dt)}} + {{ time.render_date_no_markup(event.start_dt) }} {% if event.live_stream_link %} diff --git a/cfgov/jinja2/v1/ask-cfpb/answer-page.html b/cfgov/jinja2/v1/ask-cfpb/answer-page.html index a8913f68792..370b5e2a63d 100644 --- a/cfgov/jinja2/v1/ask-cfpb/answer-page.html +++ b/cfgov/jinja2/v1/ask-cfpb/answer-page.html @@ -2,6 +2,7 @@ {% import 'tags.html' as tags with context %} {% import 'form_block.html' as form_block with context %} {% import 'macros/util/format/datetime.html' as dt %} +{% import 'macros/time.html' as time %} {% import 'ask/ask-search-bar.html' as ask_search_bar with context %} {% block title %} @@ -39,7 +40,7 @@ {% if last_edited %} {% endif %} diff --git a/cfgov/jobmanager/models/blocks.py b/cfgov/jobmanager/models/blocks.py index f60a5f79419..c07ad054525 100644 --- a/cfgov/jobmanager/models/blocks.py +++ b/cfgov/jobmanager/models/blocks.py @@ -77,4 +77,9 @@ def make_grades_value(self, instance, value): return ', '.join(sorted(g.grade.grade for g in value.all())) def make_close_date_value(self, instance, value): - return value.strftime('%b. %d, %Y') + formatted_month = value.strftime('%b') + if formatted_month != 'May' or formatted_month != 'Sep': + formatted_month = formatted_month + '.' + elif formatted_month == 'Sep': + formatted_month = 'Sept.' + return formatted_month + value.strftime(' %d, %Y') From dd6a4bdbfae80fdaa63e29be2dc4b3268bde02e2 Mon Sep 17 00:00:00 2001 From: Anselm Bradford Date: Fri, 11 Aug 2017 15:31:10 -0400 Subject: [PATCH 4/5] Fixed tests --- cfgov/jobmanager/models/blocks.py | 6 ++- cfgov/jobmanager/tests/models/test_blocks.py | 46 +++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/cfgov/jobmanager/models/blocks.py b/cfgov/jobmanager/models/blocks.py index c07ad054525..52a1161bb77 100644 --- a/cfgov/jobmanager/models/blocks.py +++ b/cfgov/jobmanager/models/blocks.py @@ -78,8 +78,10 @@ def make_grades_value(self, instance, value): def make_close_date_value(self, instance, value): formatted_month = value.strftime('%b') - if formatted_month != 'May' or formatted_month != 'Sep': + if formatted_month != 'May' and formatted_month != 'Sep': formatted_month = formatted_month + '.' elif formatted_month == 'Sep': formatted_month = 'Sept.' - return formatted_month + value.strftime(' %d, %Y') + formatted_day = value.strftime('%d').lstrip('0') + formatted_year = value.strftime('%Y') + return formatted_month + ' ' + formatted_day + ', ' + formatted_year diff --git a/cfgov/jobmanager/tests/models/test_blocks.py b/cfgov/jobmanager/tests/models/test_blocks.py index 886511beddb..80682f5a529 100644 --- a/cfgov/jobmanager/tests/models/test_blocks.py +++ b/cfgov/jobmanager/tests/models/test_blocks.py @@ -91,12 +91,12 @@ def test_html_formatting(self): '
  • ' 'Assistant' '

    CLOSING' - '.*APR 21, 2099.*

    ' + '.*Apr. 21, 2099.*

    ' '
  • ' '
  • ' 'Manager' '

    CLOSING.' - '*AUG 05, 2099.*

    ' + '*Aug. 5, 2099.*

    ' '
  • ' )) @@ -206,13 +206,13 @@ def test_html_formatting(self): '' 'Assistant' '12' - 'APR 21, 2099' + 'Apr. 21, 2099' 'Silicon Valley' '' '' 'Manager' '1, 2, 3' - 'AUG 05, 2099' + 'Aug. 5, 2099' 'Silicon Valley' '' )) @@ -230,7 +230,43 @@ def test_html_formatting_no_grade(self): '' 'CEO' '' - 'DEC 01, 2099' + 'Dec. 1, 2099' + 'Silicon Valley' + '' + )) + + def test_html_formatting_no_grade_may_date(self): + make_job_listing_page( + title='CEO', + close_date=date(2099, 5, 1) + ) + + table = JobListingTable() + html = table.render(table.to_python({})) + + self.assertHtmlRegexpMatches(html, ( + '' + 'CEO' + '' + 'May 1, 2099' + 'Silicon Valley' + '' + )) + + def test_html_formatting_no_grade_sept_date(self): + make_job_listing_page( + title='CEO', + close_date=date(2099, 9, 1) + ) + + table = JobListingTable() + html = table.render(table.to_python({})) + + self.assertHtmlRegexpMatches(html, ( + '' + 'CEO' + '' + 'Sept. 1, 2099' 'Silicon Valley' '' )) From c541b74b8fc94bf713a5c3f3f357d495764fddd4 Mon Sep 17 00:00:00 2001 From: Anselm Bradford Date: Fri, 11 Aug 2017 15:34:43 -0400 Subject: [PATCH 5/5] Update bureau structure date format --- cfgov/jinja2/v1/_includes/organisms/bureau-structure.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cfgov/jinja2/v1/_includes/organisms/bureau-structure.html b/cfgov/jinja2/v1/_includes/organisms/bureau-structure.html index b1d0d88a5ba..dbdfebd23e4 100644 --- a/cfgov/jinja2/v1/_includes/organisms/bureau-structure.html +++ b/cfgov/jinja2/v1/_includes/organisms/bureau-structure.html @@ -322,7 +322,8 @@

    Bureau Structure

    Last updated: {# Displays the date in the format: MMM. DD, YYYY #} - {{'{dt:%b}. {dt.day}, {dt.year}'.format(dt = value.last_updated_date)}} + {% import 'macros/time.html' as time %} + {{ time.render_date_no_markup(value.last_updated_date) }}

    {% endif %}