class Meta: model = AnonymousVul fields = ('title', 'category', 'detail', 'attachment', 'email') labels = { 'title': '漏洞标题', 'category': '漏洞类型', 'detail': '漏洞细节', 'attachment': '附件', 'email': '注册邮箱(可选)', } widgets = { 'detail': Textarea(**bs4_form), 'title': Input(**bs4_form), 'category': Select(**bs4_form), 'email': Input( attrs={ 'class': 'form-control', 'placeholder': '跟踪漏洞状态并注册为正式用户,内测版仅支持 @ujs.edu.cn 的邮件地址' }), }
class Meta: model = User fields = ['username', 'email'] widgets = { 'username': Input(attrs={'class': "form-control"}), 'email': Input(attrs={'class': "form-control"}) }
class Meta: model = Pledging exclude = ['expire_date'] widgets = { 'user_id': forms.HiddenInput(), 'type_pledging': forms.HiddenInput(), 'cus_id': Input(attrs={ 'class': 'form-control', 'readonly': 'readonly' }), 'pledge_balance': Input(attrs={'class': 'shadow-sm form-control'}), 'contract_term': Input(attrs={'class': 'shadow-sm form-control'}), 'dob': Input(attrs={ 'class': 'form-control', 'type': 'date' }), } labels = { 'cus_id': 'รหัสลูกค้า', 'pledge_balance': 'ยอดจำนำ', 'contract_term': 'เวลาสัญญา ( เป็นวัน )', 'pledge_date': 'วันเริ่มทำสัญญา', 'expire_date': 'วันหมดสัญญา' }
class Meta: model = User fields = ('username', 'first_name', 'last_name', 'email') widgets = { 'username': Input( attrs={ 'class': 'form-control', 'placeholder': 'Имя пользователя', 'autofocus': '' }), 'first_name': Input(attrs={ 'class': 'form-control', 'placeholder': 'Имя' }), 'last_name': Input(attrs={ 'class': 'form-control', 'placeholder': 'Фамилия' }), 'email': Input(attrs={ 'class': 'form-control', 'placeholder': 'Электронная почта' }), }
class ApplicationForm2(forms.Form): # Allow blank choices GENDERS = (('', '----'), ) + Application.GENDERS RACES = (('', '----'), ) + Application.RACES REFERRED_OPTIONS = (('', '----'), ) + Application.REFERRED_OPTIONS gender = forms.ChoiceField(widget=Select(attrs={'id': 'id_gender'}), choices=GENDERS) race = forms.ChoiceField(widget=Select(attrs={'id': 'id_race'}), choices=RACES) race_other = forms.CharField(widget=Input(attrs={'id': 'id_race_other'}), max_length=120, required=False) referred = forms.ChoiceField(widget=Select(attrs={'id': 'id_referred'}), choices=REFERRED_OPTIONS) referred_other = forms.CharField( widget=Input(attrs={'id': 'id_referred_other'}), max_length=120, required=False) veteran = forms.BooleanField( widget=CheckboxInput(attrs={'id': 'id_veteran'}), required=False) military_service = forms.MultipleChoiceField( widget=CheckboxSelectMultiple(attrs={'id': 'id_military_service'}), choices=Application.MILITARY_OPTIONS, required=False)
class CourseFilter(django_filters.FilterSet): Program = django_filters.CharFilter(lookup_expr='icontains', label='Program', widget = Input(attrs={'placeholder':'Ex: Chem',}) ) ProgramAPPX = django_filters.CharFilter( lookup_expr='icontains', field_name="Program", label='Program', widget = Input(attrs={'placeholder':'Ex: Chem',}) ) CourseID = django_filters.CharFilter( label='Course Number', widget = Input(attrs={'placeholder':'4 Digit Number', 'class': "form-control",}) ) CourseNumA = django_filters.NumberFilter( field_name="CourseNum", label='CourseNum Min', widget = Input(attrs={'placeholder':'Starting Range', 'class': "form-control",}), lookup_expr="gt", ) CourseNumB = django_filters.NumberFilter( field_name="CourseNum", label='CourseNum Max', widget = Input(attrs={'placeholder':'Starting Range', 'class': "form-control",}), lookup_expr="lt", ) class Meta: model = Course fields = ["CourseID", "Program", "CourseNum"]
class Meta: model = Book fields = ('name', 'description', 'author', 'gender', 'amount_pages', 'amount_chapter', 'img_book', 'file_book') labels = { 'name': ('Nombre'), } widgets = { 'name': Input(attrs={'class': 'form-control'}), 'description': Textarea(attrs={'class': 'form-control'}), 'author': Select(attrs={ 'class': 'form-control', 'placeholder': 'Autor' }), 'gender': SelectMultiple(attrs={'class': 'form-control'}), 'amount_pages': Input(attrs={'class': 'form-control'}), 'amount_chapter': Input(attrs={'class': 'form-control'}), 'content_adult': Input(attrs={'class': 'form-control'}), 'img_book': FileInput(attrs={'class': 'form-control'}), 'file_book': FileInput(attrs={'class': 'form-control'}), }
def test_attrs_with_type(self): attrs = {'type': 'date'} widget = Input(attrs) self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value" />') # reuse the same attrs for another widget self.check_html(Input(attrs), 'name', 'value', '<input type="date" name="name" value="value" />') attrs['type'] = 'number' # shouldn't change the widget type self.check_html(widget, 'name', 'value', '<input type="date" name="name" value="value" />')
class Meta: model = Profile fields = ['nickname', 'phone', 'avatar'] labels = {'avatar': '用户头像', 'nickname': '昵称', 'phone': '手机号码'} widgets = { 'nickname': Input(attrs={'class': "form-control"}), 'phone': Input(attrs={'class': "form-control"}) }
class Meta: model = Expenses fields = ['amount', 'exp_note', 'bill'] widgets = { 'amount': Input(attrs={'class': 'form-control', 'required': 'required', 'type': 'number'}), 'exp_note': Input(attrs={'class': 'form-control', 'required': 'required'}), 'bill': Input(attrs={'class': 'form-control', 'type': 'file', 'required': 'required'}), }
class Meta: model = User fields = ['first_name', 'last_name', 'username', 'password'] widgets = { 'password': Input(attrs={ 'type': 'password', 'class': 'form-control' }), 'first_name': Input(attrs={'class': 'form-control'}), 'last_name': Input(attrs={'class': 'form-control'}), 'username': Input(attrs={'class': 'form-control'}), }
def set_value_widget(self): """add custom widget for boolean values (after form has been initialized)""" # temp store attributes so they can be restored to reset widget value_fields = [ "value", "string_value", "date_value", "datetime_value" ] widget_attrs = {} for f in value_fields: self.fields[f].widget.attrs["class"] = "qa-input" widget_attrs[f] = self.fields[f].widget.attrs test_type = self.unit_test_info.test.type if test_type == models.BOOLEAN: self.fields["value"].widget = RadioSelect(choices=BOOL_CHOICES) elif test_type == models.CONSTANT: test = self.unit_test_info.test formatted = format_qc_value(test.constant_value, test.formatting) self.fields["value"].widget.attrs['title'] = _( 'Actual value = %(constant_value)s') % { 'constant_value': test.constant_value } self.fields["value"].widget.attrs['data-formatted'] = formatted elif test_type == models.MULTIPLE_CHOICE: self.fields["string_value"].widget = Select( choices=[("", "")] + self.unit_test_info.test.get_choices()) elif test_type == models.UPLOAD: self.fields["string_value"].widget = HiddenInput() self.fields["json_value"].widget = HiddenInput() elif test_type == models.COMPOSITE: self.fields["value"].widget = Input() if getattr(self, "instance", None): test = self.unit_test_info.test formatted = format_qc_value(self.instance.value, test.formatting) self.fields["value"].widget.attrs['data-formatted'] = formatted elif test_type in models.STRING_TYPES: self.fields['string_value'].widget = Input({'maxlength': 20000}) else: attrs = {"step": "any"} if test_type == models.WRAPAROUND: attrs['max'] = self.unit_test_info.test.wrap_high attrs['min'] = self.unit_test_info.test.wrap_low self.fields["value"].widget = NumberInput(attrs=attrs) if test_type in (models.BOOLEAN, models.MULTIPLE_CHOICE): if hasattr(self, "instance") and self.instance.value is not None: self.initial["value"] = int(self.instance.value) for f in value_fields: self.fields[f].widget.attrs.update(widget_attrs[f])
class Meta: model = Resume fields = ('name', 'surname', 'status', 'salary', 'specialty', 'grade', 'education', 'experience') widgets = { 'name': Input(attrs={'class': 'form-control'}), 'surname': Input(attrs={'class': 'form-control'}), 'status': Select(attrs={'class': 'custom-select mr-sm-2'}), 'salary': NumberInput(attrs={'class': 'form-control'}), 'specialty': Select(attrs={'class': 'custom-select mr-sm-2'}), 'grade': Select(attrs={'class': 'custom-select mr-sm-2'}), 'education': Textarea(attrs={'class': 'form-control'}), 'experience': Textarea(attrs={'class': 'form-control'}) }
class Meta: model = Application fields = ('written_username', 'written_phone', 'written_cover_letter') widgets = { 'written_username': Input(attrs={'class': 'form-control'}), 'written_phone': Input(attrs={'class': 'form-control'}), 'written_cover_letter': Textarea(attrs={ 'rows': 8, 'class': 'form-control' }), }
class Meta: model = Redeemed exclude = ['redeem_date'] widgets = { 'pledging_id': forms.HiddenInput(), 'first_name': Input(attrs={'class': 'form-control'}), 'last_name': Input(attrs={'class': 'form-control'}), 'citizen_id': Input(attrs={'class': 'form-control'}), } labels = { 'first_name': 'ชื่อ', 'last_name': 'นามสกุล', 'citizen_id': 'รหัสประชาชน', }
class Meta: model = WhiteHat fields = ('bio', 'site', 'department', 'public') labels = { 'bio': '一句话简介', 'department': '部门', 'site': '个人首页', 'public': '公开展示个人资料', } widgets = { 'bio': Input(**bs4_form), 'department': Input(**bs4_form), 'site': Input(**bs4_form), }
def _get_form(self, field_name): """ Returns form with from and to fields. The '__alt' fields are alternative fields with the correct non localized dateform needed for Django, handled by jsTree. """ from_name = self.parameter_name + '__gte' to_name = self.parameter_name + '__lte' display_widget = Input(attrs={'class': 'filtrate_date'}) hidden_widget = HiddenInput(attrs={'class': 'filtrate_date_hidden'}) def add_fields(fields, name, label): fields[name + '__alt'] = f.CharField(label=label, widget=display_widget, required=False) fields[name] = f.CharField(widget=hidden_widget, required=False) def add_data(data, name, request): date = request.GET.get(name) if date: data[name + '__alt'] = date class DateRangeForm(f.Form): def __init__(self, *args, **kwargs): super(DateRangeForm, self).__init__(*args, **kwargs) add_fields(self.fields, from_name, _('From')) add_fields(self.fields, to_name, _('To')) data = {} add_data(data, from_name, self.request) add_data(data, to_name, self.request) return DateRangeForm(data=data)
class Meta: model = MemberVul fields = ('title', 'category', 'detail', 'attachment') labels = { 'title': '漏洞标题', 'category': '漏洞类型', 'detail': '漏洞细节', 'attachment': '附件', } widgets = { 'detail': Textarea(**bs4_form), 'title': Input(**bs4_form), 'category': Select(**bs4_form), } error_messages = { 'title': { 'required': '标题不能为空', }, 'category': { 'required': '请选择一个分类', }, 'detail': { 'required': '请填写漏洞细节', } }
class Meta: model = PostComment fields = {'author', 'comment'} widgets = { 'author': Input(attrs={'class': 'form-control'}), 'comment': Textarea(attrs={'cols': 80, 'rows': 3, 'class': 'form-control'}), }
def field_to_widget(field): if type(field) is CharField: if field.choices: return Select(attrs={"class": "form-control"}) return TextInput(attrs={"class": "form-control", "rows": 1}) if type(field) is TextField: return Textarea(attrs={"class": "form-control", "rows": 1}) if type(field) is AutoField: return HiddenInput(attrs={"class": "form-control", "rows": 1}) if type(field) is IntegerField or type(field) is FloatField: return NumberInput(attrs={"class": "form-control"}) if type(field) is EmailField: return EmailInput(attrs={"class": "form-control"}) if type(field) is ForeignKey: return Select(attrs={"class": "form-control"}) if type(field) is ManyToManyField: return CheckboxSelectMultiple(attrs={"class": ""}) if type(field) is BooleanField: return CheckboxInput(attrs={"class": "form-control"}) if type(field) is FileField: return FileInput(attrs={"class": "form-control"}) if type(field) is DateField: return DateInput(attrs={"class": "form-control date", "type": "date"}) if type(field) is DateTimeField: return DateTimeInput(attrs={"class": "form-control datetimepicker"}) return Input(attrs={"class": "form-control"})
def test_attr_false_not_rendered(self): html = '<input type="None" name="name" value="value">' self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False})
class Meta: model = Task fields = '__all__' widgets = { 'title': Input(attrs={ 'class': 'input', }) }
def test_no_trailing_newline_in_attrs(self): self.check_html( Input(), "name", "value", strict=True, html='<input type="None" name="name" value="value">', )
class Meta: model = Gold fields = ['weight', 'goldtype'] widgets = { 'weight': Input(attrs={'class': 'shadow-sm form-control'}), 'goldtype': Select(attrs={'class': 'shadow-sm form-control'}), } labels = {'weight': 'น้ำหนักทอง', 'goldtype': 'ประเภททอง'}
class FiltresForm(forms.Form): types = forms.MultipleChoiceField(choices=Anomalie.type_choix, required=False) date = forms.DateField(widget=Input({'type': 'date'}), required=False) individu = forms.ModelMultipleChoiceField(queryset=Individu.objects.all(), required=False) nCommande = forms.ModelMultipleChoiceField(queryset=Commande.objects.all(), required=False)
def test_attrs_with_type(self): attrs = {"type": "date"} widget = Input(attrs) self.check_html( widget, "name", "value", '<input type="date" name="name" value="value">' ) # reuse the same attrs for another widget self.check_html( Input(attrs), "name", "value", '<input type="date" name="name" value="value">', ) attrs["type"] = "number" # shouldn't change the widget type self.check_html( widget, "name", "value", '<input type="date" name="name" value="value">' )
class ApplicationForm1(forms.Form): first_name = forms.CharField(max_length=120, widget=Input(attrs={'id': 'id_first_name'})) middle_initial = forms.CharField( widget=Input(attrs={'id': 'id_middle_inital'}), max_length=1, required=False) last_name = forms.CharField(max_length=120, widget=Input(attrs={'id': 'id_last_name'})) phone = forms.CharField(widget=PhoneInput(attrs={'id': 'id_phone'})) email = forms.CharField(max_length=120, widget=EmailInput(attrs={'id': 'id_email'})) resume = forms.FileField(widget=FileInput( attrs={ 'accept': '.doc,.docx,application/msword,' + 'application/vnd.openxmlformats-officedocument' + '.wordprocessingml.document', 'id': 'id_resume' })) desired_salary = forms.IntegerField(widget=MoneyInput(attrs={ 'min': 10000, 'step': 1000 })) us_citizenship = forms.ChoiceField( widget=Select(attrs={'id': 'id_us_citizenship'}), choices=Application.CITIZENSHIP_STATUSES) clearance = forms.BooleanField( widget=CheckboxInput(attrs={'id': 'id_clearance'}), required=False) clearance_type = forms.CharField(widget=Input( attrs={ 'id': 'id_clearance_type', 'placeholder': 'example: NACLC, Public Trust, Top Secret' }), required=False)
class Meta: fields = ('city', 'phone', 'profile_picture') model = Profile widgets = { 'profile_picture': Input(attrs={'type': 'file', 'name': 'profile_picture', 'accept': 'image/*', 'id': 'profile_picture'}) } labels = { 'profile_picture': _('Выберите изображение') }
class Meta: model = PickUp fields = ['bin_type', 'weight', 'schedule_date', 'recurring', 'notes'] widgets = { 'weight': Input( attrs={ "type": "number", "class": "form-control", 'placeholder': 'weight(lb)' }), 'schedule_date': Input( attrs={ "type": "date", "class": "form-control", "placeholder": "Schedule Date" }), }
class Meta(UserCreationForm.Meta): model = user_model widgets = { 'username': Input(attrs={ "type": "text", "class": "form-control", 'placeholder': 'Username' }), }