class Meta: model = Trial exclude = ['owner', 'created', 'recruitment'] widgets = { 'title': widgets.TextInput(attrs={ 'class': 'wider', 'data-required': 'true', 'data-maxlength': '200' }), 'reporting_freq': widgets.Select(attrs={'data-required': 'true'}), 'reporting_style': widgets.RadioSelect(attrs={'data-required': 'true'}), 'description': widgets.Textarea(attrs={'data-required': 'true'}), 'group_a': widgets.Textarea(attrs={'data-required': 'true'}), 'group_b': widgets.Textarea(attrs={'data-required': 'true'}), 'instruction_delivery': widgets.RadioSelect(), 'instruction_hours_after': widgets.TextInput(attrs={ 'data-type': 'digits', }), 'group_a_desc': widgets.Textarea(attrs={'data-required': 'true'}), 'group_b_desc': widgets.Textarea(attrs={'data-required': 'true'}), 'min_participants': widgets.TextInput(attrs={ 'data-required': 'true', 'data-type': 'digits', 'data-min': '1' }), 'max_participants': widgets.TextInput( attrs={ 'data-required': 'true', 'data-type': 'digits', 'data-min': '1', 'data-greaterthanorequalto': "#id_min_participants", 'data-greaterthanorequalto-message': "Max participants must be greater than or equal to Min participants" }), 'recruitment': widgets.RadioSelect(), 'ending_style': widgets.RadioSelect(), 'ending_reports': widgets.TextInput(attrs={ 'data-type': 'digits', 'data-min': '1' }), }
class VisualReportForm(forms.Form): visual_report_name = forms.CharField(widget=widgets.TextInput( attrs={'class': 'form-control'}, ), required=True, max_length=60, min_length=2, label='报表名称') is_down = fields.ChoiceField(initial=0, choices=((0, '是'), (1, '否')), widget=widgets.RadioSelect(), label='是否可下载') online = fields.ChoiceField(initial=0, choices=((0, '是'), (1, '否')), widget=widgets.RadioSelect(), label='是否上线') mid = fields.ChoiceField( initial=1, widget=widgets.Select(attrs={'class': 'form-control'}), label='菜单选择') def __init__(self, *args, **kwargs): super(VisualReportForm, self).__init__(*args, **kwargs) self.fields[ 'mid'].widget.choices = models.BdpDataVisualMenu.objects.all( ).values_list('mid', 'menu_name')
class ProjectForm(forms.Form): name = forms.CharField( label="所属人", max_length=100, widget=widgets.TextInput(attrs={'class': "form-control"})) fund = forms.CharField(label='所属资产', max_length=100, widget=widgets.RadioSelect(choices=(('个人', '个人'), ('公司', '公司')))) # fund = forms.CharField(label="所属资产", # max_length=100, # widget=widgets.TextInput(attrs={'class': "form-control"})) #sys = forms.CharField(verbose_name='系统', # max_length=5, # choices=(('ios', 'IOS'), ('android', 'Android'))) sys = forms.CharField(label='系统', max_length=100, widget=widgets.RadioSelect(choices=(('IOS', 'IOS'), ('Android', 'Android')))) type = forms.CharField( label="型号", max_length=100, widget=widgets.TextInput(attrs={'class': "form-control"})) version = forms.CharField( label="版本", max_length=100, widget=widgets.TextInput(attrs={'class': "form-control"}))
class BootstrapButtonPlugin(LinkPluginBase): module = 'Bootstrap' name = _("Button") form = TextLinkForm model_mixins = (LinkElementMixin,) parent_classes = ['BootstrapColumnPlugin'] render_template = 'cascade/bootstrap3/button.html' allow_children = False text_enabled = True tag_type = None default_css_class = 'btn' default_css_attributes = ('button-type', 'button-size', 'button-options', 'quick-float',) fields = ('link_content', ('link_type', 'cms_page', 'ext_url', 'mail_to'), 'glossary',) glossary_fields = ( PartialFormField('button-type', widgets.RadioSelect(choices=((k, v) for k, v in ButtonTypeRenderer.BUTTON_TYPES.items()), renderer=ButtonTypeRenderer), label=_('Button Type'), initial='btn-default', help_text=_("Display Link using this Button Style") ), PartialFormField('button-size', widgets.RadioSelect(choices=((k, v) for k, v in ButtonSizeRenderer.BUTTON_SIZES.items()), renderer=ButtonSizeRenderer), label=_('Button Size'), initial='', help_text=_("Display Link using this Button Size") ), PartialFormField('button-options', widgets.CheckboxSelectMultiple(choices=(('btn-block', _('Block level')), ('disabled', _('Disabled')),)), label=_('Button Options'), ), PartialFormField('quick-float', widgets.RadioSelect(choices=(('', _("Do not float")), ('pull-left', _("Pull left")), ('pull-right', _("Pull right")),)), label=_('Quick Float'), initial='', help_text=_("Float the button to the left or right.") ), ) + LinkPluginBase.glossary_fields + ( PartialFormField('inline_styles', MultipleCascadingSizeWidget(['margin-top', 'margin-right', 'margin-bottom', 'margin-left'], allowed_units=['px', 'em'], required=False), label=_('Margins'), help_text=_('Margins for this button wrapper.') ), ) class Media: css = {'all': ('cascade/css/admin/bootstrap.min.css', 'cascade/css/admin/bootstrap-theme.min.css',)} @classmethod def get_identifier(cls, obj): identifier = super(BootstrapButtonPlugin, cls).get_identifier(obj) content = obj.glossary.get('link_content') if not content: try: content = force_text(ButtonTypeRenderer.BUTTON_TYPES[obj.glossary['button-type']]) except KeyError: content = _("Empty") return format_html('{0}{1}', identifier, content)
class ArticleForm(Form): title = fields.CharField(widget=widgets.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'TITLE' })) summary = fields.CharField(widget=widgets.TextInput( attrs={ 'class': 'form-control', 'placeholder': 'SUMMARY' })) content = fields.CharField(widget=widgets.Textarea( attrs={'id': 'kind-editor'})) type_id = fields.IntegerField(widget=widgets.RadioSelect( choices=models.Article.type_choices, attrs={'class': "form-radio"}), label="Type") category_id = fields.ChoiceField( choices=[], widget=widgets.RadioSelect(attrs={'class': "form-radio"}), label="Category", ) tags = fields.MultipleChoiceField( choices=[], required=False, widget=widgets.CheckboxSelectMultiple(attrs={'class': "form-radio"})) def __init__(self, request, *args, **kwargs): super(ArticleForm, self).__init__(*args, **kwargs) blog_id = request.session['user_info']['blog__nid'] self.fields['category_id'].choices = models.Category.objects.filter( blog_id=blog_id).values_list('nid', 'title') self.fields['tags'].choices = models.Tag.objects.filter( blog_id=blog_id).values_list('nid', 'title')
class ReleaseNoteForm(forms.Form): v_pk = forms.CharField(widget=forms.HiddenInput) name = forms.CharField(label='Project Code') platform = forms.CharField(label='Platform') sku = forms.CharField(label='SKU') stage = forms.ModelChoiceField( label='Stage', widget=widgets.RadioSelect(renderer=BootstrapInlineRadioRenderer), queryset=Stage.objects.all(), empty_label=None) baseline = forms.CharField(label='Baseline Version', max_length=20) bstype = forms.ModelChoiceField( label='Baseline Type', widget=widgets.RadioSelect(renderer=BootstrapInlineRadioRenderer), queryset=BaselineType.objects.all(), empty_label=None) releasedate = forms.DateField(label='Release Date', initial=date.today(), input_formats=('%Y-%m-%d', ), widget=widgets.DateInput(format='%Y-%m-%d')) releasename = forms.CharField(label='Release Name / Version') checksum = forms.CharField( label='Checksum', widget=widgets.TextInput(attrs={'class': 'span4'})) comments = forms.CharField(label='', widget=forms.Textarea(attrs={'rows': 4}), required=False)
class Meta: model = models.Lead fields = ['id', 'name', 'gender', 'card_number', 'expiry_date', 'professional'] read_only_fields = ['id'] widgets = { 'name': widgets.TextInput(attrs={'class': 'form-control', 'placeholder': 'Ilya Chaban'}), 'gender': widgets.RadioSelect(), 'card_number': widgets.TextInput(attrs={'class': 'form-control', 'placeholder': 'XXXXXXXXXXXXXXX'}), 'expiry_date': widgets.DateInput(attrs={'class': 'datepicker form-control'}), 'professional': widgets.RadioSelect() }
class EmblemForm(StarkModelForm): issuer = fields.ChoiceField(widget=widgets.RadioSelect(), label='颁发者', choices=((1, '老师'), (2, '家长'), (3, '两者皆可'))) classification = fields.ChoiceField(widget=widgets.RadioSelect(), label='徽章分类', choices=((1, '鼓励与表扬'), (2, '惩罚与批评'))) scope = fields.ChoiceField(required=False, widget=widgets.RadioSelect(), label='颁发范围', choices=((1, '校级别'), (2, '班级'))) subject = forms.ModelMultipleChoiceField( required=False, label='关联课程', queryset=Course.objects.all(), widget=widgets.CheckboxSelectMultiple()) grade = forms.ModelMultipleChoiceField( required=False, label='关联年级', queryset=Grade.objects.all(), widget=widgets.CheckboxSelectMultiple()) icon = fields.FileField( widget=fields.FileInput(attrs={'style': 'display:none'}), label='徽章图片') emblem_type = forms.ModelChoiceField( required=False, label='徽章类型', queryset=EmblemType.objects.exclude(id__in=[ item.pid.id for item in EmblemType.objects.filter(pid__isnull=False) ])) is_custom = fields.ChoiceField(widget=widgets.RadioSelect(), label='是否允许自定制', choices=((True, '允许'), (False, '禁止')), initial=False) class Meta: model = Emblem fields = ( 'emblem_name', 'icon', 'description', 'classification', 'scope', 'is_custom', 'issuer', 'subject', 'emblem_type', 'grade', )
class ButtonWrapperPlugin(BootstrapPluginBase): name = _("Button wrapper") parent_classes = ['BootstrapColumnPlugin'] render_template = 'cms/plugins/naked.html' generic_child_classes = ('LinkPlugin', ) tag_type = None default_css_class = 'btn' default_css_attributes = ( 'button-type', 'button-size', 'button-options', ) partial_fields = ( PartialFormField( 'button-type', widgets.RadioSelect( choices=((k, v) for k, v in ButtonTypeRenderer.BUTTON_TYPES.items()), renderer=ButtonTypeRenderer), label=_('Button Type'), initial='btn-default'), PartialFormField( 'button-size', widgets.RadioSelect( choices=((k, v) for k, v in ButtonSizeRenderer.BUTTON_SIZES.items()), renderer=ButtonSizeRenderer), label=_('Button Size'), initial=''), PartialFormField( 'button-options', widgets.CheckboxSelectMultiple(choices=( ('btn-block', _('Block level')), ('disabled', _('Disabled')), )), label=_('Button Options'), ), PartialFormField('inline_styles', MultipleInlineStylesWidget([ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ]), label=_('Inline Styles'), help_text=_('Margins for this button wrapper.')), ) @classmethod def get_identifier(cls, obj): return ButtonTypeRenderer.BUTTON_TYPES.get( obj.context.get('button-type'), '')
class TeacherEditModelForm(StarkModelForm): birthday = Ffields.DateField( required=False, label='生日', widget=Fwidgets.DateInput(attrs={ 'type': 'date', 'style': 'width: 600px' })) identity = form_models.ModelChoiceField( required=False, empty_label=None, label='职务', queryset=teamodels.Identity.objects.all(), widget=Fwidgets.RadioSelect()) course = form_models.ModelMultipleChoiceField( required=False, label='所带课程', queryset=scmodels.Course.objects.all(), widget=Fwidgets.CheckboxSelectMultiple()) gender = Ffields.ChoiceField(required=False, label='性别', choices=((1, '男'), (2, '女')), widget=Fwidgets.RadioSelect()) class Meta: model = teamodels.TeacherInfo fields = ('last_name', 'first_name', 'gender', 'birthday', 'telephone', 'wechat', 'school', 'identity', 'course') widgets = { "last_name": Fwidgets.TextInput(attrs={'style': 'width: 600px'}), "first_name": Fwidgets.TextInput(attrs={'style': 'width: 600px'}), 'wechat': Fwidgets.TextInput(attrs={'style': 'width: 600px'}), 'telephone': Fwidgets.TextInput(attrs={'style': 'width: 600px'}), 'school': Fwidgets.Select(attrs={'style': 'width: 600px'}), } error_messages = { "last_name": { "required": "请输入老师姓" }, "first_name": { "required": "请输入老师名" }, "gender": { "required": "请选择性别" }, } labels = { 'last_name': '老师姓(必填)', 'first_name': '老师名(必填)', }
def get_form(self, request, obj=None, **kwargs): font_choices = IconFont.objects.values_list('id', 'identifier') glossary_fields = ( PartialFormField( 'icon_font', widgets.Select(choices=font_choices), label=_("Font"), ), PartialFormField( 'content', widgets.HiddenInput(), label=_("Select Icon"), ), PartialFormField( 'font-size', widgets.Select(choices=self.SIZE_CHOICES), label=_("Icon Size"), ), PartialFormField( 'text-align', widgets.RadioSelect(choices=(('', _("Do not align")), ('text-left', _("Left")), ('text-center', _("Center")), ('text-right', _("Right")))), label=_("Text Align"), initial='', help_text=_("Align the icon inside the parent column.")), ) kwargs.update(glossary_fields=glossary_fields) form = super(FontIconPlugin, self).get_form(request, obj=obj, **kwargs) return form
class BreadcrumbPlugin(ShopPluginBase): name = _("Breadcrumb") CHOICES = ( ('default', _("Default Breadcrumb")), ('soft-root', _("“Soft-Root” Breadcrumb")), ('catalog', _("With Catalog Count")), ('empty', _("Empty Breadcrumb")), ) glossary_fields = (PartialFormField( 'render_type', widgets.RadioSelect(choices=CHOICES), label=_("Render as"), initial='default', help_text=_("Render an alternative Breadcrumb"), ), ) parent_classes = () allow_children = None def get_render_template(self, context, instance, placeholder): render_type = instance.glossary.get('render_type') try: return select_template([ '{}/breadcrumb/{}.html'.format(shop_settings.APP_LABEL, render_type), 'shop/breadcrumb/{}.html'.format(render_type), ]) except TemplateDoesNotExist: return Template('<!-- empty breadcrumb -->')
class ArticleForm(forms.Form): title = fields.CharField( widget=widgets.TextInput(attrs={'class': 'form-control', 'placeholder': '文章标题'}) ) summary = fields.CharField( widget=widgets.Textarea(attrs={'class': 'form-control', 'placeholder': '文章简介', 'rows': '3'}) ) content = fields.CharField( widget=widgets.Textarea(attrs={'class': 'kind-content'}) ) article_type_id = fields.IntegerField( widget=widgets.RadioSelect(choices=models.Article.type_choices) ) category_id = fields.ChoiceField( choices=[], widget=widgets.RadioSelect ) tag = fields.MultipleChoiceField( choices=[], widget=widgets.CheckboxSelectMultiple ) def __init__(self, request, *args, **kwargs): super(ArticleForm, self).__init__(*args, **kwargs) blog_id = request.session['user_info']['blog__nid'] self.fields['category_id'].choices = models.Article.objects.filter(blog_id=blog_id).values_list('nid', 'title') self.fields['tag'].choices = models.Article.objects.filter(blog_id=blog_id).values_list('nid', 'title')
class LoginForm(forms.Form): username = fields.CharField( widget=widgets.TextInput(attrs={ "class": "form-control", "placeholder": "学号/工号" }), label="ID", validators=[RegexValidator(r'\d{8,13}')], error_messages={ 'required': '该字段必须要输入', 'invalid': '输入不符合要求' }) password = fields.CharField( widget=widgets.TextInput(attrs={ "type": "password", "class": "form-control", "placeholder": "在这里输入密码" }), label="密码", help_text="初始密码为身份证后6位") choices = ( (1, "学生"), (2, "教师"), (3, "教务"), ) group_id = fields.IntegerField(widget=widgets.RadioSelect(choices=choices), label="选择你的身份")
class BreadcrumbPlugin(ShopPluginBase): name = _("Breadcrumb") CHOICES = (('default', _("Default Breadcrumb")), ('soft-root', _("“Soft-Root” Breadcrumb")), ('catalog', _("With Catalog Count")), ('empty', _("Hidden Breadcrumb")),) parent_classes = () allow_children = None render_type = GlossaryField( widgets.RadioSelect(choices=CHOICES), label=_("Render as"), initial='default', help_text=_("Render an alternative Breadcrumb"), ) @classmethod def get_identifier(cls, instance): render_type = instance.glossary.get('render_type') return mark_safe(dict(cls.CHOICES).get(render_type, '')) def get_render_template(self, context, instance, placeholder): render_type = instance.glossary.get('render_type') try: return select_template([ '{}/breadcrumb/{}.html'.format(app_settings.APP_LABEL, render_type), 'shop/breadcrumb/{}.html'.format(render_type), ]) except TemplateDoesNotExist: return engines['django'].from_string('<!-- empty breadcrumb -->') def get_use_cache(self, context, instance, placeholder): try: app = apphook_pool.get_apphook(instance.page.application_urls) return app.cache_placeholders except (AttributeError, ImproperlyConfigured): return super(BreadcrumbPlugin, self).get_use_cache(context, instance, placeholder)
class Meta: model = RMUser fields = [ 'name', 'email', 'receive_questions', 'receive_emails', 'single_page', 'dob', 'gender', 'postcode' ] widgets = {'gender': widgets.RadioSelect()}
class TestForm(forms.Form): n1 = fields.CharField(widget=widgets.PasswordInput()) n2 = fields.CharField(widget=widgets.Textarea()) n3 = fields.CharField(widget=widgets.Select(choices=[ (1, "上海"), (2, "北京"), (3, "广州"), ])) n4 = fields.ChoiceField(choices=[(1, "上海"), (2, "北京"), (3, "广州")], widget=widgets.SelectMultiple()) n5 = fields.IntegerField(widget=widgets.RadioSelect(choices=[ (1, '上海'), (2, '北京'), ])) n6 = fields.CharField(widget=widgets.CheckboxInput()) n7 = fields.ChoiceField(choices=[ (1, '上海'), (2, '北京'), ], widget=widgets.CheckboxSelectMultiple()) n8 = fields.FileField()
class ShopCatalogPlugin(ShopPluginBase): name = _("Catalog List View") require_parent = True parent_classes = ('BootstrapColumnPlugin', 'SimpleWrapperPlugin',) cache = False pagination = GlossaryField( widgets.RadioSelect(choices=[ ('paginator', _("Use Paginator")), ('manual', _("Manual Infinite")), ('auto', _("Auto Infinite")) ]), label=_("Pagination"), initial=True, help_text=_("Shall the product list view use a paginator or scroll infinitely?"), ) def get_render_template(self, context, instance, placeholder): templates = [] if instance.glossary.get('render_template'): templates.append(instance.glossary['render_template']) templates.extend([ '{}/catalog/list.html'.format(app_settings.APP_LABEL), 'shop/catalog/list.html', ]) return select_template(templates) def render(self, context, instance, placeholder): context['pagination'] = instance.glossary.get('pagination', 'paginator') return context @classmethod def get_identifier(cls, obj): pagination = obj.glossary.get('pagination') if pagination == 'paginator': return ugettext("Manual Pagination") return ugettext("Infinite Scroll")
class StudentEditForm(forms.ModelForm): gender = Ffields.ChoiceField(required=True, choices=((1, '男'), (2, '女')), widget=Fwidgets.RadioSelect()) birthday = Ffields.DateField( required=False, widget=DateTimePickerInput(attrs={ 'type': 'date', 'style': 'width: 600px' })) class Meta: model = stumodels.StudentInfo fields = ("last_name", 'first_name', 'full_name', "gender", "birthday", 'period', 'school', 'period', 'age', 'day_age', 'constellation', 'chinese_zodiac', 'school') widgets = { "last_name": Fwidgets.TextInput(attrs={ 'class': 'form-control', 'style': 'width: 600px' }), "first_name": Fwidgets.TextInput(attrs={ 'class': 'form-control', 'style': 'width: 600px' }), "school": Ffields.Select(attrs={ 'class': 'form-control', 'style': 'width: 600px' }) }
class Meta: model = models.Audioset fields = [ 'name', 'published', 'description', 'slug', 'image', 'readme', 'mode_display', 'background', 'map_scale', 'map_center_x', 'map_center_y', 'playmode', 'audio_bpm', 'audio_quantize', 'map_url', 'map_lambda', 'map_shift_vertical', ] widgets = { 'description' : LimitedTextareaWidget(attrs={'rows':2 }, limit=70), 'image' : ImagePreviewWidget( placeholder=_('<img src="%s" />' % static('img/audioset.jpg')) ), 'mode_display' : widgets.RadioSelect(), 'background' : ImagePreviewWidget(), }
class ArticleForm(django_forms.Form): title = django_fields.CharField( widget=django_widgets.TextInput(attrs={ 'class': 'form-control', 'placeholder': '文章标题' }), error_messages={'required': '标题不能为空.'}) content = django_fields.CharField( widget=django_widgets.Textarea(attrs={ 'class': 'form-control', 'placeholder': '文章简介', 'rows': '3' }), error_messages={'required': '简介不能为空.'}) detail = django_fields.CharField( widget=django_widgets.Textarea(attrs={'class': 'kind-content'}), error_messages={'required': '内容不能为空.'}) category_id = django_fields.IntegerField( widget=django_widgets.RadioSelect( choices=models.Article.category_choice), error_messages={'required': '请选择一个分类.'}) tags = django_fields.MultipleChoiceField( choices=[], widget=django_widgets.CheckboxSelectMultiple, error_messages={'required': '请选择标签.'}) def __init__(self, request, *args, **kwargs): super(ArticleForm, self).__init__(*args, **kwargs) blog_id = request.session['user_info']['blog__nid'] self.fields['tags'].choices = models.Tag.objects.filter( blog_id=blog_id).values_list('nid', 'caption')
class ShippingMethodForm(DialogForm): scope_prefix = 'data.shipping_method' shipping_modifier = fields.ChoiceField( label=_("Shipping Method"), widget=widgets.RadioSelect(attrs={'ng-change': 'upload()'}), ) def __init__(self, *args, **kwargs): choices = [ m.get_choice() for m in cart_modifiers_pool.get_shipping_modifiers() if not m.is_disabled(kwargs['cart']) ] self.base_fields['shipping_modifier'].choices = choices if len(choices) == 1: # with only one choice, initialize with it try: kwargs['initial']['shipping_modifier'] = choices[0][0] except KeyError: pass super(ShippingMethodForm, self).__init__(*args, **kwargs) def has_choices(self): return len(self.base_fields['shipping_modifier'].choices) > 0 @classmethod def form_factory(cls, request, data, cart): cart.update(request) shipping_method_form = cls(data=data, cart=cart) if shipping_method_form.is_valid(): cart.extra.update(shipping_method_form.cleaned_data) return shipping_method_form
class ArticleForm(Form): def __init__(self, val, *args, **kwargs): super(ArticleForm, self).__init__(*args, **kwargs) self.val = val self.fields['category_id'].choices = models.Category.objects.filter( blog__user=self.val).values_list('nid', 'title').all() self.fields['tags'].choices = models.Tag.objects.filter( blog__user=self.val).values_list('nid', 'title').all() print(self.val) title = fields.CharField(max_length=64) summary = fields.CharField(max_length=128) article_type_id = fields.IntegerField(widget=widgets.RadioSelect( choices=models.Article.type_choices)) category_id = fields.ChoiceField(widget=widgets.RadioSelect) tags = fields.MultipleChoiceField(widget=widgets.CheckboxSelectMultiple) content = fields.CharField(widget=widgets.Textarea(attrs={'id': 'i1'})) def clean_content(self): old = self.cleaned_data['content'] from utils.xss import xss return xss(old)
class ProjectConfigForm(forms.Form): name = forms.CharField(label='Project Code') platform = forms.CharField(label='Platform') sku = forms.CharField(label='SKU') stage = forms.ModelChoiceField( label='Stage', widget=widgets.RadioSelect(renderer=BootstrapInlineRadioRenderer), queryset=Stage.objects.all(), empty_label=None) ftp_username = forms.CharField(label='FTP Username', max_length=50, required=False) ftp_password = forms.CharField( label='FTP Password', max_length=50, required=False, widget=widgets.PasswordInput(render_value=True)) ftp_host = forms.CharField(label='FTP Host', max_length=50, required=False) ftp_upload_path = forms.CharField(label='Upload Path', max_length=50, required=False) ftp_folder_have_project_name = forms.BooleanField( label='Folder include project name', required=False) ftp_folder_have_version_name = forms.BooleanField( label='Folder include version name', required=False)
class ArticleForm(forms.Form): title = forms.CharField(widget=widgets.TextInput(attrs={ 'class': 'form-control', 'placeholder': '文章标题' })) summary = forms.CharField(widget=widgets.Textarea( attrs={ 'class': 'form-control', 'placeholder': '文章简介', 'rows': '3' })) content = forms.CharField(widget=widgets.Textarea( attrs={'class': 'kind-content'})) # 单选按钮(定义的枚举) ms_Type = forms.IntegerField(widget=widgets.RadioSelect( choices=models.Article.masterStation_type)) # 分类 classification_id = forms.ChoiceField(choices=[], widget=widgets.RadioSelect) # 标签 tags = forms.MultipleChoiceField(choices=[], widget=widgets.CheckboxSelectMultiple) def __init__(self, request, *args, **kwargs): super(ArticleForm, self).__init__(*args, **kwargs) blog_id = request.session['user_info']["bloginfo__bid"] self.fields[ 'classification_id'].choices = models.Classification.objects.filter( blog_id=blog_id).values_list('nid', 'title') self.fields['tags'].choices = models.Tag.objects.filter( blog_id=blog_id).values_list('nid', 'title')
class Meta(object): model = Event fields = ('template', 'recursive') widgets = { 'recursive': widgets.RadioSelect(choices=[(False, 'Нет'), (True, 'Да')]), }
class PaymentMethodForm(DialogForm): scope_prefix = 'data.payment_method' payment_modifier = fields.ChoiceField( label=_("Payment Method"), widget=widgets.RadioSelect(attrs={'ng-change': 'upload()'}), ) def __init__(self, *args, **kwargs): choices = [ m.get_choice() for m in cart_modifiers_pool.get_payment_modifiers() if not m.is_disabled(kwargs['cart']) ] self.base_fields['payment_modifier'].choices = choices if len(choices) == 1: # if there is only one shipping method available, always set it as default try: kwargs['initial']['payment_modifier'] = choices[0][0] except KeyError: pass super(PaymentMethodForm, self).__init__(*args, **kwargs) def has_choices(self): return len(self.base_fields['payment_modifier'].choices) > 0 @classmethod def form_factory(cls, request, data, cart): cart.update(request) payment_method_form = cls(data=data, cart=cart) if payment_method_form.is_valid(): cart.extra.update(payment_method_form.cleaned_data, payment_extra_data=data.get('payment_data', {})) return payment_method_form
class ArticleForm(django_forms.Form): title =django_fields.CharField( widget=django_widgets.TextInput(attrs={'class':'form-control','placeholder':'文章标题'}) ) summary = django_fields.CharField( widget=django_widgets.Textarea(attrs={'class':'form-control','placeholder':'文章简介','rows':'3'}) ) content = django_fields.CharField( widget= django_widgets.Textarea(attrs={'class':'kind-content'}) ) article_type_id = django_fields.IntegerField( widget=django_widgets.RadioSelect(choices=models.Article.type_choices) ) category_id = django_fields.ChoiceField( choices=[], widget=django_widgets.RadioSelect ) tags = django_fields.MultipleChoiceField( choices=[], widget=django_widgets.CheckboxSelectMultiple ) # 主要是为了实现数据库的实时更新(初始化函数中加上数据的获取) def __init__(self,request,*args,**kwargs): super(ArticleForm,self).__init__(*args,**kwargs) blog_id =request.session['user_info']['blog__nid'] self.fields['category_id'].choices = models.Category.objects.filter(blog_id=blog_id).values_list('nid','title') print(self.fields['category_id']) #<django.forms.fields.ChoiceField object at 0x035E0B30> print(self.fields['category_id'].choices) # [(1, '.NET'), (2, '领域驱动'), (3, 'python'), (4, '设计模式'), (5, 'letCode')] self.fields['tags'].choices = models.Tag.objects.filter(blog_id=blog_id).values_list('nid','title')
class BootstrapContainerPlugin(BootstrapPluginBase): name = _("Container") default_css_class = 'container' require_parent = False CONTEXT_WIDGET_CHOICES = ( ('lg', _('Large (>1200px)')), ('md', _('Medium (>992px)')), ('sm', _('Small (>768px)')), ('xs', _('Tiny (<768px)')), ) partial_fields = (PartialFormField( 'breakpoint', widgets.RadioSelect(choices=CONTEXT_WIDGET_CHOICES, renderer=ContainerRadioFieldRenderer), label=_('Display Breakpoint'), initial=settings.CMS_CASCADE_BOOTSTRAP3_BREAKPOINT, help_text=_("Narrowest display for Bootstrap's grid system.")), ) @classmethod def get_identifier(cls, obj): try: texts = [ d for c, d in cls.CONTEXT_WIDGET_CHOICES if c == obj.context.get('breakpoint') ] return _('Narrowest grid: {0}').format(texts[0].lower()) except (TypeError, KeyError, ValueError): return ''
def get_form_class(self, scales_issues): fields = {'topic_id': forms.IntegerField(widget=widgets.HiddenInput(), initial=self.id)} # TODO: optimize database queries for idx, scale_issue in enumerate(scales_issues): scale = ScaleInTopic.objects.filter( topic=self, scale_label_group=scale_issue.label_group).get() scale_label_group = scale.scale_label_group labels = ScaleLabel.objects.filter(group=scale_label_group) name = '%s__%s__%s' % (self.short_name, scale_label_group.scale.short_name, scale_label_group.short_name) # TODO: extract to class fields[name] = forms.TypedChoiceField( label=scale.scale.title, choices=[(label.mark, label.label_text) for label in labels], coerce=int, required=True, error_messages={ 'required': 'Выберите вариант', 'invalid_choice': 'Какой-то неправильный вариант. Давайте ' 'попробуем ещё раз'}, widget=widgets.RadioSelect(attrs={})) return type('%sForm' % self.short_name, (forms.Form,), fields)