Example #1
0
 def on_create(self, docs):
     """Set default metadata."""
     planning_type = get_resource_service('planning_types').find_one(
         req=None, name='planning')
     for doc in docs:
         if 'guid' not in doc:
             doc['guid'] = generate_guid(type=GUID_NEWSML)
         doc[config.ID_FIELD] = doc['guid']
         self.validate_planning(doc)
         set_original_creator(doc)
         self._set_planning_event_info(doc, planning_type)
         self._set_coverage(doc)
         self.set_planning_schedule(doc)
         # set timestamps
         update_dates_for(doc)
    def on_create(self, docs):
        for doc in docs:
            date = utc_to_local(doc.get('tz') or app.config['DEFAULT_TIMEZONE'], doc.get('date'))
            _id = date.strftime(ID_DATE_FORMAT)

            items = self.find(where={'_id': _id})
            if items.count() > 0:
                raise SuperdeskApiError.badRequestError(
                    message="Featured story already exists for this date.")

            self.validate_featured_attrribute(doc.get('items'))
            doc['_id'] = _id
            self.post_featured_planning(doc)
            # set the author
            set_original_creator(doc)

            # set timestamps
            update_dates_for(doc)
Example #3
0
    def on_create(self, docs):
        # events generated by recurring rules
        generated_events = []
        for event in docs:
            # generates an unique id
            if 'guid' not in event:
                event['guid'] = generate_guid(type=GUID_NEWSML)
            event[config.ID_FIELD] = event['guid']

            # family_id get on ingest we don't need it planning
            event.pop('family_id', None)

            # set the author
            set_original_creator(event)

            # set timestamps
            update_dates_for(event)

            # overwrite expiry date
            overwrite_event_expiry_date(event)

            # We ignore the 'update_method' on create
            if 'update_method' in event:
                del event['update_method']

            # Remove the 'expired' flag if it is set, as no new Event can be created
            # as expired
            if 'expired' in event:
                del event['expired']

            set_planning_schedule(event)
            planning_item = event.get('_planning_item')

            # validate event
            self.validate_event(event)

            # generates events based on recurring rules
            if event['dates'].get('recurring_rule', None):
                recurring_events = generate_recurring_events(event)
                generated_events.extend(recurring_events)
                # remove the event that contains the recurring rule. We don't need it anymore
                docs.remove(event)

                # Set the current Event to the first Event in the new series
                # This will make sure the ID of the Event can be used when
                # using 'event' from here on, such as when linking to a Planning item
                event = recurring_events[0]
                # And set the Planning Item from the original
                # (generate_recurring_events removes this field)
                event['_planning_item'] = planning_item

            if event['state'] == 'ingested':
                events_history = get_resource_service('events_history')
                events_history.on_item_created([event])

            if planning_item:
                self._link_to_planning(event)
                del event['_planning_item']

        if generated_events:
            docs.extend(generated_events)