Skip to content

Commit

Permalink
Escaping quotes for json output in macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayur Dhamanwala committed Aug 18, 2016
1 parent c4a490c commit c3acc8e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion server/aap/macros/generate_slugline_story_by_desk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions server/aap/macros/generate_slugline_story_by_desk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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'])
2 changes: 1 addition & 1 deletion server/templates/article_killed_override.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"body_html": "<p>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 %}.</p>{{body_html | escape}}"
"body_html": "<p>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 %}.</p>{{body_html.replace('\"', '\\\"') | escape}}"
}
2 changes: 1 addition & 1 deletion server/templates/skeds_body_html.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<p>{{desk_name}} skeds for {{now | format_datetime('Australia/Sydney', '%A, %B %-d')}}:</p></br>{% for item in items %}<p>{{item.dateline_city}} {{item.abstract|striptags}} ({{item.slugline}}) {{item.anpa_take_key}} {{item.versioncreated | format_datetime('Australia/Sydney', '%H:%S')}}</p></br>{% endfor %}",
"body_html": "<p>{{desk_name}} skeds for {{now | format_datetime('Australia/Sydney', '%A, %B %-d')}}:</p></br>{% for item in items %}<p>{{item.dateline_city}} {{item.abstract.replace('\"', '\\\"') | striptags}} ({{item.slugline.replace('\"', '\\\"')}}) {{item.anpa_take_key.replace('\"', '\\\"')}} {{item.versioncreated | format_datetime('Australia/Sydney', '%H:%S')}}</p></br>{% endfor %}",
"anpa_category": [{"qcode" : "v", "name" : "Advisories", "is_active" : true}],
"subject": [{"qcode" : "99001000", "scheme" : null, "name" : "advisory", "parent" : "99000000"}]
}

0 comments on commit c3acc8e

Please sign in to comment.