Ejemplo n.º 1
0
def publish_item(doc, is_new):
    """Duplicating the logic from content_api.publish service."""
    set_dates(doc)
    doc['firstpublished'] = parse_date_str(doc.get('firstpublished'))
    doc.setdefault('wordcount', get_word_count(doc.get('body_html', '')))
    doc.setdefault('charcount', get_char_count(doc.get('body_html', '')))
    service = superdesk.get_resource_service('content_api')
    if 'evolvedfrom' in doc:
        parent_item = service.find_one(req=None, _id=doc['evolvedfrom'])
        if parent_item:
            doc['ancestors'] = copy(parent_item.get('ancestors', []))
            doc['ancestors'].append(doc['evolvedfrom'])
            doc['bookmarks'] = parent_item.get('bookmarks', [])
            doc['planning_id'] = parent_item.get('planning_id')
            doc['coverage_id'] = parent_item.get('coverage_id')
        else:
            logger.warning("Failed to find evolvedfrom item %s for %s", doc['evolvedfrom'], doc['guid'])
    fix_hrefs(doc)
    logger.debug('publishing %s', doc['guid'])
    for assoc in doc.get('associations', {}).values():
        if assoc:
            assoc.setdefault('subscribers', [])
    if doc.get('associations', {}).get('featuremedia'):
        app.generate_renditions(doc)
    if doc.get('coverage_id'):
        agenda_items = superdesk.get_resource_service('agenda').set_delivery(doc)
        if agenda_items:
            [notify_new_item(item, check_topics=False) for item in agenda_items]
    publish_item_signal.send(app._get_current_object(), item=doc, is_new=is_new)
    _id = service.create([doc])[0]
    if 'evolvedfrom' in doc and parent_item:
        service.system_update(parent_item['_id'], {'nextversion': _id}, parent_item)
    return _id
Ejemplo n.º 2
0
def publish_item(doc, original):
    """Duplicating the logic from content_api.publish service."""
    set_dates(doc)
    doc['firstpublished'] = parse_date_str(doc.get('firstpublished'))
    doc['publish_schedule'] = parse_date_str(doc.get('publish_schedule'))
    doc.setdefault('wordcount', get_word_count(doc.get('body_html', '')))
    doc.setdefault('charcount', get_char_count(doc.get('body_html', '')))
    service = superdesk.get_resource_service('content_api')
    service.datasource = 'items'

    if 'evolvedfrom' in doc:
        parent_item = service.find_one(req=None, _id=doc['evolvedfrom'])
        if parent_item:
            doc['ancestors'] = copy(parent_item.get('ancestors', []))
            doc['ancestors'].append(doc['evolvedfrom'])
            doc['bookmarks'] = parent_item.get('bookmarks', [])
            doc['planning_id'] = parent_item.get('planning_id')
            doc['coverage_id'] = parent_item.get('coverage_id')
        else:
            logger.warning("Failed to find evolvedfrom item %s for %s",
                           doc['evolvedfrom'], doc['guid'])
    fix_hrefs(doc)
    logger.debug('publishing %s', doc['guid'])
    for assoc in doc.get('associations', {}).values():
        if assoc:
            assoc.setdefault('subscribers', [])
    if doc.get('associations', {}).get('featuremedia'):
        app.generate_renditions(doc)

    # If there is a function defined that generates renditions for embedded images call it.
    if app.generate_embed_renditions:
        app.generate_embed_renditions(doc)

    try:
        if doc.get('coverage_id'):
            agenda_items = superdesk.get_resource_service(
                'agenda').set_delivery(doc)
            if agenda_items:
                [
                    notify_new_item(item, check_topics=False)
                    for item in agenda_items
                ]
    except Exception as ex:
        logger.info('Failed to notify new wire item for Agenda watches')
        logger.exception(ex)

    publish_item_signal.send(app._get_current_object(),
                             item=doc,
                             is_new=original is None)
    _id = service.create([doc])[0]
    if 'associations' not in doc and original is not None and bool(
            original.get('associations', {})):
        service.patch(_id, updates={'associations': None})
    if 'evolvedfrom' in doc and parent_item:
        service.system_update(parent_item['_id'], {'nextversion': _id},
                              parent_item)
    return _id