示例#1
0
def redo_work_item(work_item: models.WorkItem,
                   user: BaseUser,
                   context: Optional[dict] = None) -> models.WorkItem:
    """
    Redo a work item.

    >>> redo_work_item(
    ...     work_item=models.WorkItem.objects.first(),
    ...     user=AnonymousUser()
    ... )
    <WorkItem: WorkItem object (some-uuid)>
    """
    domain_logic.RedoWorkItemLogic.validate_for_redo(work_item)

    validated_data = domain_logic.RedoWorkItemLogic.pre_redo(
        work_item, {}, user, context)

    domain_logic.RedoWorkItemLogic.set_succeeding_work_item_status_redo(
        work_item)

    update_model(work_item, validated_data)

    domain_logic.RedoWorkItemLogic.post_redo(work_item, user, context)

    return work_item
示例#2
0
    def update(instance: BaseModel, validated_data, user: Optional[BaseUser] = None):
        if user:
            validated_data["modified_by_user"] = user.username
            validated_data["modified_by_group"] = user.group

        update_model(instance, validated_data)
        instance.refresh_from_db()

        return instance
示例#3
0
    def update(validated_data, answer):
        if answer.question.type == models.Question.TYPE_TABLE:
            documents = validated_data.pop("documents")
            answer.unlink_unused_rows(docs_to_keep=documents)

        if (answer.question.type == models.Question.TYPE_FILE
                and answer.file.name is not validated_data["file"]):
            answer.file.delete()
            validated_data = __class__.set_file(validated_data)

        update_model(answer, validated_data)

        if answer.question.type == models.Question.TYPE_TABLE:
            answer.create_answer_documents(documents)

        answer.refresh_from_db()
        return answer
示例#4
0
文件: api.py 项目: luytena/caluma
def skip_work_item(work_item: models.WorkItem,
                   user: BaseUser,
                   context: Optional[dict] = None) -> models.WorkItem:
    """
    Skip a work item (just like `SkipWorkItem`).

    >>> skip_work_item(
    ...     work_item=models.WorkItem.first(),
    ...     user=AnonymousUser()
    ... )
    <WorkItem: WorkItem object (some-uuid)>
    """
    domain_logic.SkipWorkItemLogic.validate_for_skip(work_item)

    validated_data = domain_logic.SkipWorkItemLogic.pre_skip(
        work_item, {}, user, context)

    update_model(work_item, validated_data)

    domain_logic.SkipWorkItemLogic.post_skip(work_item, user, context)

    return work_item
示例#5
0
文件: api.py 项目: luytena/caluma
def complete_work_item(work_item: models.WorkItem,
                       user: BaseUser,
                       context: Optional[dict] = None) -> models.WorkItem:
    """
    Complete a work item (just like `completeWorkItem`).

    >>> complete_work_item(
    ...     work_item=models.WorkItem.first(),
    ...     user=AnonymousUser()
    ... )
    <WorkItem: WorkItem object (some-uuid)>
    ```
    """
    domain_logic.CompleteWorkItemLogic.validate_for_complete(work_item, user)
    validated_data = domain_logic.CompleteWorkItemLogic.pre_complete(
        work_item, {}, user, context)

    update_model(work_item, validated_data)

    domain_logic.CompleteWorkItemLogic.post_complete(work_item, user, context)

    return work_item
示例#6
0
 def update(document, **kwargs):
     update_model(document, kwargs)