Example #1
0
def on_create_item(docs, repo_type=ARCHIVE):
    """Make sure item has basic fields populated."""

    for doc in docs:
        editor_utils.generate_fields(doc)
        update_dates_for(doc)
        set_original_creator(doc)

        if not doc.get(GUID_FIELD):
            doc[GUID_FIELD] = generate_guid(type=GUID_NEWSML)

        if "unique_id" not in doc:
            generate_unique_id_and_name(doc, repo_type)

        if "family_id" not in doc:
            doc["family_id"] = doc[GUID_FIELD]

        if "event_id" not in doc and repo_type != "ingest":
            doc["event_id"] = generate_guid(type=GUID_TAG)

        set_default_state(doc, CONTENT_STATE.DRAFT)
        doc.setdefault(config.ID_FIELD, doc[GUID_FIELD])

        if repo_type == ARCHIVE:
            # set the source for the article
            set_default_source(doc)

        if "profile" not in doc and app.config.get("DEFAULT_CONTENT_TYPE",
                                                   None):
            doc["profile"] = app.config.get("DEFAULT_CONTENT_TYPE", None)

        copy_metadata_from_profile(doc)
        copy_metadata_from_user_preferences(doc, repo_type)

        if "language" not in doc:
            doc["language"] = app.config.get("DEFAULT_LANGUAGE", "en")

            if doc.get("task", None) and doc["task"].get("desk", None):
                desk = superdesk.get_resource_service("desks").find_one(
                    req=None, _id=doc["task"]["desk"])
                if desk and desk.get("desk_language", None):
                    doc["language"] = desk["desk_language"]

        if not doc.get(ITEM_OPERATION):
            doc[ITEM_OPERATION] = ITEM_CREATE

        if doc.get("template"):
            from apps.templates.content_templates import render_content_template_by_id  # avoid circular import

            doc.pop("fields_meta", None)
            render_content_template_by_id(doc, doc["template"], update=True)
            editor_utils.generate_fields(doc)
Example #2
0
def on_create_item(docs, repo_type=ARCHIVE):
    """Make sure item has basic fields populated."""

    for doc in docs:
        editor_utils.generate_fields(doc)
        update_dates_for(doc)
        set_original_creator(doc)

        if not doc.get(GUID_FIELD):
            doc[GUID_FIELD] = generate_guid(type=GUID_NEWSML)

        if 'unique_id' not in doc:
            generate_unique_id_and_name(doc, repo_type)

        if 'family_id' not in doc:
            doc['family_id'] = doc[GUID_FIELD]

        if 'event_id' not in doc and repo_type != 'ingest':
            doc['event_id'] = generate_guid(type=GUID_TAG)

        set_default_state(doc, CONTENT_STATE.DRAFT)
        doc.setdefault(config.ID_FIELD, doc[GUID_FIELD])

        if repo_type == ARCHIVE:
            # set the source for the article
            set_default_source(doc)

        if 'profile' not in doc and app.config.get('DEFAULT_CONTENT_TYPE',
                                                   None):
            doc['profile'] = app.config.get('DEFAULT_CONTENT_TYPE', None)

        copy_metadata_from_profile(doc)
        copy_metadata_from_user_preferences(doc, repo_type)

        if 'language' not in doc:
            doc['language'] = app.config.get('DEFAULT_LANGUAGE', 'en')

            if doc.get('task', None) and doc['task'].get('desk', None):
                desk = superdesk.get_resource_service('desks').find_one(
                    req=None, _id=doc['task']['desk'])
                if desk and desk.get('desk_language', None):
                    doc['language'] = desk['desk_language']

        if not doc.get(ITEM_OPERATION):
            doc[ITEM_OPERATION] = ITEM_CREATE

        if doc.get('template'):
            from apps.templates.content_templates import render_content_template_by_id  # avoid circular import
            doc.pop('fields_meta', None)
            render_content_template_by_id(doc, doc['template'], update=True)
            editor_utils.generate_fields(doc)
def copy_metadata_from_highlight_template(doc):
    """
    Copy the values set on highlight template

    :param doc
    """
    highlight_id = doc.get('highlight', None)
    if highlight_id:
        highlight = superdesk.get_resource_service('highlights').find_one(req=None, _id=highlight_id)
        if highlight and 'template' in highlight:
            updates = render_content_template_by_id(doc, highlight.get('template', None))
            doc.update(updates)
def copy_metadata_from_highlight_template(doc):
    """
    Copy the values set on highlight template

    :param doc
    """
    highlight_id = doc.get('highlight', None)
    if highlight_id:
        highlight = superdesk.get_resource_service('highlights').find_one(req=None, _id=highlight_id)
        if highlight and 'template' in highlight:
            updates = render_content_template_by_id(doc, highlight.get('template', None))
            doc.update(updates)
def copy_metadata_from_highlight_template(doc):
    """
    Copy the values set on highlight template

    :param doc
    """
    highlight_id = doc.get("highlight", None)
    if highlight_id:
        highlight = superdesk.get_resource_service("highlights").find_one(req=None, _id=highlight_id)
        if highlight and "template" in highlight:
            from apps.templates.content_templates import render_content_template_by_id

            updates = render_content_template_by_id(doc, highlight.get("template", None))
            if ITEM_TYPE in updates:
                del updates[ITEM_TYPE]
            doc.update(updates)