<commit_before># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from superdesk import get_resource_service, config
from superdesk.validation import ValidationError
from apps.publish.content.common import ITEM_PUBLISH
from flask_babel import lazy_gettext


def validate_for_publish(item, **kwargs):
    doc = get_resource_service('archive').find_one(req=None, _id=item[config.ID_FIELD])
    validate_item = {'act': ITEM_PUBLISH, 'type': doc['type'], 'validate': doc}
    validation_errors = get_resource_service('validate').create([validate_item], fields=True)
    if validation_errors[0][0]:
        raise ValidationError(validation_errors[0][0])

    return item


name = 'Validate for Publish'
label = lazy_gettext('Validate for Publish')
callback = validate_for_publish
access_type = 'frontend'
action_type = 'direct'<commit_msg>Improve display of validation error messages. [SDESK-5444] (#1977)<commit_after># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from superdesk import get_resource_service, config
from superdesk.validation import ValidationError
from apps.publish.content.common import ITEM_PUBLISH
from flask_babel import lazy_gettext
import json


def validate_for_publish(item, **kwargs):
    doc = get_resource_service('archive').find_one(req=None, _id=item[config.ID_FIELD])
    validate_item = {'act': ITEM_PUBLISH, 'type': doc['type'], 'validate': doc}
    validation_errors = get_resource_service('validate').create([validate_item], fields=True)
    if validation_errors[0][0]:
        raise ValidationError(json.dumps(validation_errors[0][0]))

    return item


name = 'Validate for Publish'
label = lazy_gettext('Validate for Publish')
callback = validate_for_publish
access_type = 'frontend'
action_type = 'direct'
{'fraction_non_alphanumeric': 0.10712704736609119, 'fraction_numerical': 0.015050907481186366, 'mean_word_length': 5.627565982404692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4029282', 'n_tokens_mistral': 706, 'n_tokens_neox': 659, 'n_words': 190}