<commit_before># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2016 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.errors import SuperdeskApiError
from superdesk.services import BaseService

from superdesk.metadata.item import metadata_schema
from superdesk.resource import Resource


class SavedActivityReportResource(Resource):
    """Saved Activity Report schema
    """

    schema = {
        'name': {
            'type': 'string',
            'required': True,
            'minlength': 1
        },
        'description': {
            'type': 'string'
        },
        'is_global': {
            'type': 'boolean',
            'default': False
        },
        'owner': Resource.rel('users', nullable=True),
        'operation': {
            'type': 'string',
            'required': True
        },
        'desk': Resource.rel('desks', nullable=True),
        'operation_date': {
            'type': 'datetime',
            'required': True
        },
        'subject': metadata_schema['subject'],
        'keywords': metadata_schema['keywords'],
        'group_by': {
            'type': 'list'
        }
    }
    item_methods = ['GET', 'PATCH', 'PUT', 'DELETE']
    resource_methods = ['GET', 'POST']
    privileges = {'POST': 'activity_reports', 'PATCH': 'activity_reports',
                  'PUT': 'activity_reports', 'DELETE': 'activity_reports'}


class SavedActivityReportService(BaseService):
    """Save activity reports service
    """

    def create(self, docs, **kwargs):
        for doc in docs:
            if doc.get('group_by') and doc.get('desk'):
                raise SuperdeskApiError.badRequestError('The desk must not be defined when group by is defined.')
            if not doc.get('group_by', False) and not doc.get('desk'):
                raise SuperdeskApiError.badRequestError('The desk is required when group by desk is false')
        return super().create(docs, **kwargs)
<commit_msg>needed fields for saving the reports (#738)<commit_after># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2016 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.errors import SuperdeskApiError
from superdesk.services import BaseService

from superdesk.metadata.item import metadata_schema
from superdesk.resource import Resource


class SavedActivityReportResource(Resource):
    """Saved Activity Report schema
    """

    schema = {
        'name': {
            'type': 'string',
            'required': True,
            'minlength': 1
        },
        'description': {
            'type': 'string'
        },
        'is_global': {
            'type': 'boolean',
            'default': False
        },
        'owner': Resource.rel('users', nullable=True),
        'operation': {
            'type': 'string',
            'required': True
        },
        'desk': Resource.rel('desks', nullable=True),
        'operation_date': {
            'type': 'datetime',
            'required': True
        },
        'subject': metadata_schema['subject'],
        'category': metadata_schema['anpa_category'],
        'keywords': metadata_schema['keywords'],
        'urgency': metadata_schema['urgency'],
        'priority': metadata_schema['priority'],
        'subscriber': {'type': 'string'},
        'group_by': {
            'type': 'list'
        }
    }
    item_methods = ['GET', 'PATCH', 'PUT', 'DELETE']
    resource_methods = ['GET', 'POST']
    privileges = {'POST': 'activity_reports', 'PATCH': 'activity_reports',
                  'PUT': 'activity_reports', 'DELETE': 'activity_reports'}


class SavedActivityReportService(BaseService):
    """Save activity reports service
    """

    def create(self, docs, **kwargs):
        for doc in docs:
            if doc.get('group_by') and doc.get('desk'):
                raise SuperdeskApiError.badRequestError('The desk must not be defined when group by is defined.')
            if not doc.get('group_by', False) and not doc.get('desk'):
                raise SuperdeskApiError.badRequestError('The desk is required when group by desk is false')
        return super().create(docs, **kwargs)

{'fraction_non_alphanumeric': 0.13256738842244808, 'fraction_numerical': 0.003314184710561202, 'mean_word_length': 2.4930555555555554, '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': '1774572', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1226, 'n_words': 347}