From c3acc8eab2ea8ca93630d40f1ef320748f901f34 Mon Sep 17 00:00:00 2001 From: Mayur Dhamanwala Date: Thu, 18 Aug 2016 15:45:21 +1000 Subject: [PATCH] Escaping quotes for json output in macros. --- server/aap/macros/generate_slugline_story_by_desk.py | 3 ++- server/aap/macros/generate_slugline_story_by_desk_test.py | 4 ++-- server/templates/article_killed_override.json | 2 +- server/templates/skeds_body_html.json | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/aap/macros/generate_slugline_story_by_desk.py b/server/aap/macros/generate_slugline_story_by_desk.py index 8c9ac575c..b5b869f35 100644 --- a/server/aap/macros/generate_slugline_story_by_desk.py +++ b/server/aap/macros/generate_slugline_story_by_desk.py @@ -139,7 +139,8 @@ def process(self, articles): article['abstract'] = article.get('abstract') or '' article['slugline'] = article.get('slugline') or '' article['source'] = article.get('source') or '' - article['dateline_city'] = (article.get('dateline', {}).get('located', {}).get('city') or '').upper() + article['dateline_city'] = \ + (((article.get('dateline') or {}).get('located') or {}).get('city') or '').upper() def generate_published_slugline_story_by_desk(item, **kwargs): diff --git a/server/aap/macros/generate_slugline_story_by_desk_test.py b/server/aap/macros/generate_slugline_story_by_desk_test.py index 01afd24d6..4dfa4b602 100644 --- a/server/aap/macros/generate_slugline_story_by_desk_test.py +++ b/server/aap/macros/generate_slugline_story_by_desk_test.py @@ -48,7 +48,7 @@ def setUp(self): } }, { - '_id': '2', 'type': 'text', 'abstract': 'abstract item 2', 'slugline': 'slugline item 2', + '_id': '2', 'type': 'text', 'abstract': 'abstract "item 2"', 'slugline': 'slugline item 2', 'dateline': { 'text': 'Sydney, 01 Jan AAP -', 'located': { @@ -253,6 +253,6 @@ def test_generate_body_html(self): } generate_published_slugline_story_by_desk(item) - self.assertTrue('SYDNEY abstract item 2 (slugline item 2)' in item['body_html']) + self.assertTrue('SYDNEY abstract "item 2" (slugline item 2)' in item['body_html']) self.assertTrue('SYDNEY abstract item 2a (slugline item 2a)' in item['body_html']) self.assertTrue('SYDNEY abstract item 7 (slugline item 7)' in item['body_html']) diff --git a/server/templates/article_killed_override.json b/server/templates/article_killed_override.json index a0b78df08..cae2fe408 100644 --- a/server/templates/article_killed_override.json +++ b/server/templates/article_killed_override.json @@ -1,3 +1,3 @@ { - "body_html": "

Please kill story slugged {{ slugline }} headlined {{headline}} ex {{ city }} at {%if desk_name.strip().lower() == 'new zealand'%}{{versioncreated | format_datetime('Pacific/Auckland', '%d %b %Y %H:%S %Z')}}{% else %}{{versioncreated | format_datetime('Australia/Sydney', '%d %b %Y %H:%S %Z')}}{% endif %}.

{{body_html | escape}}" + "body_html": "

Please kill story slugged {{ slugline.replace('\"', '\\\"') }} headlined {{headline.replace('\"', '\\\"')}} ex {{ city }} at {%if desk_name.strip().lower() == 'new zealand'%}{{versioncreated | format_datetime('Pacific/Auckland', '%d %b %Y %H:%S %Z')}}{% else %}{{versioncreated | format_datetime('Australia/Sydney', '%d %b %Y %H:%S %Z')}}{% endif %}.

{{body_html.replace('\"', '\\\"') | escape}}" } \ No newline at end of file diff --git a/server/templates/skeds_body_html.json b/server/templates/skeds_body_html.json index cdb44735f..8cfb77d05 100644 --- a/server/templates/skeds_body_html.json +++ b/server/templates/skeds_body_html.json @@ -2,7 +2,7 @@ "slugline": "{{desk_name}} skeds {{now | format_datetime('Australia/Sydney', '%b %-d')}}", "abstract": "{{desk_name}} skedlines, {{now | format_datetime('Australia/Sydney', '%B %-d')}}", "headline": "{{desk_name}} skedlines, {{now | format_datetime('Australia/Sydney', '%B %-d')}}", - "body_html": "

{{desk_name}} skeds for {{now | format_datetime('Australia/Sydney', '%A, %B %-d')}}:


{% for item in items %}

{{item.dateline_city}} {{item.abstract|striptags}} ({{item.slugline}}) {{item.anpa_take_key}} {{item.versioncreated | format_datetime('Australia/Sydney', '%H:%S')}}


{% endfor %}", + "body_html": "

{{desk_name}} skeds for {{now | format_datetime('Australia/Sydney', '%A, %B %-d')}}:


{% for item in items %}

{{item.dateline_city}} {{item.abstract.replace('\"', '\\\"') | striptags}} ({{item.slugline.replace('\"', '\\\"')}}) {{item.anpa_take_key.replace('\"', '\\\"')}} {{item.versioncreated | format_datetime('Australia/Sydney', '%H:%S')}}


{% endfor %}", "anpa_category": [{"qcode" : "v", "name" : "Advisories", "is_active" : true}], "subject": [{"qcode" : "99001000", "scheme" : null, "name" : "advisory", "parent" : "99000000"}] }