Exemple #1
0
class MilestoneExportValidator(WatcheableObjectModelValidatorMixin):
    owner = UserRelatedField(required=False)
    modified_date = serializers.DateTimeField(required=False)
    estimated_start = serializers.DateField(required=False)
    estimated_finish = serializers.DateField(required=False)

    def __init__(self, *args, **kwargs):
        project = kwargs.pop('project', None)
        super(MilestoneExportValidator, self).__init__(*args, **kwargs)
        if project:
            self.project = project

    def validate_name(self, attrs, source):
        """
        Check the milestone name is not duplicated in the project
        """
        name = attrs[source]
        qs = self.project.milestones.filter(name=name)
        if qs.exists():
            raise ValidationError(_("Name duplicated for the project"))

        return attrs

    class Meta:
        model = milestones_models.Milestone
        exclude = ('id', 'project')
Exemple #2
0
class WikiPageExportValidator(WatcheableObjectModelValidatorMixin):
    owner = UserRelatedField(required=False)
    last_modifier = UserRelatedField(required=False)
    modified_date = serializers.DateTimeField(required=False)

    class Meta:
        model = wiki_models.WikiPage
        exclude = ('id', 'project')
Exemple #3
0
class TaskExportValidator(WatcheableObjectModelValidatorMixin):
    owner = UserRelatedField(required=False)
    status = ProjectRelatedField(slug_field="name")
    user_story = ProjectRelatedField(slug_field="ref", required=False)
    milestone = ProjectRelatedField(slug_field="name", required=False)
    assigned_to = UserRelatedField(required=False)
    modified_date = serializers.DateTimeField(required=False)
    due_date = serializers.DateTimeField(required=False)

    class Meta:
        model = tasks_models.Task
        exclude = ('id', 'project')

    def custom_attributes_queryset(self, project):
        if project.id not in _custom_tasks_attributes_cache:
            _custom_tasks_attributes_cache[project.id] = list(project.taskcustomattributes.all().values('id', 'name'))
        return _custom_tasks_attributes_cache[project.id]
Exemple #4
0
class AttachmentExportValidator(validators.ModelValidator):
    owner = UserRelatedField(required=False)
    attached_file = FileField()
    modified_date = serializers.DateTimeField(required=False)

    class Meta:
        model = attachments_models.Attachment
        exclude = ('id', 'content_type', 'object_id', 'project')
Exemple #5
0
class UserStoryExportValidator(WatcheableObjectModelValidatorMixin):
    role_points = RolePointsExportValidator(many=True, required=False)
    owner = UserRelatedField(required=False)
    assigned_to = UserRelatedField(required=False)
    assigned_users = UserRelatedField(many=True, required=False)
    status = ProjectRelatedField(slug_field="name")
    milestone = ProjectRelatedField(slug_field="name", required=False)
    modified_date = serializers.DateTimeField(required=False)
    generated_from_issue = ProjectRelatedField(slug_field="ref", required=False)
    generated_from_task = ProjectRelatedField(slug_field="ref", required=False)
    due_date = serializers.DateTimeField(required=False)

    class Meta:
        model = userstories_models.UserStory
        exclude = ('id', 'project', 'points', 'tasks')

    def custom_attributes_queryset(self, project):
        if project.id not in _custom_userstories_attributes_cache:
            _custom_userstories_attributes_cache[project.id] = list(
                project.userstorycustomattributes.all().values('id', 'name')
            )
        return _custom_userstories_attributes_cache[project.id]
Exemple #6
0
class EpicExportValidator(WatcheableObjectModelValidatorMixin):
    owner = UserRelatedField(required=False)
    assigned_to = UserRelatedField(required=False)
    status = ProjectRelatedField(slug_field="name")
    modified_date = serializers.DateTimeField(required=False)
    user_stories = EpicRelatedUserStoryExportValidator(many=True, required=False)

    class Meta:
        model = epics_models.Epic
        exclude = ('id', 'project')

    def custom_attributes_queryset(self, project):
        if project.id not in _custom_epics_attributes_cache:
            _custom_epics_attributes_cache[project.id] = list(
                project.epiccustomattributes.all().values('id', 'name')
            )
        return _custom_epics_attributes_cache[project.id]
Exemple #7
0
class HistoryExportValidator(validators.ModelValidator):
    user = HistoryUserField()
    diff = HistoryDiffField(required=False)
    snapshot = HistorySnapshotField(required=False)
    values = HistoryValuesField(required=False)
    comment = CommentField(required=False)
    delete_comment_date = serializers.DateTimeField(required=False)
    delete_comment_user = HistoryUserField(required=False)

    class Meta:
        model = history_models.HistoryEntry
        exclude = ("id", "comment_html", "key", "project")

    def restore_object(self, attrs, instance=None):
        snapshot = attrs["snapshot"]
        statuses = self.context.get("statuses", {})
        if "status" in snapshot:
            status_id = statuses.get(snapshot["status"], None)
            attrs["snapshot"]["status"] = status_id

        instance = super(HistoryExportValidator,
                         self).restore_object(attrs, instance)
        return instance
Exemple #8
0
class ProjectExportValidator(WatcheableObjectModelValidatorMixin):
    logo = FileField(required=False)
    anon_permissions = PgArrayField(required=False)
    public_permissions = PgArrayField(required=False)
    modified_date = serializers.DateTimeField(required=False)
    roles = RoleExportValidator(many=True, required=False)
    owner = UserRelatedField(required=False)
    memberships = MembershipExportValidator(many=True, required=False)
    points = PointsExportValidator(many=True, required=False)
    us_statuses = UserStoryStatusExportValidator(many=True, required=False)
    task_statuses = TaskStatusExportValidator(many=True, required=False)
    issue_types = IssueTypeExportValidator(many=True, required=False)
    issue_statuses = IssueStatusExportValidator(many=True, required=False)
    priorities = PriorityExportValidator(many=True, required=False)
    severities = SeverityExportValidator(many=True, required=False)
    tags_colors = JSONField(required=False)
    creation_template = serializers.SlugRelatedField(slug_field="slug", required=False)
    default_points = serializers.SlugRelatedField(slug_field="name", required=False)
    default_us_status = serializers.SlugRelatedField(slug_field="name", required=False)
    default_task_status = serializers.SlugRelatedField(slug_field="name", required=False)
    default_priority = serializers.SlugRelatedField(slug_field="name", required=False)
    default_severity = serializers.SlugRelatedField(slug_field="name", required=False)
    default_issue_status = serializers.SlugRelatedField(slug_field="name", required=False)
    default_issue_type = serializers.SlugRelatedField(slug_field="name", required=False)
    userstorycustomattributes = UserStoryCustomAttributeExportValidator(many=True, required=False)
    taskcustomattributes = TaskCustomAttributeExportValidator(many=True, required=False)
    issuecustomattributes = IssueCustomAttributeExportValidator(many=True, required=False)
    user_stories = UserStoryExportValidator(many=True, required=False)
    tasks = TaskExportValidator(many=True, required=False)
    milestones = MilestoneExportValidator(many=True, required=False)
    issues = IssueExportValidator(many=True, required=False)
    wiki_links = WikiLinkExportValidator(many=True, required=False)
    wiki_pages = WikiPageExportValidator(many=True, required=False)

    class Meta:
        model = projects_models.Project
        exclude = ('id', 'members')
Exemple #9
0
class IssueCustomAttributeExportValidator(validators.ModelValidator):
    modified_date = serializers.DateTimeField(required=False)

    class Meta:
        model = custom_attributes_models.IssueCustomAttribute
        exclude = ('id', 'project')