How to use the eve.utils.config function in Eve

To help you get started, we’ve selected a few Eve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github superdesk / superdesk-planning / server / planning / assignments / assignments.py View on Github external
def on_fetched_resource_archive(self, docs):
        self._enhance_archive_items(docs.get(config.ITEMS, []))
github superdesk / superdesk-planning / server / planning / assignments / assignments_complete.py View on Github external
def update(self, id, updates, original):
        user = get_user(required=True).get(config.ID_FIELD, '')
        session = get_auth().get(config.ID_FIELD, '')

        original_assigned_to = deepcopy(original).get('assigned_to')
        if not updates.get('assigned_to'):
            updates['assigned_to'] = {}
        original_assigned_to.update(updates['assigned_to'])
        updates['assigned_to'] = original_assigned_to

        assignments_service = get_resource_service('assignments')
        # If we are confirming availability, save the revert state for revert action
        text_assignment = assignments_service.is_text_assignment(original)
        if not text_assignment:
            updates['assigned_to']['revert_state'] = updates['assigned_to']['state']

        updates['assigned_to']['state'] = get_next_assignment_status(updates, ASSIGNMENT_WORKFLOW_STATE.COMPLETED)

        remove_lock_information(updates)
github superdesk / superdesk-planning / server / planning / coverage.py View on Github external
if user and user.get(config.ID_FIELD):
                planning['assigned_to']['assigned_by'] = user[config.ID_FIELD]

            planning['assigned_to']['assigned_date'] = utcnow()
            if planning['assigned_to'].get('user'):
                # Done to avoid fetching users data for every assignment
                # Because user assigned can also be a provider whose qcode
                # might be an invalid GUID, check if the user assigned is a valid user (GUID)
                # However, in a rare case where qcode of a provider is a valid GUID,
                # This will create activity records - inappropirate
                if ObjectId.is_valid(planning['assigned_to'].get('user')):
                    add_activity(ACTIVITY_UPDATE,
                                 '{{assignor}} assigned a coverage to {{assignee}}',
                                 self.datasource,
                                 notify=[planning['assigned_to'].get('user')],
                                 assignor=user.get('username') if str(user.get(config.ID_FIELD, None)) != planning[
                                     'assigned_to'].get('user') else 'You',
                                 assignee='you' if str(user.get(config.ID_FIELD, None)) != planning['assigned_to'].get(
                                     'user') else 'yourself')
github pyeve / eve / eve / io / mongo / mongo.py View on Github external
field.
        """
        id_field = config.DOMAIN[resource]['id_field']
        query = {id_field: id_}
        if config.ETAG in original:
            query[config.ETAG] = original[config.ETAG]

        datasource, filter_, _, _ = self._datasource_ex(
            resource, query)

        coll = self.get_collection_with_write_concern(datasource, resource)
        try:
            result = coll.replace_one(filter_, changes) if replace else \
                coll.update_one(filter_, changes)

            if (result and result.acknowledged and config.IF_MATCH and
                    result.modified_count == 0):
                raise self.OriginalChangedError()
        except pymongo.errors.DuplicateKeyError as e:
            abort(400, description=debug_error_message(
                'pymongo.errors.DuplicateKeyError: %s' % e
            ))
        except pymongo.errors.OperationFailure as e:
            # server error codes and messages changed between 2.4 and 2.6/3.0.
            server_version = \
                self.driver.db.client.server_info()['version'][:3]
            if (
                (server_version == '2.4' and e.code in (13596, 10148)) or
                (server_version in ('2.6', '3.0', '3.2') and
                    e.code in (66, 16837))
            ):
                # attempt to update an immutable field. this usually
github superdesk / superdesk-planning / server / planning / assignments / assignments_history.py View on Github external
def _save_history(self, assignment, update, operation):
        history = {
            'assignment_id': assignment[config.ID_FIELD],
            'user_id': self.get_user_id(),
            'operation': operation,
            'update': update
        }

        self.post([history])
github pyeve / eve / eve / io / mongo / mongo.py View on Github external
def sanitize_keys(spec):
            ops = set([op for op in spec.keys() if op[0] == '$'])
            unknown = ops - Mongo.operators
            if unknown:
                abort(400, description=debug_error_message(
                    'Query contains unknown or unsupported operators: %s' %
                    ', '.join(unknown)
                ))

            if set(spec.keys()) & set(config.MONGO_QUERY_BLACKLIST):
                abort(400, description=debug_error_message(
                    'Query contains operators banned in MONGO_QUERY_BLACKLIST'
                ))
github superdesk / superdesk-planning / server / planning / assignments / assignments.py View on Github external
def _publish_planning(item):
                item.pop(config.VERSION, None)
                item.pop('item_id', None)
                version, item = get_version_item_for_post(item)

                # Create an entry in the planning versions collection for this published version
                version_id = get_resource_service('published_planning').post([{'item_id': item['_id'],
                                                                               'version': version,
                                                                               'type': 'planning',
                                                                               'published_item': item}])
                if version_id:
                    # Asynchronously enqueue the item for publishing.
                    enqueue_planning_item.apply_async(kwargs={'id': version_id[0]}, serializer="eve/json")
                else:
                    logger.error('Failed to save planning version for planning item id {}'.format(item['_id']))
github superdesk / superdesk-planning / server / planning / events / events_history.py View on Github external
def _save_history(self, event, update, operation):
        history = {
            'event_id': event[config.ID_FIELD],
            'user_id': self.get_user_id(),
            'operation': operation,
            'update': update
        }
        # a post action is recorded as a special case
        if operation == 'update':
            if 'scheduled' == update.get('state', ''):
                history['operation'] = 'post'
            elif 'canceled' == update.get('state', ''):
                history['operation'] = 'unpost'
        elif operation == 'create' and 'ingested' == update.get('state', ''):
            history['operation'] = 'ingested'
        self.post([history])
github superdesk / superdesk-planning / server / planning / events / events_post.py View on Github external
def post_related_plannings(self, plannings, new_post_state):
        # Check to see if we are un-posting, we need to unpost it's planning item
        if new_post_state != POST_STATE.CANCELLED:
            return

        planning_post_service = get_resource_service('planning_post')
        planning_spike_service = get_resource_service('planning_spike')
        docs = []
        for planning in plannings:
            if not planning.get('pubstatus') and planning.get('state') in\
                    [WORKFLOW_STATE.DRAFT, WORKFLOW_STATE.POSTPONED, WORKFLOW_STATE.CANCELLED]:
                planning_spike_service.patch(planning.get(config.ID_FIELD), planning)
            elif planning.get('pubstatus') != POST_STATE.CANCELLED:
                docs.append({
                    'planning': planning.get(config.ID_FIELD),
                    'etag': planning.get('etag'),
                    'pubstatus': POST_STATE.CANCELLED
                })

        # unpost all required planning items
        if len(docs) > 0:
            planning_post_service.post(docs)