Ejemplo n.º 1
0
    def apply_kill_override(self, item, updates):
        """Applies kill override.

        Kill requires content to be generate based on the item getting killed (and not the
        item that is being actioned on).

        :param dict item: item to kill
        :param dict updates: updates that needs to be modified based on the template
        :return:
        """
        try:
            desk_name = get_resource_service('desks').get_desk_name(item.get('task', {}).get('desk'))
            city = get_dateline_city(item.get('dateline'))
            kill_header = json.loads(render_template('article_killed_override.json',
                                                     slugline=item.get('slugline', ''),
                                                     headline=item.get('headline', ''),
                                                     desk_name=desk_name,
                                                     city=city,
                                                     versioncreated=item.get('versioncreated',
                                                                             item.get(config.LAST_UPDATED)),
                                                     body_html=updates.get('body_html')))
            for key, value in kill_header.items():
                kill_header[key] = html.unescape(value)

            updates.update(kill_header)
        except:
            logger.exception('Failed to apply kill header template to item {}.'.format(item))
Ejemplo n.º 2
0
    def apply_kill_override(self, item, updates):
        """Applies kill override.

        Kill requires content to be generate based on the item getting killed (and not the
        item that is being actioned on).

        :param dict item: item to kill
        :param dict updates: updates that needs to be modified based on the template
        :return:
        """
        try:
            desk_name = get_resource_service('desks').get_desk_name(
                item.get('task', {}).get('desk'))
            city = get_dateline_city(item.get('dateline'))
            kill_header = json.loads(render_template(
                'article_killed_override.json',
                slugline=item.get('slugline', ''),
                headline=item.get('headline', ''),
                desk_name=desk_name,
                city=city,
                versioncreated=item.get('versioncreated',
                                        item.get(config.LAST_UPDATED)),
                body_html=updates.get('body_html', ''),
                update_headline=updates.get('headline', '')),
                                     strict=False)
            for key, value in kill_header.items():
                kill_header[key] = html.unescape(value)

            updates.update(kill_header)
        except Exception:
            logger.exception(
                'Failed to apply kill header template to item {}.'.format(
                    item))
Ejemplo n.º 3
0
 def test_get_dateline_city_from_located_with_country(self):
     self.assertEqual(
         get_dateline_city({
             'located': {
                 'country': 'Canada'
             },
             'text': 'Sydney, 9 July AAP'
         }), 'Sydney')
Ejemplo n.º 4
0
 def test_get_dateline_city_from_located(self):
     self.assertEqual(
         get_dateline_city({
             'located': {
                 'city': 'Melbourne'
             },
             'text': 'Sydney, 9 July AAP'
         }), 'Melbourne')
Ejemplo n.º 5
0
 def test_get_dateline_city_from_text_no_city(self):
     self.assertEqual(
         get_dateline_city({
             'located': {
                 'city': None
             },
             'text': 'Sydney, 9 July AAP'
         }), 'Sydney')
Ejemplo n.º 6
0
 def test_get_dateline_city_from_located_with_country(self):
     self.assertEqual(
         get_dateline_city({
             "located": {
                 "country": "Canada"
             },
             "text": "Sydney, 9 July AAP"
         }), "Sydney")
Ejemplo n.º 7
0
 def test_get_dateline_city_from_text_no_city(self):
     self.assertEqual(
         get_dateline_city({
             "located": {
                 "city": None
             },
             "text": "Sydney, 9 July AAP"
         }), "Sydney")
Ejemplo n.º 8
0
 def test_get_dateline_city_from_located(self):
     self.assertEqual(
         get_dateline_city({
             "located": {
                 "city": "Melbourne"
             },
             "text": "Sydney, 9 July AAP"
         }), "Melbourne")
Ejemplo n.º 9
0
    def apply_kill_override(self, item, updates):
        """Applies kill override.

        Kill requires content to be generate based on the item getting killed (and not the
        item that is being actioned on).

        :param dict item: item to kill
        :param dict updates: updates that needs to be modified based on the template
        :return:
        """
        try:
            if item.get("_type") == "archive":
                # attempt to find the published item as this will have an accurate time of publication
                published_item = get_resource_service(
                    PUBLISHED).get_last_published_version(
                        item.get(config.ID_FIELD))
                versioncreated = (
                    published_item.get("versioncreated") if published_item else
                    item.get("versioncreated", item.get(config.LAST_UPDATED)))
            else:
                versioncreated = item.get("versioncreated",
                                          item.get(config.LAST_UPDATED))
            desk_name = get_resource_service("desks").get_desk_name(
                item.get("task", {}).get("desk"))
            city = get_dateline_city(item.get("dateline"))
            kill_header = json.loads(
                render_template(
                    "article_killed_override.json",
                    slugline=item.get("slugline", ""),
                    headline=item.get("headline", ""),
                    desk_name=desk_name,
                    city=city,
                    versioncreated=versioncreated,
                    body_html=updates.get("body_html", ""),
                    update_headline=updates.get("headline", ""),
                    item_operation=self.item_operation.lower(),
                ),
                strict=False,
            )

            for key, value in kill_header.items():
                kill_header[key] = html.unescape(value)

            updates.update(kill_header)
        except Exception:
            logger.exception(
                "Failed to apply kill header template to item {}.".format(
                    item))
Ejemplo n.º 10
0
    def apply_kill_override(self, item, updates):
        """Applies kill override.

        Kill requires content to be generate based on the item getting killed (and not the
        item that is being actioned on).

        :param dict item: item to kill
        :param dict updates: updates that needs to be modified based on the template
        :return:
        """
        try:
            if item.get('_type') == 'archive':
                # attempt to find the published item as this will have an accurate time of publication
                published_items = get_resource_service(
                    PUBLISHED).get_last_published_version(
                        item.get(config.ID_FIELD))
                published_item = [p for p in published_items if p.get(LAST_PUBLISHED_VERSION)][0] \
                    if published_items.count() > 0 else None
                versioncreated = published_item.get('versioncreated') if published_item else \
                    item.get('versioncreated', item.get(config.LAST_UPDATED))
            else:
                versioncreated = item.get('versioncreated',
                                          item.get(config.LAST_UPDATED))
            desk_name = get_resource_service('desks').get_desk_name(
                item.get('task', {}).get('desk'))
            city = get_dateline_city(item.get('dateline'))
            kill_header = json.loads(render_template(
                'article_killed_override.json',
                slugline=item.get('slugline', ''),
                headline=item.get('headline', ''),
                desk_name=desk_name,
                city=city,
                versioncreated=versioncreated,
                body_html=updates.get('body_html', ''),
                update_headline=updates.get('headline', ''),
                item_operation=self.item_operation.lower()),
                                     strict=False)

            for key, value in kill_header.items():
                kill_header[key] = html.unescape(value)

            updates.update(kill_header)
        except Exception:
            logger.exception(
                'Failed to apply kill header template to item {}.'.format(
                    item))
Ejemplo n.º 11
0
    def broadcast_kill_email(self, original, updates):
        """
        Sends the broadcast email to all subscribers (including in-active subscribers)
        :param dict original: Document to kill
        :param dict updates: kill updates
        """
        # Get all subscribers
        subscribers = list(get_resource_service('subscribers').get(req=None, lookup=None))

        recipients = [s.get('email').split(',') for s in subscribers if s.get('email')]
        recipients = list(set(chain(*recipients)))
        # send kill email.
        kill_article = deepcopy(original)
        kill_article['body_html'] = updates.get('body_html')
        kill_article['desk_name'] = get_resource_service('desks').get_desk_name(kill_article.get('task',
                                                                                                 {}).get('desk'))
        kill_article['city'] = get_dateline_city(kill_article.get('dateline'))
        send_article_killed_email(kill_article, recipients, utcnow())
Ejemplo n.º 12
0
    def broadcast_kill_email(self, original, updates):
        """Sends the broadcast email to all subscribers (including in-active subscribers)

        :param dict original: Document to kill
        :param dict updates: kill updates
        """
        # Get all subscribers
        subscribers = list(get_resource_service('subscribers').get(req=None, lookup=None))

        recipients = [s.get('email').split(',') for s in subscribers if s.get('email')]
        recipients = list(set(chain(*recipients)))
        # send kill email.
        kill_article = deepcopy(original)
        kill_article['body_html'] = updates.get('body_html')
        kill_article['headline'] = updates.get('headline')
        kill_article['desk_name'] = get_resource_service('desks').get_desk_name(kill_article.get('task',
                                                                                                 {}).get('desk'))
        kill_article['city'] = get_dateline_city(kill_article.get('dateline'))
        kill_article['action'] = self.item_operation
        send_article_killed_email(kill_article, recipients, utcnow())
Ejemplo n.º 13
0
    def broadcast_kill_email(self, original, updates):
        """Sends the broadcast email to all subscribers (including in-active subscribers)

        :param dict original: Document to kill
        :param dict updates: kill updates
        """
        # Get all subscribers
        subscribers = list(get_resource_service("subscribers").get(req=None, lookup=None))

        recipients = [s.get("email").split(",") for s in subscribers if s.get("email")]
        recipients = list(set(chain(*recipients)))
        # send kill email.
        kill_article = deepcopy(original)
        kill_article["body_html"] = updates.get("body_html")
        kill_article["headline"] = updates.get("headline")
        kill_article["desk_name"] = get_resource_service("desks").get_desk_name(
            kill_article.get("task", {}).get("desk")
        )
        kill_article["city"] = get_dateline_city(kill_article.get("dateline"))
        kill_article["action"] = self.item_operation
        send_article_killed_email(kill_article, recipients, utcnow())
Ejemplo n.º 14
0
    def apply_kill_override(self, item, updates):
        """Applies kill override.

        Kill requires content to be generate based on the item getting killed (and not the
        item that is being actioned on).

        :param dict item: item to kill
        :param dict updates: updates that needs to be modified based on the template
        :return:
        """
        try:
            if item.get('_type') == 'archive':
                # attempt to find the published item as this will have an accurate time of publication
                published_items = get_resource_service(PUBLISHED).get_last_published_version(item.get(config.ID_FIELD))
                published_item = [p for p in published_items if p.get(LAST_PUBLISHED_VERSION)][0] \
                    if published_items.count() > 0 else None
                versioncreated = published_item.get('versioncreated') if published_item else \
                    item.get('versioncreated', item.get(config.LAST_UPDATED))
            else:
                versioncreated = item.get('versioncreated', item.get(config.LAST_UPDATED))
            desk_name = get_resource_service('desks').get_desk_name(item.get('task', {}).get('desk'))
            city = get_dateline_city(item.get('dateline'))
            kill_header = json.loads(render_template('article_killed_override.json',
                                                     slugline=item.get('slugline', ''),
                                                     headline=item.get('headline', ''),
                                                     desk_name=desk_name,
                                                     city=city,
                                                     versioncreated=versioncreated,
                                                     body_html=updates.get('body_html', ''),
                                                     update_headline=updates.get('headline', ''),
                                                     item_operation=self.item_operation.lower()),
                                     strict=False)

            for key, value in kill_header.items():
                kill_header[key] = html.unescape(value)

            updates.update(kill_header)
        except Exception:
            logger.exception('Failed to apply kill header template to item {}.'.format(item))
Ejemplo n.º 15
0
 def test_get_dateline_city_from_text_with_city_state(self):
     self.assertEqual(
         get_dateline_city({
             "located": None,
             "text": "City, State, 9 July AAP"
         }), "City, State")
Ejemplo n.º 16
0
 def test_get_dateline_city_located_as_none_text_as_none(self):
     self.assertEqual(get_dateline_city({
         "located": None,
         "text": None
     }), "")
Ejemplo n.º 17
0
 def test_get_dateline_city_from_located_with_country(self):
     self.assertEqual(get_dateline_city({'located': {'country': 'Canada'}, 'text': 'Sydney, 9 July AAP'}),
                      'Sydney')
Ejemplo n.º 18
0
 def test_get_dateline_city_from_text_with_city_state(self):
     self.assertEqual(get_dateline_city({'located': None, 'text': 'City, State, 9 July AAP'}), 'City, State')
Ejemplo n.º 19
0
 def test_get_dateline_city_from_located(self):
     self.assertEqual(get_dateline_city({'located': {'city': 'Melbourne'}, 'text': 'Sydney, 9 July AAP'}),
                      'Melbourne')
Ejemplo n.º 20
0
 def test_get_dateline_city_from_text_no_city(self):
     self.assertEqual(get_dateline_city({'located': {'city': None}, 'text': 'Sydney, 9 July AAP'}),
                      'Sydney')
Ejemplo n.º 21
0
 def test_get_dateline_city_located_as_none_text_as_none(self):
     self.assertEqual(get_dateline_city({'located': None, 'text': None}), '')
Ejemplo n.º 22
0
 def test_get_dateline_city_None(self):
     self.assertEqual(get_dateline_city(None), '')
Ejemplo n.º 23
0
 def test_get_dateline_city_None(self):
     self.assertEqual(get_dateline_city(None), '')
Ejemplo n.º 24
0
 def test_get_dateline_city_located_as_none_text_as_none(self):
     self.assertEqual(get_dateline_city({
         'located': None,
         'text': None
     }), '')
Ejemplo n.º 25
0
 def test_get_dateline_city_from_text_with_city_state(self):
     self.assertEqual(
         get_dateline_city({
             'located': None,
             'text': 'City, State, 9 July AAP'
         }), 'City, State')