Ejemplo n.º 1
0
def store_task(project, task):
    if 'status' not in task and project.default_task_status:
        task['status'] = project.default_task_status.name

    serialized = serializers.TaskExportSerializer(data=task, context={"project": project})
    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(serialized.object, project)
            serialized.object.save()

        for task_attachment in task.get('attachments', []):
            store_attachment(project, serialized.object, task_attachment)

        for history in task.get('history', []):
            store_history(project, serialized.object, history)

        return serialized

    add_errors("tasks", serialized.errors)
    return None
Ejemplo n.º 2
0
def store_task(project, task):
    if 'status' not in task and project.default_task_status:
        task['status'] = project.default_task_status.name

    serialized = serializers.TaskExportSerializer(data=task,
                                                  context={"project": project})
    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(
                serialized.object, project)
            serialized.object.save()

        for task_attachment in task.get('attachments', []):
            store_attachment(project, serialized.object, task_attachment)

        for history in task.get('history', []):
            store_history(project, serialized.object, history)

        return serialized

    add_errors("tasks", serialized.errors)
    return None
Ejemplo n.º 3
0
def store_issue(project, data):
    serialized = serializers.IssueExportSerializer(
        data=data, context={"project": project})

    if "type" not in data and project.default_issue_type:
        data["type"] = project.default_issue_type.name

    if "status" not in data and project.default_issue_status:
        data["status"] = project.default_issue_status.name

    if "priority" not in data and project.default_priority:
        data["priority"] = project.default_priority.name

    if "severity" not in data and project.default_severity:
        data["severity"] = project.default_severity.name

    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()
        serialized.save_watchers()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(
                serialized.object, project)
            serialized.object.save()

        for attachment in data.get("attachments", []):
            store_attachment(project, serialized.object, attachment)

        history_entries = data.get("history", [])
        for history in history_entries:
            store_history(project, serialized.object, history)

        if not history_entries:
            take_snapshot(serialized.object, user=serialized.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = serialized.object.project.issuecustomattributes.all(
            ).values('id', 'name')
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(
                custom_attributes, custom_attributes_values)
            store_custom_attributes_values(
                serialized.object, custom_attributes_values, "issue",
                serializers.IssueCustomAttributesValuesExportSerializer)

        return serialized

    add_errors("issues", serialized.errors)
    return None
Ejemplo n.º 4
0
def store_issue(project, data):
    validator = validators.IssueExportValidator(data=data, context={"project": project})

    if "type" not in data and project.default_issue_type:
        data["type"] = project.default_issue_type.name

    if "status" not in data and project.default_issue_status:
        data["status"] = project.default_issue_status.name

    if "priority" not in data and project.default_priority:
        data["priority"] = project.default_priority.name

    if "severity" not in data and project.default_severity:
        data["severity"] = project.default_severity.name

    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(validator.object, project)
            validator.object.save()

        for attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, attachment)

        history_entries = data.get("history", [])
        statuses = {s.name: s.id for s in project.issue_statuses.all()}
        for history in history_entries:
            _store_history(project, validator.object, history, statuses)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.issuecustomattributes.all().values('id', 'name')
            custom_attributes_values = \
                _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                        custom_attributes_values)
            _store_custom_attributes_values(validator.object, custom_attributes_values,
                                            "issue",
                                            validators.IssueCustomAttributesValuesExportValidator)

        return validator

    add_errors("issues", validator.errors)
    return None
Ejemplo n.º 5
0
def store_user_story(project, data):
    if "status" not in data and project.default_us_status:
        data["status"] = project.default_us_status.name

    us_data = {
        key: value
        for key, value in data.items()
        if key not in ["role_points", "custom_attributes_values"]
    }
    serialized = serializers.UserStoryExportSerializer(
        data=us_data, context={"project": project})

    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()
        serialized.save_watchers()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(
                serialized.object, project)
            serialized.object.save()

        for us_attachment in data.get("attachments", []):
            store_attachment(project, serialized.object, us_attachment)

        for role_point in data.get("role_points", []):
            store_role_point(project, serialized.object, role_point)

        history_entries = data.get("history", [])
        for history in history_entries:
            store_history(project, serialized.object, history)

        if not history_entries:
            take_snapshot(serialized.object, user=serialized.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = serialized.object.project.userstorycustomattributes.all(
            ).values('id', 'name')
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(
                custom_attributes, custom_attributes_values)
            store_custom_attributes_values(
                serialized.object, custom_attributes_values, "user_story",
                serializers.UserStoryCustomAttributesValuesExportSerializer)

        return serialized

    add_errors("user_stories", serialized.errors)
    return None
Ejemplo n.º 6
0
def store_epic(project, data):
    if "status" not in data and project.default_epic_status:
        data["status"] = project.default_epic_status.name

    validator = validators.EpicExportValidator(data=data,
                                               context={"project": project})
    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(
                validator.object, project)
            validator.object.save()

        for epic_attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, epic_attachment)

        for related_user_story in data.get("related_user_stories", []):
            _store_epic_related_user_story(project, validator.object,
                                           related_user_story)

        history_entries = data.get("history", [])
        statuses = {s.name: s.id for s in project.epic_statuses.all()}
        for history in history_entries:
            _store_history(project, validator.object, history, statuses)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.epiccustomattributes.all(
            ).values("id", "name")
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(
                custom_attributes, custom_attributes_values)
            _store_custom_attributes_values(
                validator.object,
                custom_attributes_values,
                "epic",
                validators.EpicCustomAttributesValuesExportValidator,
            )

        return validator

    add_errors("epics", validator.errors)
    return None
Ejemplo n.º 7
0
def store_user_story(project, data):
    if "status" not in data and project.default_us_status:
        data["status"] = project.default_us_status.name

    us_data = {key: value for key, value in data.items() if key not in
               ["role_points", "custom_attributes_values", 'generated_from_task', 'generated_from_issue']}

    validator = validators.UserStoryExportValidator(data=us_data, context={"project": project})

    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(validator.object, project)
            validator.object.save()

        for us_attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, us_attachment)

        for role_point in data.get("role_points", []):
            _store_role_point(project, validator.object, role_point)

        history_entries = data.get("history", [])
        statuses = {s.name: s.id for s in project.us_statuses.all()}
        for history in history_entries:
            _store_history(project, validator.object, history, statuses)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.userstorycustomattributes.all().values('id', 'name')
            custom_attributes_values = \
                _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                        custom_attributes_values)

            _store_custom_attributes_values(validator.object, custom_attributes_values,
                                            "user_story",
                                            validators.UserStoryCustomAttributesValuesExportValidator)

        return validator

    add_errors("user_stories", validator.errors)
    return None
Ejemplo n.º 8
0
def store_user_story(project, data):
    if "status" not in data and project.default_us_status:
        data["status"] = project.default_us_status.name

    us_data = {key: value for key, value in data.items() if key not in
               ["role_points", "custom_attributes_values", 'generated_from_task', 'generated_from_issue']}

    validator = validators.UserStoryExportValidator(data=us_data, context={"project": project})

    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(validator.object, project)
            validator.object.save()

        for us_attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, us_attachment)

        for role_point in data.get("role_points", []):
            _store_role_point(project, validator.object, role_point)

        history_entries = data.get("history", [])
        statuses = {s.name: s.id for s in project.us_statuses.all()}
        for history in history_entries:
            _store_history(project, validator.object, history, statuses)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.userstorycustomattributes.all().values('id', 'name')
            custom_attributes_values = \
                _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                        custom_attributes_values)

            _store_custom_attributes_values(validator.object, custom_attributes_values,
                                            "user_story",
                                            validators.UserStoryCustomAttributesValuesExportValidator)

        return validator

    add_errors("user_stories", validator.errors)
    return None
Ejemplo n.º 9
0
def store_user_story(project, data):
    if "status" not in data and project.default_us_status:
        data["status"] = project.default_us_status.name

    us_data = {key: value for key, value in data.items() if key not in ["role_points", "custom_attributes_values"]}
    serialized = serializers.UserStoryExportSerializer(data=us_data, context={"project": project})

    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()
        serialized.save_watchers()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(serialized.object, project)
            serialized.object.save()

        for us_attachment in data.get("attachments", []):
            store_attachment(project, serialized.object, us_attachment)

        for role_point in data.get("role_points", []):
            store_role_point(project, serialized.object, role_point)

        history_entries = data.get("history", [])
        for history in history_entries:
            store_history(project, serialized.object, history)

        if not history_entries:
            take_snapshot(serialized.object, user=serialized.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = serialized.object.project.userstorycustomattributes.all().values("id", "name")
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(
                custom_attributes, custom_attributes_values
            )
            store_custom_attributes_values(
                serialized.object,
                custom_attributes_values,
                "user_story",
                serializers.UserStoryCustomAttributesValuesExportSerializer,
            )

        return serialized

    add_errors("user_stories", serialized.errors)
    return None
Ejemplo n.º 10
0
    def process_issues_refs(self):
        print(".. Processing issues.")
        model_cls = get_model("issues", "Issue")
        queryset = model_cls.objects.all()

        for item in self.iter_queryset(queryset):
            refval, _ = make_reference(item, item.project, create=True)
            print("process issue {0}: {1} -> {2}".format(item.pk, item.ref, refval))
            self.refmap[item.project_id]["issue"][item.ref] = refval
            item.ref = refval
            item.save()
Ejemplo n.º 11
0
    def process_tasks_refs(self):
        print(".. Processing tasks.")
        model_cls = get_model("tasks", "Task")
        queryset = model_cls.objects.only("ref")

        for item in self.iter_queryset(queryset):
            refval, _ = make_reference(item, item.project, create=True)
            print("process task {0}: {1} -> {2}".format(item.pk, item.ref, refval))
            self.refmap[item.project_id]["task"][item.ref] = refval
            item.ref = refval
            item.save(update_fields=["ref"])
Ejemplo n.º 12
0
def store_issue(project, data):
    serialized = serializers.IssueExportSerializer(data=data, context={"project": project})

    if "type" not in data and project.default_issue_type:
        data["type"] = project.default_issue_type.name

    if "status" not in data and project.default_issue_status:
        data["status"] = project.default_issue_status.name

    if "priority" not in data and project.default_priority:
        data["priority"] = project.default_priority.name

    if "severity" not in data and project.default_severity:
        data["severity"] = project.default_severity.name

    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(serialized.object, project)
            serialized.object.save()

        for attachment in data.get("attachments", []):
            store_attachment(project, serialized.object, attachment)

        for history in data.get("history", []):
            store_history(project, serialized.object, history)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = serialized.object.project.issuecustomattributes.all().values('id', 'name')
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                                               custom_attributes_values)
            store_custom_attributes_values(serialized.object, custom_attributes_values,
                                           "issue", serializers.IssueCustomAttributesValuesExportSerializer)

        return serialized

    add_errors("issues", serialized.errors)
    return None
Ejemplo n.º 13
0
def store_task(project, data):
    if "status" not in data and project.default_task_status:
        data["status"] = project.default_task_status.name

    validator = validators.TaskExportValidator(data=data, context={"project": project})
    if validator.is_valid():
        validator.object.project = project
        if validator.object.owner is None:
            validator.object.owner = validator.object.project.owner
        validator.object._importing = True
        validator.object._not_notify = True

        validator.save()
        validator.save_watchers()

        if validator.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, validator.object.ref)
        else:
            validator.object.ref, _ = refs.make_reference(validator.object, project)
            validator.object.save()

        for task_attachment in data.get("attachments", []):
            _store_attachment(project, validator.object, task_attachment)

        history_entries = data.get("history", [])
        for history in history_entries:
            _store_history(project, validator.object, history)

        if not history_entries:
            take_snapshot(validator.object, user=validator.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = validator.object.project.taskcustomattributes.all().values('id', 'name')
            custom_attributes_values = \
                _use_id_instead_name_as_key_in_custom_attributes_values(custom_attributes,
                                                                        custom_attributes_values)

            _store_custom_attributes_values(validator.object, custom_attributes_values,
                                            "task",
                                            validators.TaskCustomAttributesValuesExportValidator)

        return validator

    add_errors("tasks", validator.errors)
    return None
Ejemplo n.º 14
0
def store_task(project, data):
    if "status" not in data and project.default_task_status:
        data["status"] = project.default_task_status.name

    serialized = serializers.TaskExportSerializer(data=data, context={"project": project})
    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()
        serialized.save_watchers()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(serialized.object, project)
            serialized.object.save()

        for task_attachment in data.get("attachments", []):
            store_attachment(project, serialized.object, task_attachment)

        history_entries = data.get("history", [])
        for history in history_entries:
            store_history(project, serialized.object, history)

        if not history_entries:
            take_snapshot(serialized.object, user=serialized.object.owner)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = serialized.object.project.taskcustomattributes.all().values('id', 'name')
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(
                                                    custom_attributes, custom_attributes_values)
            store_custom_attributes_values(serialized.object, custom_attributes_values,
                                           "task", serializers.TaskCustomAttributesValuesExportSerializer)

        return serialized

    add_errors("tasks", serialized.errors)
    return None
Ejemplo n.º 15
0
def store_task(project, data):
    if "status" not in data and project.default_task_status:
        data["status"] = project.default_task_status.name

    serialized = serializers.TaskExportSerializer(data=data,
                                                  context={"project": project})
    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(
                serialized.object, project)
            serialized.object.save()

        for task_attachment in data.get("attachments", []):
            store_attachment(project, serialized.object, task_attachment)

        for history in data.get("history", []):
            store_history(project, serialized.object, history)

        custom_attributes_values = data.get("custom_attributes_values", None)
        if custom_attributes_values:
            custom_attributes = serialized.object.project.taskcustomattributes.all(
            ).values('id', 'name')
            custom_attributes_values = _use_id_instead_name_as_key_in_custom_attributes_values(
                custom_attributes, custom_attributes_values)
            store_custom_attributes_values(
                serialized.object, custom_attributes_values, "task",
                serializers.TaskCustomAttributesValuesExportSerializer)

        return serialized

    add_errors("tasks", serialized.errors)
    return None
Ejemplo n.º 16
0
def store_issue(project, data):
    serialized = serializers.IssueExportSerializer(
        data=data, context={"project": project})

    if 'type' not in data and project.default_issue_type:
        data['type'] = project.default_issue_type.name

    if 'status' not in data and project.default_issue_status:
        data['status'] = project.default_issue_status.name

    if 'priority' not in data and project.default_priority:
        data['priority'] = project.default_priority.name

    if 'severity' not in data and project.default_severity:
        data['severity'] = project.default_severity.name

    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(
                serialized.object, project)
            serialized.object.save()

        for attachment in data.get('attachments', []):
            store_attachment(project, serialized.object, attachment)
        for history in data.get('history', []):
            store_history(project, serialized.object, history)
        return serialized
    add_errors("issues", serialized.errors)
    return None
Ejemplo n.º 17
0
def store_user_story(project, userstory):
    if 'status' not in userstory and project.default_us_status:
        userstory['status'] = project.default_us_status.name

    userstory_data = {}
    for key, value in userstory.items():
        if key != 'role_points':
            userstory_data[key] = value
    serialized_us = serializers.UserStoryExportSerializer(
        data=userstory_data, context={"project": project})
    if serialized_us.is_valid():
        serialized_us.object.project = project
        if serialized_us.object.owner is None:
            serialized_us.object.owner = serialized_us.object.project.owner
        serialized_us.object._importing = True
        serialized_us.object._not_notify = True

        serialized_us.save()

        if serialized_us.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized_us.object.ref)
        else:
            serialized_us.object.ref, _ = refs.make_reference(
                serialized_us.object, project)
            serialized_us.object.save()

        for us_attachment in userstory.get('attachments', []):
            store_attachment(project, serialized_us.object, us_attachment)

        for role_point in userstory.get('role_points', []):
            store_role_point(project, serialized_us.object, role_point)

        for history in userstory.get('history', []):
            store_history(project, serialized_us.object, history)

        return serialized_us
    add_errors("user_stories", serialized_us.errors)
    return None
Ejemplo n.º 18
0
def store_issue(project, data):
    serialized = serializers.IssueExportSerializer(data=data, context={"project": project})

    if 'type' not in data and project.default_issue_type:
        data['type'] = project.default_issue_type.name

    if 'status' not in data and project.default_issue_status:
        data['status'] = project.default_issue_status.name

    if 'priority' not in data and project.default_priority:
        data['priority'] = project.default_priority.name

    if 'severity' not in data and project.default_severity:
        data['severity'] = project.default_severity.name

    if serialized.is_valid():
        serialized.object.project = project
        if serialized.object.owner is None:
            serialized.object.owner = serialized.object.project.owner
        serialized.object._importing = True
        serialized.object._not_notify = True

        serialized.save()

        if serialized.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized.object.ref)
        else:
            serialized.object.ref, _ = refs.make_reference(serialized.object, project)
            serialized.object.save()

        for attachment in data.get('attachments', []):
            store_attachment(project, serialized.object, attachment)
        for history in data.get('history', []):
            store_history(project, serialized.object, history)
        return serialized
    add_errors("issues", serialized.errors)
    return None
Ejemplo n.º 19
0
def store_user_story(project, userstory):
    if 'status' not in userstory and project.default_us_status:
        userstory['status'] = project.default_us_status.name

    userstory_data = {}
    for key, value in userstory.items():
        if key != 'role_points':
            userstory_data[key] = value
    serialized_us = serializers.UserStoryExportSerializer(data=userstory_data, context={"project": project})
    if serialized_us.is_valid():
        serialized_us.object.project = project
        if serialized_us.object.owner is None:
            serialized_us.object.owner = serialized_us.object.project.owner
        serialized_us.object._importing = True
        serialized_us.object._not_notify = True

        serialized_us.save()

        if serialized_us.object.ref:
            sequence_name = refs.make_sequence_name(project)
            if not seq.exists(sequence_name):
                seq.create(sequence_name)
            seq.set_max(sequence_name, serialized_us.object.ref)
        else:
            serialized_us.object.ref, _ = refs.make_reference(serialized_us.object, project)
            serialized_us.object.save()

        for us_attachment in userstory.get('attachments', []):
            store_attachment(project, serialized_us.object, us_attachment)

        for role_point in userstory.get('role_points', []):
            store_role_point(project, serialized_us.object, role_point)

        for history in userstory.get('history', []):
            store_history(project, serialized_us.object, history)

        return serialized_us
    add_errors("user_stories", serialized_us.errors)
    return None