Skip to content

Commit

Permalink
Merge pull request #98 from mdhaman/1.0
Browse files Browse the repository at this point in the history
Escaping quotes for json output in macros and removing duplicate legal keyword.
  • Loading branch information
Mayur Dhamanwala authored Aug 18, 2016
2 parents 833c239 + e3658f9 commit 875dd62
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 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'])
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def format(self, article, subscriber, codes=None):
"""
try:
formatted_article = deepcopy(article)
formatted_article['slugline'] = self.get_text_content(to_ascii(self.append_legal(article=formatted_article,
truncate=True))).strip()
pub_seq_num = superdesk.get_resource_service('subscribers').generate_sequence_number(subscriber)
body_html = to_ascii(self.append_body_footer(formatted_article)).strip('\r\n')

Expand Down Expand Up @@ -71,7 +69,7 @@ def format(self, article, subscriber, codes=None):
formatted_article['first_subject'] = set_subject(category, formatted_article)
formatted_article['slugline'] = self.get_text_content(
to_ascii(SluglineMapper().map(article=formatted_article,
category=category.get('qcode').upper(), truncate=True))).strip()
category=category.get('qcode').upper(), truncate=True)).strip())

odbc_item = {
'id': formatted_article.get(config.ID_FIELD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ def test_strip_html(self):
config.VERSION: 2,
'source': 'AAP',
'headline': 'This is a test headline&nbsp;<span></span>',
'slugline': 'This is a test slugline ',
'slugline': 'slugline',
'abstract': '<p>abstract</p>',
'type': 'text',
'anpa_category': [{'qcode': 'a', 'name': 'Australian General News'}],
'flags': {
'marked_for_legal': True
},
'body_html': ('<p>The story&nbsp;<span></span>body line 1<br>Line 2</p>'
'<p>abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi'
'<span> abcdefghi</span> abcdefghi abcdefghi more</p>'
Expand All @@ -101,7 +105,7 @@ def test_strip_html(self):
self.assertEqual(test_article['body_text'], body_text)
self.assertEqual(test_article['abstract'], 'abstract')
self.assertEqual(test_article['headline'], 'This is a test headline')
self.assertEqual(test_article['slugline'], 'This is a test slugline')
self.assertEqual(test_article['slugline'], 'Legal: slugline')

def test_strip_html_case1(self):
article = {
Expand Down
2 changes: 1 addition & 1 deletion server/aap/publish/formatters/unicodetoascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def to_ascii(input_str):
try:
return unidecode.unidecode(input_str)
return unidecode.unidecode(input_str) if input_str else ''
except:
logger.exception('Cannot convert input {} to ascii'.format(input_str))
return input_str
2 changes: 2 additions & 0 deletions server/aap/publish/formatters/unicodetoascii_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ def TestCase(self):
self.assertEqual(to_ascii('ʺ'), '"')
self.assertEqual(to_ascii('̀'), '')
self.assertEqual(to_ascii('ˮ'), '"')
self.assertEqual(to_ascii(None), '')
self.assertEqual(to_ascii(''), '')
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 875dd62

Please sign in to comment.