def validate(self, data):
        version_id = data['version_id']
        try:
            ventity = models.VersionedEntity.objects.get(id=version_id)
        except models.VersionedEntity.DoesNotExist:
            raise ResNotFoundError(
                '{prefix_msg}id:{version_id}{suffix_msg}'.format(
                    prefix_msg=_("模板集版本"),
                    version_id=version_id,
                    suffix_msg=_("不存在")))
        else:
            data['ventity'] = ventity

        project_id = data['project_id']
        try:
            template = models.get_template_by_project_and_id(
                project_id, ventity.template_id)
        except ValidationError:
            raise ValidationError(
                '{prefix_msg}id:{version_id}{suffix_msg}id:{project_id}'.
                format(prefix_msg=_("模板集版本"),
                       version_id=version_id,
                       suffix_msg=_("不属于该项目"),
                       project_id=project_id))
        else:
            data['template'] = template

        return data
Exemple #2
0
def validate_resource_name(resource_name):
    if resource_name not in RESOURCE_NAMES:
        raise ResNotFoundError(
            '{prefix_msg}{resource_name}{suffix_msg}'.format(
                prefix_msg=_("资源"),
                resource_name=resource_name,
                suffix_msg=_("不存在")))
Exemple #3
0
    def validate(self, data):
        version_id = data['version_id']
        try:
            ventity = models.VersionedEntity.objects.get(id=version_id)
            template = models.Template.objects.get(id=ventity.template_id)

        except ObjectDoesNotExist:
            raise ResNotFoundError(f"模板集版本(id:{version_id})不存在")

        except Exception as error:
            logger.exceptions('get template error, %s', error)
            raise ResNotFoundError(f"模板集版本(id:{version_id})获取失败")

        project_id = data['project_id']
        if project_id != template.project_id:
            raise ValidationError(f"模板集版本(id:{version_id})不属于该项目(id:{project_id})")

        data['ventity'] = ventity
        return data
Exemple #4
0
    def validate(self, data):
        version_id = data['version_id']
        try:
            ventity = models.VersionedEntity.objects.get(id=version_id)
            template = models.Template.objects.get(id=ventity.template_id)
        except Exception as e:
            raise ResNotFoundError(f"模板集版本(id:{version_id})不存在")

        project_id = data['project_id']
        if project_id != template.project_id:
            raise ValidationError(f"模板集版本(id:{version_id})不属于该项目(id:{project_id})")

        data['ventity'] = ventity
        return data
Exemple #5
0
    def validate(self, data):
        version_id = data['version_id']
        try:
            ventity = models.VersionedEntity.objects.get(id=version_id)
        except models.VersionedEntity.DoesNotExist:
            raise ResNotFoundError(f"模板集版本(id:{version_id})不存在")
        else:
            data['ventity'] = ventity

        project_id = data['project_id']
        try:
            template = models.get_template_by_project_and_id(project_id, ventity.template_id)
        except ValidationError:
            raise ValidationError(f"模板集版本(id:{version_id})不属于该项目(id:{project_id})")
        else:
            data['template'] = template

        return data
Exemple #6
0
    def get_config(self, obj):
        show_version_id = obj["show_version_id"]
        template = obj["template"]
        config = {"show_version_id": show_version_id}
        if show_version_id == -1:
            config["version"] = template.draft_version
            config.update(template.get_draft())
            return config

        show_version = obj["show_version"]
        real_version_id = show_version.real_version_id
        # ugly! real_version_id may be integer(-1, 0, ...) or None
        if real_version_id is None:
            config["version"] = real_version_id
            return config

        # version_id 为 -1 则查看草稿
        if real_version_id == -1:
            config["version"] = real_version_id
            config.update(template.get_draft())
            return config

        # real_version_id 为 0 查看最新版本
        if real_version_id == 0:
            ventity = models.VersionedEntity.objects.get_latest_by_template(
                template.id)
        else:
            try:
                ventity = models.VersionedEntity.objects.get(
                    id=real_version_id)
            except models.VersionedEntity.DoesNotExist:
                raise ResNotFoundError(
                    _("模板集版本(id:{})不存在").format(real_version_id))

        if ventity:
            config["version"] = ventity.id
            config.update(ventity.get_resource_config())

        return config
Exemple #7
0
def validate_resource_name(resource_name):
    if resource_name not in RESOURCE_NAMES:
        raise ResNotFoundError(_('资源{}不存在').format(resource_name))
Exemple #8
0
def validate_resource_name(resource_name):
    if resource_name not in RESOURCE_NAMES:
        raise ResNotFoundError(f"资源{resource_name}不存在")