Beispiel #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))
Beispiel #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))
Beispiel #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')
Beispiel #4
0
 def test_get_dateline_city_from_located(self):
     self.assertEqual(
         get_dateline_city({
             'located': {
                 'city': 'Melbourne'
             },
             'text': 'Sydney, 9 July AAP'
         }), 'Melbourne')
Beispiel #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')
 def test_get_dateline_city_from_located_with_country(self):
     self.assertEqual(
         get_dateline_city({
             "located": {
                 "country": "Canada"
             },
             "text": "Sydney, 9 July AAP"
         }), "Sydney")
 def test_get_dateline_city_from_text_no_city(self):
     self.assertEqual(
         get_dateline_city({
             "located": {
                 "city": None
             },
             "text": "Sydney, 9 July AAP"
         }), "Sydney")
 def test_get_dateline_city_from_located(self):
     self.assertEqual(
         get_dateline_city({
             "located": {
                 "city": "Melbourne"
             },
             "text": "Sydney, 9 July AAP"
         }), "Melbourne")
Beispiel #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))
Beispiel #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))
Beispiel #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())
Beispiel #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())
Beispiel #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())
Beispiel #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))
 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")
 def test_get_dateline_city_located_as_none_text_as_none(self):
     self.assertEqual(get_dateline_city({
         "located": None,
         "text": None
     }), "")
 def test_get_dateline_city_from_located_with_country(self):
     self.assertEqual(get_dateline_city({'located': {'country': 'Canada'}, 'text': 'Sydney, 9 July AAP'}),
                      'Sydney')
 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')
 def test_get_dateline_city_from_located(self):
     self.assertEqual(get_dateline_city({'located': {'city': 'Melbourne'}, 'text': 'Sydney, 9 July AAP'}),
                      'Melbourne')
 def test_get_dateline_city_from_text_no_city(self):
     self.assertEqual(get_dateline_city({'located': {'city': None}, 'text': 'Sydney, 9 July AAP'}),
                      'Sydney')
 def test_get_dateline_city_located_as_none_text_as_none(self):
     self.assertEqual(get_dateline_city({'located': None, 'text': None}), '')
 def test_get_dateline_city_None(self):
     self.assertEqual(get_dateline_city(None), '')
Beispiel #23
0
 def test_get_dateline_city_None(self):
     self.assertEqual(get_dateline_city(None), '')
Beispiel #24
0
 def test_get_dateline_city_located_as_none_text_as_none(self):
     self.assertEqual(get_dateline_city({
         'located': None,
         'text': None
     }), '')
Beispiel #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')