Exemplo n.º 1
0
class TravelRoutesForm(ModelForm):
    class Meta:
        model = TravelRoutes
        fields = '__all__'

    depart = fields.DateTimeField(label='Depart',
                                  widget=DateTimeWidget(bootstrap_version=3),
                                  input_formats=['%d/%m/%Y %H:%M'])
    arrive = fields.DateTimeField(label='Arrive',
                                  widget=DateTimeWidget(bootstrap_version=3),
                                  input_formats=['%d/%m/%Y %H:%M'])

    def clean(self):
        cleaned_data = super(TravelRoutesForm, self).clean()
        depart = cleaned_data.get('depart')
        arrive = cleaned_data.get('arrive')

        if arrive and depart:
            if arrive < depart:
                raise ValidationError('Arrival must be greater than departure')

            if self.instance and self.instance.trip_id is not None:
                from_date = datetime.strptime(self.data.get('from_date'),
                                              '%Y-%m-%d').date()
                to_date = datetime.strptime(self.data.get('to_date'),
                                            '%Y-%m-%d').date()
                depart = depart.date()
                arrive = arrive.date()

                # check if itinerary dates are outside the entire trip date range
                if to_date < depart or depart < from_date or to_date < arrive or arrive < from_date:
                    raise ValidationError(
                        'Travel dates must be within overall trip dates')
        return cleaned_data
Exemplo n.º 2
0
class SubscribeForm(forms.Form):
    model = Subscribe
    use_required_attribute = False

    email = fields.EmailField(label='E-Mail',
                              required=True,
                              help_text='Please enter a valid email address')

    created_at = fields.DateTimeField()
    updated_at = fields.DateTimeField()
Exemplo n.º 3
0
class ProjectForm(Form):

    project_id = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    project_name = fields.CharField(widget=widgets.TextInput(
        attrs={'class': 'form-control'}))
    project_model = fields.CharField(widget=widgets.TextInput(
        attrs={
            'class': 'form-control',
            'placeholder': '多个model 用","隔开'
        }))
    test_leader_wzs_id = fields.IntegerField(widget=widgets.Select(
        attrs={'class': 'form-control'}))
    test_leader_whq_id = fields.IntegerField(widget=widgets.Select(
        attrs={'class': 'form-control'}))
    schedule_start = fields.DateTimeField(widget=widgets.TextInput(
        attrs={
            'class': 'form-control',
            'readonly': 'true'
        }))
    schedule_end = fields.DateTimeField(widget=widgets.TextInput(
        attrs={
            'class': 'form-control',
            'readonly': 'true'
        }))
    project_platform_id = fields.IntegerField(widget=widgets.Select(
        choices=models.Platform.objects.values_list('id', 'name'),
        attrs={'class': 'form-control'}))
    project_type_id = fields.IntegerField(widget=widgets.Select(
        choices=models.ProjectType.objects.values_list('id', 'name'),
        attrs={'class': 'form-control'}))
    project_style_id = fields.IntegerField(widget=widgets.Select(
        choices=models.ProjectStyle.objects.values_list('id', 'name'),
        attrs={'class': 'form-control'}))
    project_sku_qty = fields.CharField(widget=widgets.TextInput(
        attrs={'class': 'form-control'}))
    project_is_leading_project = fields.CharField(widget=widgets.TextInput(
        attrs={'class': 'form-control'}))
    project_progress = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )

    def __init__(self, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)
        self.fields[
            "test_leader_wzs_id"].widget.choices = models.UserProfile.objects.values_list(
                "id", "name").filter(site='1')
        self.fields[
            "test_leader_whq_id"].widget.choices = models.UserProfile.objects.values_list(
                "id", "name").filter(site='2')
Exemplo n.º 4
0
class PrescriptionForm(forms.Form):
    domain = fields.CharField()
    type = fields.CharField()
    start = fields.DateTimeField()
    end = fields.DateTimeField()
    params = fields.CharField(required=False)

    def clean_params(self):
        try:
            params = json.loads(self.cleaned_data['params']
                                ) if self.cleaned_data['params'] else {}
        except ValueError:
            raise ValidationError('Message has to be a JSON obj')
        if not isinstance(params, dict):
            raise ValidationError('Message has to be a JSON obj')
        return params
Exemplo n.º 5
0
class QuestionFormPure(forms.ModelForm):
    question_text = fields.CharField()
    pub_date = fields.DateTimeField()

    class Meta:
        model = models.Question
        fields = ['question_text', 'pub_date']
Exemplo n.º 6
0
class AlbumForm(Form):
    title = fields.CharField(max_length=100)
    year = fields.IntegerField()
    artist = FormField(form=ArtistForm)
    songs = FormFieldList(form=SongForm)
    type = EnumField(enum=Album.AlbumType, required=True)
    metadata = DictionaryField(fields.DateTimeField())

    def clean_year(self):
        if self.cleaned_data['year'] == 1992:
            raise ValidationError("Year 1992 is forbidden!", 'forbidden-value')
        return self.cleaned_data['year']

    def clean(self):
        if (self.cleaned_data['year']
                == 1998) and (self.cleaned_data['artist']['name']
                              == "Nirvana"):
            raise ValidationError("Sounds like a bullshit",
                                  code='time-traveling')
        return self.cleaned_data

    def fill_artist(self, obj, value: dict):
        return Artist(name=value.get('name'),
                      genres=value.get('genres'),
                      members=value.get('members'))
Exemplo n.º 7
0
class TestimgForm(forms.Form):
    title = fields.CharField()
    img = fields.FileField()
    times = fields.DateTimeField(widget=widgets.DateTimeInput(
        attrs={
            'type': "datetime-local",
            'value': "2018-09-01-14:02:30"
        }))
Exemplo n.º 8
0
class perOrderForm(Form):
    title = fields.CharField(max_length=10,
                             min_length=3,
                             error_messages={
                                 "required": '标题不能为空',
                                 "invaild": '格式为字符',
                                 "max_length": '最长10字符',
                                 "min_length": '最短3字符'
                             })
    detail = fields.CharField(widget=widgets.Textarea(attrs={'id': 'content'}),
                              min_length=10,
                              error_messages={
                                  "required": '内容不能为空',
                                  "invaild": '格式为字符',
                                  "min_length": '最短10字符'
                              })
    # create_user_id = fields.CharField(
    #     widget=widgets.CheckboxInput(attrs={"checked":"checked"})
    # )
    create_user_id = fields.ChoiceField(widget=widgets.RadioSelect(
        attrs={'checked': 'checked'}))
    ctime = fields.DateTimeField(required=False)
    status = fields.ChoiceField(choices=models.Order.status_choice,
                                widget=widgets.Select)

    processor_id = fields.CharField(widget=widgets.CheckboxInput)
    solution = fields.CharField(
        widget=widgets.Textarea(attrs={'id': 'content'}),
        required=False,
        min_length=5,
        error_messages={
            "required": '内容不能为空',
            "invaild": '格式为字符',
            "min_length": '最短5字符'
        })
    ptime = fields.DateTimeField(required=False)

    def __init__(self, request, *args, **kwargs):
        super(perOrderForm, self).__init__(*args, **kwargs)
        self.request = request
        self.fields['create_user_id'].choices = ((
            1, self.request.session['user_info']['nickname']), )
        print("---------self", self.fields['create_user_id'].choices)
Exemplo n.º 9
0
class WeekReportForms(Form):
    '周报表单'
    import time
    create_time = fields.DateTimeField(required=True,
                                       initial=time.strftime(
                                           "%Y-%m-%d %H:%M:%S",
                                           time.localtime()))
    weekly_content = fields.CharField(
        min_length=2,
        required=True,
        widget=widgets.Textarea(attrs={'id': 'i1'}))
Exemplo n.º 10
0
class ConponForm(forms.Form):
    name = fields.CharField(max_length=60,
                            error_messages={
                                'required': '优惠卷名称不能为空',
                                'max_length': '优惠卷名称最长不能超过50'
                            })
    type = fields.IntegerField(error_messages={
        'required': '优惠卷类型不能为空',
        'invalid': '请输入数字'
    })
    status = fields.IntegerField(error_messages={
        'required': '必须选择优惠卷状态',
        'invalid': '优惠卷状态非法选择'
    })
    price = fields.IntegerField(error_messages={
        'required': '优惠卷金额不能为空',
        'invalid': '优惠卷金额必须是整数'
    })
    # threshold = fields.IntegerField(error_messages={'required': '优惠卷使用门槛不能为空',
    #                                                 'invalid': '优惠卷使用门槛必须为整数'})
    number = fields.IntegerField(error_messages={
        'required': '优惠卷数量不能为空',
        'invalid': '优惠卷数量必须为整数'
    })
    start_time = fields.DateTimeField(error_messages={
        'required': '开始时间不能为空',
        'invalid': '开始时间必须为时间格式'
    })
    end_time = fields.DateTimeField(error_messages={
        'required': '结束时间不能为空',
        'invalid': '结束时间必须为时间格式'
    })
    price_reduction = fields.IntegerField(required=False,
                                          error_messages={
                                              'required': '开始时间不能为空',
                                              'invalid': '开始时间必须为时间格式'
                                          })
Exemplo n.º 11
0
class PlanForm(forms.Form):
    time_list = [(0, '2019-5-28 8:00:00'), (1, '2019-5-28 10:30:00'), (2, '2019-5-28 13:00:00'),
                 (3, '2019-5-28 15:30:00')]
    plan_start_time = fields.IntegerField(
        required=True,
        error_messages={
            'required': '开始时间不能为空',
            'invalid': '时间格式不正确,应为year-month-day hh:mm:ss格式',
        },
        widget=widgets.Select(attrs={'class': 'form-control'},
                              choices=time_list)
    )
    plan_end_time = fields.DateTimeField(
        required=True,
        error_messages={
            'required': '结束时间不能为空',
            'invalid': '时间格式不正确,应为year-month-day hh:mm:ss格式'
        },
        widget=widgets.TextInput(attrs={'class': 'form-control'})
    )
    plan_movie = forms.ModelChoiceField(
        queryset=models.Movie.objects.all(),
        required=True,
        widget=widgets.Select(attrs={'class': 'form-control'})
    )
    plan_cinema = forms.ModelChoiceField(
        queryset=models.Cinema.objects.all(),
        required=True,
        error_messages={
            'required': '不能为空',
        },
        widget=widgets.Select(attrs={'class': 'form-control'})
    )

    def clean(self):
        value_dict = self.cleaned_data
        cinema = value_dict.get('plan_cinema')
        start_time = value_dict.get('plan_start_time')
        end_time = value_dict.get('plan_end_time')
        t = int(start_time)
        time_list = [(0, '2019-5-28 08:00:00'), (1, '2019-5-28 10:30:00'), (2, '2019-5-28 13:00:00'),
                     (3, '2019-5-28 15:30:00')]
        plan_start_time = time_list[t][1]
        if models.Plan.objects.filter(plan_cinema=cinema,
                                      plan_start_time=plan_start_time).count():
            raise ValidationError('计划安排失败')
        return self.cleaned_data
Exemplo n.º 12
0
class dataForm(Form):

    driverName = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    date = fields.DateField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    location = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    plateNumber = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    project = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    quantity = fields.FloatField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={
            'required': "can't be null",
            'invalid': 'must be number'
        })
    receiveID = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    receiverName = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    category_id = fields.IntegerField()
    time = fields.TimeField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    unit = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})
    uploadTime = fields.DateTimeField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        error_messages={'required': "can't be null"})

    def __init__(self, *args, **kwargs):  # 自定义__init__
        super(dataForm, self).__init__(*args, **kwargs)
        self.fields['category_id'].widget = widgets.Select(
            choices=material.objects.values_list('id', 'categoryName'),
            attrs={'class': 'form-control'})
Exemplo n.º 13
0
 def compress(self, data_list):
     if data_list:
         if data_list[2] in validators.EMPTY_VALUES:
             return None
         elif data_list[0] == "DBRef":
             cleaner = DBRefField()
             return cleaner.clean(data_list[1:3])
         elif data_list[0] == "int":
             cleaner = fields.IntegerField()
         elif data_list[0] == "float":
             cleaner = fields.FloatField()
         elif data_list[0] == "unicode":
             cleaner = fields.CharField(max_length=10000)
         elif data_list[0] == "datetime":
             cleaner = fields.DateTimeField()
         else:
             raise ValidationError(self.error_messages['invalid_type'])
         return cleaner.clean(data_list[2])
     return None
Exemplo n.º 14
0
class emp_form(forms.Form):
    id = fields.IntegerField(
        label='员工ID:',
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
    )
    name = fields.CharField(
        max_length=32,
        widget=widgets.TextInput(attrs={'class': 'form-control'}),
        label='姓名:',
    )
    depart = ModelChoiceField(
        queryset=models.depart.objects.all(),
        widget=widgets.Select(attrs={'class': 'form-control'}),
        label='部门:',
    )
    m_time = fields.DateTimeField(
        label='修改时间:',
        widget=widgets.DateTimeInput(attrs={'class': 'form-control'}),
    )
Exemplo n.º 15
0
    def test_dictionaryfield_required(self):
        dict_field = DictionaryField(fields.DateTimeField())

        # TEST: valid value (type of dict values match DictionaryField)
        now = datetime.datetime(2020,
                                5,
                                2,
                                22,
                                31,
                                32,
                                tzinfo=datetime.timezone.utc)
        expected_result = {
            "created_at": now,
            "updated_at": now,
        }
        now_formatted = now.strftime(settings.DATETIME_INPUT_FORMATS[0])
        test_input = {
            "created_at": now_formatted,
            "updated_at": now_formatted,
        }
        self.assertEqual(expected_result, dict_field.clean(test_input))

        # TEST: invalid value (type of dict values DO NOT match DictionaryField)
        test_input = {"created_at": "blah"}
        with self.assertRaisesMessage(
                ValidationError,
                "{'created_at': ['Enter a valid date/time.']}"):
            dict_field.clean(test_input)

        # TEST: required=True - all empty non-dict values throw an error
        for empty_val in [None, '', [], ()]:
            expected_error = DictionaryField.default_error_messages['not_dict']
            expected_error = expected_error.format(type(empty_val))
            with self.assertRaisesMessage(ValidationError, expected_error):
                log_input(empty_val)
                dict_field.clean(empty_val)

        # TEST: required=True - {} throws error
        with self.assertRaisesMessage(ValidationError,
                                      "['This field is required.']"):
            dict_field.clean({})
Exemplo n.º 16
0
class RegisterOnSiteForm(Form):
    name = fields.CharField()
    username = fields.CharField(validators=[
        validators.RegexValidator(
            r'^[\w.@+-]+$',
            'Enter a valid username. This value may contain only letters, '
            'numbers and @/./+/-/_ characters.', 'invalid')
    ])
    email = fields.EmailField()
    departure = fields.DateTimeField()
    coc_ack = fields.BooleanField(label='Agrees to abide by CoC')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.include_media = False
        layout = self.helper.build_default_layout(self)
        layout.fields.append(
            ButtonHolder(
                Submit('register', 'Register'),
                HTML(
                    '<a href="{}" class="btn btn-secondary">Cancel</a>'.format(
                        reverse('front_desk'))),
            ))
        self.helper.add_layout(layout)

    def clean_username(self):
        username = self.cleaned_data['username']
        if get_user_model().objects.filter(username=username).exists():
            raise ValidationError('User with this username already exists')
        return username

    def clean_email(self):
        email = self.cleaned_data['email']
        if get_user_model().objects.filter(email=email).exists():
            raise ValidationError('User with this email already exists')
        return email
Exemplo n.º 17
0
class EditInfo(forms.ModelForm):

    birthday = fields.DateTimeField(
        widget=widgets.DateInput(attrs={
            'type': 'date',
            'class': 'el-input__inner'
        }),
        label='生日')
    nickname = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'el-input__inner'}),
        label='昵称')
    sex = fields.ChoiceField(
        widget=widgets.Select(attrs={'class': 'el-input__inner'}),
        label='性别',
        choices=((0, '男'), (1, '女'), (2, '未知')))
    address = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'el-input__inner'}),
        label='地址')
    introduction = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'textarea'}), label='简介')

    class Meta:
        model = UserInfo
        fields = ('nickname', 'sex', 'birthday', 'address', 'introduction')
Exemplo n.º 18
0
class RegisterForm(Form):
    username = fields.CharField(widget=widgets.TextInput(
        attrs={"class": "form-control"}))
    email = fields.EmailField(widget=widgets.TextInput(
        attrs={"class": "form-control"}))
    password = fields.CharField(widget=widgets.TextInput(attrs={
        "class": "form-control",
        "type": "password"
    }))
    password2 = fields.CharField(widget=widgets.TextInput(attrs={
        "class": "form-control",
        "type": "password"
    }))
    avatar = fields.FileField(widget=widgets.FileInput(attrs={
        "class": "f1",
        "id": "imgSelect"
    }))
    code = fields.CharField(widget=widgets.TextInput(
        attrs={"class": "form-control"}))
    nickname = fields.CharField(
        required=False,
        widget=widgets.TextInput(attrs={"class": "form-control"}))
    create_time = fields.DateTimeField(required=False)

    # 传入request是为了检查session中的code字段
    def __init__(self, request, *args, **kwargs):  # 传入request
        super(RegisterForm, self).__init__(*args, **kwargs)
        self.request = request

    def clean_code(self):
        input_code = self.cleaned_data["code"]
        session_code = self.request.session.get("code")
        if input_code.upper() != session_code.upper():
            raise ValidationError("验证码错误")
        return input_code

    # 检出用户名是否已被占用
    def clean_username(self):
        username = self.cleaned_data["username"]
        if models.UserInfo.objects.filter(username=username):
            raise ValidationError("该用户已被占用")
        return username

    # 检出邮箱是否已被占用
    def clean_email(self):
        email = self.cleaned_data["email"]
        if models.UserInfo.objects.filter(email=email):
            raise ValidationError("该邮箱已被占用")
        return email

    # 检出nickname是否已被占用
    def clean_nickname(self):
        nickname = self.cleaned_data["nickname"]
        if models.UserInfo.objects.filter(nickname=nickname):
            raise ValidationError("该昵称已被占用")
        return nickname

    def clean(self):
        # 检查两次密码是否一致
        p1 = self.cleaned_data.get("password")
        p2 = self.cleaned_data.get("password2")
        if p1 != p2:
            self.add_error("password2", ValidationError("密码不一致"))
            # raise ValidationError("密码不一致")
        else:
            self.cleaned_data.pop(
                "password2", None
            )  # 如果一致,则去除password2,只保留password,为了与数据库字段一致(数据库只有password)
            # return self.cleaned_data
            # return None # 两者均可

        # 如无创建时间,添加创建时间
        # if not self.cleaned_data.get("create_time"):
        #     self.cleaned_data["create_time"] = time.strftime("%Y-%m-%d")
        # 如无nickname,添加nickname
        if not self.cleaned_data.get("nickname"):
            self.cleaned_data["nickname"] = self.cleaned_data.get(
                "username", "") + str(int(time.time()))
        # 如果验证码正确,去除code,目的是与数据库字段一致(数据库没code)
        if self.cleaned_data.get("code"):
            self.cleaned_data.pop("code")
        return self.cleaned_data
Exemplo n.º 19
0
class clas_form(forms.Form):
    clsId = fields.IntegerField(widget=forms.HiddenInput(), initial=0)
    clsname = fields.CharField(
        max_length=64,
        required=True,
        error_messages={
            'required': '请填写班级名称',
            'max_length': '班级名称不可超过32个字'
        },
    )
    coursId = ModelChoiceField(
        required=True,
        queryset=models.Courses.objects.all().order_by(
            '-id'),  #新增班级页面,初始化科目下拉列表
        empty_label="-------",  #ModelChoiceField 具有empty_label属性
        error_messages={
            'required': '请选择科目!',
        },
    )
    starttime = fields.DateTimeField(
        required=True,
        error_messages={
            'required': '请填写开课日期',
            'invalid': '输入格式不正确,例:2017-01-01',
        },
    )
    endtime = fields.DateTimeField(
        required=True,
        error_messages={
            'required': '请填写结课日期',
            'invalid': '输入格式不正确,例:2017-01-01',
        },
    )

    #op = fields.CharField(widget=forms.HiddenInput(),initial='add')
    # class Meta:
    #     model = models.Clas
    #     fields = '__all__'

    def clean_clsname(self):
        clsname = self.cleaned_data['clsname']
        clsId = self.data['clsId']
        #print("123:",clsname)
        #op = self.cleaned_data['op']
        if clsId == 0:  #clsId 为0,代表新增班级
            if clsname:
                c = models.Clas.objects.filter(clsName=clsname)
                if c:
                    raise ValueError('班级名称已存在,请重新输入!')
                else:
                    return clsname
        else:  #clsId 不为0,代表编辑班级
            if clsname:
                c = models.Clas.objects.filter(clsName=clsname).exclude(
                    id=clsId)  #查询数据库中是否存在相同名称时,排除当前班级
                if c:
                    raise ValueError('班级名称已存在,请重新输入!')
                else:
                    return clsname

        #clsId = self.cleaned_data['clsId']
        #print("++++++++",clsId)
    def clean(self):
        clean_data = self.cleaned_data
        start = clean_data.get('starttime')
        end = clean_data.get('endtime')
        if start and end:
            if end <= start:
                raise ValidationError('结课日期必须大于开课日期')
            else:
                return self.cleaned_data
Exemplo n.º 20
0
class SqlComForm(Form):

    title = fields.CharField(
        max_length=60,
        label='工单标题',
        error_messages={'required': '标题不能为空'},
        widget=widgets.TextInput(
            attrs={
                'class': 'form-control',
                'style': 'min-width:200px; max-width:500px',
                'placeholder': '简述工单功能与作用'
            }))
    # version = fields.ChoiceField(
    #     label='发布版本号',
    #     widget=widgets.Select(choices=[],
    #                           attrs={'class': 'form-control',
    #                                  'style': 'min-width:200px; max-width:500px'})
    # )
    host = fields.CharField(label='数据库地址',
                            widget=widgets.Select(choices=[],
                                                  attrs={
                                                      'class':
                                                      'form-control',
                                                      'id':
                                                      'chose_db_ip',
                                                      'style':
                                                      'min-width:200px;'
                                                      ' max-width:500px'
                                                      ''
                                                  }))
    port = fields.IntegerField(
        widget=widgets.NumberInput(attrs={
            'class': 'form-control',
            'style': 'min-width:200px; max-width:500px'
        }),
        label='端口',
        max_value=65530,
        min_value=1025,
        error_messages={
            'invalid': '请输入有效端口号',
            'min_value': '请输入一个大于或等于1025的端口号',
            'max_value': '请输入一个小于或等于65530的端口号',
            'placeholder': '端口号'
        })
    db_name = fields.CharField(
        label='库名',
        strip=True,
        widget=widgets.TextInput(
            attrs={
                'class': 'form-control',
                'style': 'min-width:200px; max-width:500px',
                'placeholder': '库名'
            }))
    review_name = fields.CharField(label='审核人',
                                   widget=widgets.Select(
                                       choices=[],
                                       attrs={
                                           'class':
                                           'form-control',
                                           'style':
                                           'min-width:200px; max-width:500px'
                                       }))
    run_time = fields.DateTimeField(
        label='工单执行时间',
        required=False,
        widget=widgets.DateTimeInput(
            attrs={
                'class': 'form-control',
                'style': 'min-width:200px; max-width:500px',
                'placeholder': '格式为:2017-06-01 20:00:00 默认为立即执行,当前还未加入定时执行功能'
            }))
    is_commit = fields.ChoiceField(
        label='提交审核',
        initial=0,
        choices=((0, '否'), (1, '是')),
        widget=widgets.Select(attrs={
            'class': 'form-control',
            'style': 'min-width:200px; max-width:500px'
        }),
    )
    sql_content = fields.CharField(
        label='SQL 内容',
        error_messages={'required': 'SQL 内容不能为空'},
        widget=widgets.Textarea(
            attrs={
                'class': 'form-control',
                'style': 'min-width:200px;'
                'max-width:800px;height: 100px'
            }))
    comm = fields.CharField(
        label='工单说明',
        required=False,
        widget=widgets.Textarea(
            attrs={
                'class': 'form-control',
                'style': 'min-width:200px; max-width:500px;height: 35px',
                'placeholder': '审核中有警告时,依然需要提交执行时, 需要在此处写明原因'
            }))

    def __init__(self, *args, **kwargs):
        super(SqlComForm, self).__init__(*args, **kwargs)
        # self.fields['version'].widget.choices = models.HostGroup.objects.values_list('id', 'host_group_jd')
        self.fields[
            'host'].widget.choices = models.HostInfo.objects.values_list(
                'id', 'host_ip')
        user_info = models.UserInfo.objects.filter(
            userrolerelationship__role_id=1).values_list('id', 'user_name')
        self.fields['review_name'].widget.choices = user_info
Exemplo n.º 21
0
class ProjectInfoForm(Form):

    # project_id = fields.IntegerField(
    #     widget=widgets.Select(choices=models.Project.objects.values_list('id', 'project_name').filter(),
    #                           attrs={'class': 'form-control'})
    # )
    project_id = fields.IntegerField(widget=widgets.Select(
        attrs={'class': 'form-control'}))
    # project_id = fields.CharField(
    #     widget=widgets.TextInput(attrs={'class': 'form-control'}),
    # )

    project_bios = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    project_mb = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    project_os = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    update_time = fields.DateTimeField(widget=widgets.TextInput(
        attrs={'class': 'form-control'}))
    dr_chipset = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_vga = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_iamt = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_storage = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_lan = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_audio = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_cr = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_wireless = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_bt = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_panel = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_finger_printer = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_g_sensor = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_camera = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_usb = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_com_parallel = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_serial_io = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_sgx = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )
    dr_others = fields.CharField(
        widget=widgets.TextInput(attrs={'class': 'form-control'}), )

    def __init__(self, *args, **kwargs):
        super(ProjectInfoForm, self).__init__(*args, **kwargs)
        self.fields[
            "project_id"].widget.choices = models.Project.objects.values_list(
                "id", "project_name").filter()