def on_created(self, docs): push_notification(self.datasource, created=1) push_notification('task:new') for doc in docs: insert_into_versions(doc['_id']) if is_assigned_to_a_desk(doc): add_activity(ACTIVITY_CREATE, 'added new task {{ subject }} of type {{ type }}', self.datasource, item=doc, subject=get_subject(doc), type=doc[ITEM_TYPE])
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 = str(updates.get('task', {}).get('stage', '')) old_stage_id = str(original.get('task', {}).get('stage', '')) new_user_id = updates.get('task', {}).get('user', '') if new_stage_id and new_stage_id != old_stage_id: updates[ITEM_OPERATION] = ITEM_SEND send_to(doc=original, update=updates, desk_id=None, stage_id=new_stage_id, user_id=new_user_id) resolve_document_version(updates, ARCHIVE, 'PATCH', original) update_version(updates, original)
def on_updated(self, updates, original): updated = copy(original) updated.update(updates) if self._stage_changed(updates, original): insert_into_versions(doc=updated) new_task = updates.get('task', {}) old_task = original.get('task', {}) if new_task.get('stage') != old_task.get('stage'): push_notification('task:stage', new_stage=str(new_task.get('stage', '')), old_stage=str(old_task.get('stage', '')), new_desk=str(new_task.get('desk', '')), old_desk=str(old_task.get('desk', '')) ) else: push_notification(self.datasource, updated=1) if is_assigned_to_a_desk(updated): if self.__is_content_assigned_to_new_desk(original, updates) and \ not self._stage_changed(updates, original): insert_into_versions(doc=updated) add_activity(ACTIVITY_UPDATE, 'updated task {{ subject }} for item {{ type }}', self.datasource, item=updated, subject=get_subject(updated), type=updated['type'])