示例#1
0
文件: views.py 项目: zzdx713/bk-PaaS
    def _update_base_info(self, request, app_code):
        app = App.objects.get(code=app_code)

        form = BaseInfoForm(request.POST)
        if not form.is_valid():
            message = first_error_message(form)
            raise BadRequestException(message)

        name = form.cleaned_data["name"]
        developer = form.cleaned_data["developer"]
        app_tags = form.cleaned_data["app_tags"]

        old_name = app.name
        is_valid, message = validate_app_name(name, old_name)
        if not is_valid:
            raise BadRequestException(message)
        developer_list = developer.split(';') if developer else []
        # 保存用户基本信息
        with transaction.atomic():
            app.name = name
            app.tags = app_tags
            app.save()

            # 保存开发负责人信息
            if developer_list:
                app.developer.clear()
                user_model = get_user_model()
                for dev in developer_list:
                    d_user = user_model.objects.get(username=dev)
                    app.developer.add(d_user)
示例#2
0
    def test_util_validate_app_name(self):
        new_name = 'a' * 21

        r, _ = validate_app_name(new_name, None)
        self.assertFalse(r)

        r, _ = validate_app_name(self.old_name, None)
        self.assertFalse(r)

        new_name = 'validname'
        # change from old_name to new_name
        r, _ = validate_app_name(new_name, self.old_name)
        self.assertTrue(r)

        # totally new
        r, _ = validate_app_name(new_name, None)
        self.assertTrue(r)
示例#3
0
    def clean_name(self):
        name = self.cleaned_data["name"]
        name = name.replace(' ', ' ').strip()
        # for create, the old_name is ''
        valid, message = validate_app_name(name, '')
        if not valid:
            self.add_error('name', message)

        return name
示例#4
0
文件: views.py 项目: zzdx713/bk-PaaS
    def get_context_data(self, **kwargs):
        context = super(CheckAppNameView, self).get_context_data(**kwargs)
        request = self.request

        name = request.GET.get('name', '')
        old_name = request.GET.get('old_name', '')
        is_valid, message = validate_app_name(name, old_name)

        context.update({'result': is_valid, 'message': message})
        return context