Beispiel #1
0
    def __set_published_item_expiry(self, doc):
        """
        Set the expiry for the published item
        :param dict doc: doc on which publishing action is performed
        """
        desk_id = doc.get('task', {}).get('desk', None)
        stage_id = doc.get('task', {}).get('stage', None)

        doc['expiry'] = get_expiry(desk_id, stage_id, offset=doc.get(EMBARGO)) if doc.get(EMBARGO) else \
            get_expiry(desk_id, stage_id)
Beispiel #2
0
    def __set_published_item_expiry(self, doc):
        """
        Set the expiry for the published item
        :param dict doc: doc on which publishing action is performed
        """
        desk_id = doc.get("task", {}).get("desk", None)
        stage_id = doc.get("task", {}).get("stage", None)

        doc["expiry"] = (
            get_expiry(desk_id, stage_id, offset=doc.get(EMBARGO))
            if doc.get(EMBARGO)
            else get_expiry(desk_id, stage_id)
        )
Beispiel #3
0
def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None):
    """Send item to given desk and stage.
    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """

    original_task = doc.setdefault("task", {})
    current_stage = None
    if original_task.get("stage"):
        current_stage = get_resource_service("stages").find_one(req=None, _id=original_task.get("stage"))
    destination_stage = calculate_expiry_from = None
    task = {"desk": desk_id, "stage": stage_id, "user": original_task.get("user") if user_id is None else user_id}

    if current_stage:
        apply_stage_rule(doc, update, current_stage, is_incoming=False)

    if desk_id and not stage_id:
        desk = superdesk.get_resource_service("desks").find_one(req=None, _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError("Invalid desk identifier %s" % desk_id)

        calculate_expiry_from = desk
        task["desk"] = desk_id
        task["stage"] = desk.get("incoming_stage")
        destination_stage = get_resource_service("stages").find_one(req=None, _id=desk.get("incoming_stage"))

    if stage_id:
        destination_stage = get_resource_service("stages").find_one(req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError("Invalid stage identifier %s" % stage_id)

        calculate_expiry_from = destination_stage
        task["desk"] = destination_stage["desk"]
        task["stage"] = stage_id

    if destination_stage:
        apply_stage_rule(doc, update, destination_stage, is_incoming=True)
        if destination_stage.get("task_status"):
            task["status"] = destination_stage["task_status"]

    if update:
        update.setdefault("task", {})
        update["task"].update(task)
        update["expiry"] = get_expiry(desk_or_stage_doc=calculate_expiry_from)
    else:
        doc["task"].update(task)
        doc["expiry"] = get_expiry(desk_or_stage_doc=calculate_expiry_from)
Beispiel #4
0
def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None):
    """Send item to given desk and stage.
    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """
    task = doc.get('task', {})
    current_stage = get_resource_service('stages').find_one(req=None, _id=task.get('stage'))
    destination_stage = None
    task.setdefault('desk', desk_id)
    task.setdefault('stage', stage_id)
    task.setdefault('user', user_id)

    calculate_expiry_from = None

    if current_stage:
        apply_stage_rule(doc, update, current_stage, is_incoming=False)

    if desk_id and not stage_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None, _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError('Invalid desk identifier %s' % desk_id)

        calculate_expiry_from = desk
        task['desk'] = desk_id
        task['stage'] = desk.get('incoming_stage')
        destination_stage = get_resource_service('stages').find_one(req=None, _id=desk.get('incoming_stage'))

    if stage_id:
        destination_stage = get_resource_service('stages').find_one(req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError('Invalid stage identifier %s' % stage_id)

        calculate_expiry_from = destination_stage
        task['desk'] = destination_stage['desk']
        task['stage'] = stage_id

    if destination_stage:
        apply_stage_rule(doc, update, destination_stage, is_incoming=True)
        if destination_stage.get('task_status'):
            task['status'] = destination_stage['task_status']

    if update:
        update['task'] = task
        update['expiry'] = get_expiry(desk_or_stage_doc=calculate_expiry_from)
    else:
        doc['task'] = task
        doc['expiry'] = get_expiry(desk_or_stage_doc=calculate_expiry_from)
Beispiel #5
0
def send_to(doc, desk_id=None, stage_id=None):
    """Send item to given desk and stage.

    :param doc: item to be sent
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """
    task = doc.get('task', {})
    task.setdefault('desk', desk_id)
    task.setdefault('stage', stage_id)

    calculate_expiry_from = None

    if desk_id and not stage_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None, _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError('Invalid desk identifier %s' % desk_id)

        calculate_expiry_from = desk
        task['desk'] = desk_id
        task['stage'] = desk.get('incoming_stage')

    if stage_id:
        stage = get_resource_service('stages').find_one(req=None, _id=stage_id)
        if not stage:
            raise SuperdeskApiError.notFoundError('Invalid stage identifier %s' % stage_id)

        calculate_expiry_from = stage
        task['desk'] = stage['desk']
        task['stage'] = stage_id
        if stage.get('task_status'):
            task['status'] = stage['task_status']

    doc['task'] = task
    doc['expiry'] = get_expiry(desk_or_stage_doc=calculate_expiry_from)
Beispiel #6
0
def send_to(doc, desk_id=None, stage_id=None):
    """Send item to given desk and stage.

    :param doc: item to be sent
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """
    task = doc.get('task', {})
    task.setdefault('desk', desk_id)
    task.setdefault('stage', stage_id)

    if desk_id and not stage_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None,
                                                                _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError(
                'Invalid desk identifier %s' % desk_id)
        task['stage'] = desk.get('incoming_stage')
    if task['stage']:
        stage = get_resource_service('stages').find_one(req=None,
                                                        _id=task['stage'])
        if not stage:
            raise SuperdeskApiError.notFoundError(
                'Invalid stage identifier %s' % task['stage'])
        if stage.get('task_status'):
            doc['task'] = doc.get('task', {})
            doc['task']['status'] = stage['task_status']
    doc['task'] = task
    doc['expiry'] = get_expiry(desk_id, stage_id)
    def __set_published_item_expiry(self, doc):
        """Set the expiry for the published item.

        :param dict doc: doc on which publishing action is performed
        """
        desk_id = doc.get('task', {}).get('desk', None)
        stage_id = doc.get('task', {}).get('stage', None)
        offset = get_utc_schedule(doc, PUBLISH_SCHEDULE) or get_utc_schedule(doc, EMBARGO)
        doc['expiry'] = get_expiry(desk_id, stage_id, offset=offset)
Beispiel #8
0
    def __set_published_item_expiry(self, doc):
        """
        Set the expiry for the published item
        :param dict doc: doc on which publishing action is performed
        """
        desk_id = doc.get('task', {}).get('desk', None)
        stage_id = doc.get('task', {}).get('stage', None)

        doc['expiry'] = get_expiry(desk_id, stage_id, offset=doc.get(EMBARGO, doc.get('publish_schedule')))
Beispiel #9
0
    def __set_published_item_expiry(self, doc):
        """Set the expiry for the published item.

        :param dict doc: doc on which publishing action is performed
        """
        desk_id = doc.get('task', {}).get('desk', None)
        stage_id = doc.get('task', {}).get('stage', None)
        offset = get_utc_schedule(doc, PUBLISH_SCHEDULE) or get_utc_schedule(doc, EMBARGO)
        doc['expiry'] = get_expiry(desk_id, stage_id, offset=offset)
Beispiel #10
0
    def _set_item_expiry(self, updates, original):
        """
        Set the expiry for the item
        :param dict updates: doc on which publishing action is performed
        """
        desk_id = original.get('task', {}).get('desk')
        stage_id = original.get('task', {}).get('stage')
        offset = updates.get(EMBARGO, original.get(EMBARGO)) or \
            updates.get('publish_schedule', original.get('publish_schedule'))

        updates['expiry'] = get_expiry(desk_id, stage_id, offset=offset)
Beispiel #11
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = updates.get('task', {}).get('stage', '')
     old_stage_id = original.get('task', {}).get('stage', '')
     if new_stage_id and new_stage_id != old_stage_id:
         new_stage = get_resource_service('stages').find_one(req=None, _id=new_stage_id)
         if not new_stage:
             raise SuperdeskApiError.notFoundError('Invalid stage identifier %s' % new_stage)
         updates['expiry'] = get_expiry(new_stage['desk'], new_stage_id)
         if new_stage.get('task_status'):
             updates['task']['status'] = new_stage['task_status']
Beispiel #12
0
    def _set_item_expiry(self, updates, original):
        """
        Set the expiry for the item
        :param dict updates: doc on which publishing action is performed
        """
        desk_id = original.get('task', {}).get('desk')
        stage_id = original.get('task', {}).get('stage')

        if EMBARGO in updates or PUBLISH_SCHEDULE in updates:
            offset = get_utc_schedule(updates, PUBLISH_SCHEDULE) or get_utc_schedule(updates, EMBARGO)
        elif EMBARGO in original or PUBLISH_SCHEDULE in original:
            offset = get_utc_schedule(original, PUBLISH_SCHEDULE) or get_utc_schedule(original, EMBARGO)

        updates['expiry'] = get_expiry(desk_id, stage_id, offset=offset)
Beispiel #13
0
 def on_update(self, updates, original):
     self.update_times(updates)
     if is_assigned_to_a_desk(updates):
         self.__update_state(updates, original)
     new_stage_id = updates.get('task', {}).get('stage', '')
     old_stage_id = original.get('task', {}).get('stage', '')
     if new_stage_id and new_stage_id != old_stage_id:
         new_stage = get_resource_service('stages').find_one(
             req=None, _id=new_stage_id)
         if not new_stage:
             raise SuperdeskApiError.notFoundError(
                 'Invalid stage identifier %s' % new_stage)
         updates['expiry'] = get_expiry(new_stage['desk'], new_stage_id)
         if new_stage.get('task_status'):
             updates['task']['status'] = new_stage['task_status']
Beispiel #14
0
    def _set_item_expiry(self, updates, original):
        """Set the expiry for the item.

        :param dict updates: doc on which publishing action is performed
        """
        desk_id = original.get("task", {}).get("desk")
        stage_id = original.get("task", {}).get("stage")

        if EMBARGO in updates or PUBLISH_SCHEDULE in updates:
            offset = get_utc_schedule(updates, PUBLISH_SCHEDULE) or get_utc_schedule(updates, EMBARGO)
        elif EMBARGO in original or PUBLISH_SCHEDULE in original:
            offset = get_utc_schedule(original, PUBLISH_SCHEDULE) or get_utc_schedule(original, EMBARGO)

        if app.settings.get("PUBLISHED_CONTENT_EXPIRY_MINUTES"):
            updates["expiry"] = get_expiry_date(app.settings["PUBLISHED_CONTENT_EXPIRY_MINUTES"], offset=offset)
        else:
            updates["expiry"] = get_expiry(desk_id, stage_id, offset=offset)
Beispiel #15
0
    def _set_item_expiry(self, updates, original):
        """Set the expiry for the item.

        :param dict updates: doc on which publishing action is performed
        """
        desk_id = original.get('task', {}).get('desk')
        stage_id = original.get('task', {}).get('stage')

        if EMBARGO in updates or PUBLISH_SCHEDULE in updates:
            offset = get_utc_schedule(updates, PUBLISH_SCHEDULE) or get_utc_schedule(updates, EMBARGO)
        elif EMBARGO in original or PUBLISH_SCHEDULE in original:
            offset = get_utc_schedule(original, PUBLISH_SCHEDULE) or get_utc_schedule(original, EMBARGO)

        if app.settings.get('PUBLISHED_CONTENT_EXPIRY_MINUTES'):
            updates['expiry'] = get_expiry_date(app.settings['PUBLISHED_CONTENT_EXPIRY_MINUTES'], offset=offset)
        else:
            updates['expiry'] = get_expiry(desk_id, stage_id, offset=offset)
Beispiel #16
0
def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None):
    """Send item to given desk and stage.
    Applies the outgoing and incoming macros of current and destination stages

    :param doc: original document to be sent
    :param update: updates for the document
    :param desk: id of desk where item should be sent
    :param stage: optional stage within the desk
    """

    original_task = doc.setdefault('task', {})
    current_stage = None
    if original_task.get('stage'):
        current_stage = get_resource_service('stages').find_one(
            req=None, _id=original_task.get('stage'))
    destination_stage = calculate_expiry_from = None
    task = {
        'desk': desk_id,
        'stage': stage_id,
        'user': original_task.get('user') if user_id is None else user_id
    }

    if current_stage:
        apply_stage_rule(doc, update, current_stage, is_incoming=False)

    if desk_id and not stage_id:
        desk = superdesk.get_resource_service('desks').find_one(req=None,
                                                                _id=desk_id)
        if not desk:
            raise SuperdeskApiError.notFoundError(
                'Invalid desk identifier %s' % desk_id)

        calculate_expiry_from = desk
        task['desk'] = desk_id
        task['stage'] = desk.get('incoming_stage')
        destination_stage = get_resource_service('stages').find_one(
            req=None, _id=desk.get('incoming_stage'))

    if stage_id:
        destination_stage = get_resource_service('stages').find_one(
            req=None, _id=stage_id)
        if not destination_stage:
            raise SuperdeskApiError.notFoundError(
                'Invalid stage identifier %s' % stage_id)

        calculate_expiry_from = destination_stage
        task['desk'] = destination_stage['desk']
        task['stage'] = stage_id

    if destination_stage:
        apply_stage_rule(doc, update, destination_stage, is_incoming=True)
        if destination_stage.get('task_status'):
            task['status'] = destination_stage['task_status']

    if update:
        update.setdefault('task', {})
        update['task'].update(task)
        update['expiry'] = get_expiry(desk_or_stage_doc=calculate_expiry_from)
    else:
        doc['task'].update(task)
        doc['expiry'] = get_expiry(desk_or_stage_doc=calculate_expiry_from)