class NameForm(forms.ModelForm): helper = FormHelper() helper.layout = Layout( 'name', Submit("save", "Save"), Button("cancel", "Cancel", data_toggle="collapse", data_target="#name_form"), ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self.instance.public: self.fields[ 'name'].help_text = 'Changing the name of your ballot will also change the share link to your ballot' def save(self): obj = super().save(commit=False) obj.slug = slugify(obj.name) obj.save() return obj class Meta: fields = ['name'] model = RankedList
def __init__(self, *args, **kwargs): """Initiate form with Crispy Form's FormHelper.""" super(AddressForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Submit')) self.helper.layout = Layout( Fieldset( 'An address', Field( 'street', autofocus=True, ), 'postal_code', Field('place', placeholder='Wait for it.'), Field('municipality', readonly='true', placeholder='Will be filled automatically.'), Field('city', readonly='true', placeholder='Will be filled automatically.'), Field('state', readonly='true', placeholder='Will be filled automatically.'), ), ) self.fields['place'].required = True self.fields['street'].required = True self.fields['postal_code'].required = True
def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) self.object = kwargs.pop('object', None) super(CategoriaForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Div( Div(Row( Div(Field('descripcion', placeholder="Ingrese un nombre"), css_class='col-md-6'), Div(FieldWithButtons( 'departamento', StrictButton("Agregar", id='addDepartamento')), css_class='col-md-6'), ), css_class='modal-body'), Div( Row(FormActions( smtSave(), btnCancel(), btnReset(), ), ), css_class='modal-footer', ), ), )
def __init__(self, *args, **kwargs): super(MenuForm, self).__init__(*args, **kwargs) self.fields[ 'tipo_menu'].help_text = u'<small class="help-error"></small> %s' % ( u' ') self.fields[ 'fecha'].help_text = u'<small class="help-error"></small> %s' % ( u' ') self.helper = FormHelper() self.helper.form_class = 'js-validate form-vertical' self.helper.form_id = 'form' self.helper.layout = Layout( Div( HTML( '<button type="button" class="close" data-dismiss="modal" \ aria-hidden="true">×</button>\ <h4 class="modal-title"><i class="fa fa-info"></i>\ Formulario menu</h4>'), css_class="modal-header modal-header-primary", ), Div( Field('tipo_menu', css_class='input-required'), Field('fecha', css_class='input-required'), css_class="modal-body", ), Div(FormActions( smtSave(), Button('cancel', 'Cancel', data_dismiss="modal", css_class="btn-default")), css_class='modal-footer'))
def __init__(self, user, *args, **kwargs): super(GlucoseFilterForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'filter_form' self.helper.form_method = 'post' self.helper.form_action = '.' self.fields['tags'] = forms.ChoiceField(choices=self.get_tags( Glucose.objects.filter(user=user).exclude( tags__name__isnull=True)), required=False) self.helper.layout = Layout( 'quick_date_select', Field('start_date', placeholder='From (mm/dd/yyyy)'), Field('end_date', placeholder='To (mm/dd/yyyy)'), 'category', Field('start_value', placeholder='From', step='any'), Field('end_value', placeholder='To', step='any'), 'notes', Field('tags'), FormActions( Submit('submit', 'Filter'), Reset('reset', 'Reset'), ), )
def __init__(self, *args, **kwargs): super(ClienteForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_class = 'form-vertical' self.helper.layout = Layout( Row( Div(Field('nombre', css_class='input-required'), css_class='col-md-6'), Div(Field('apellidos', css_class=''), css_class='col-md-6'), ), Row( Div(Field('dni', css_class='input-numeric mask-num'), css_class='col-md-6'), Div(Field('categoria', css_class='input-numeric mask-num'), css_class='col-md-6'), ), Row( Div(Field('productos', css_class=''), css_class='col-md-6'), ), Row( Div(Field('foto', css_class=''), css_class='col-md-6'), ), FormActions( Submit('save', 'Save changes'), Button('cancel', 'Cancel') ) )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_class = "form-class" self.helper.field_class = "form-field-class" self.helper.layout = Layout( "users", Submit("submit", "Add To Group", css_class="col-lg-2"))
def __init__(self, *args, **kwargs): super(HeadquarForm, self).__init__(*args, **kwargs) self.fields[ 'name'].help_text = u'<small class="help-error"></small> %s' % _( u' ') self.fields[ 'phone'].help_text = u'<small class="help-error"></small> %s' % _( u' ') self.fields['address'].widget.attrs = { 'rows': 3, } self.helper = FormHelper() self.helper.form_id = 'form' self.helper.form_class = 'js-validate form-vertical' self.helper.layout = Layout( Row( Div(Field('name', css_class='input-required'), css_class='col-md-6'), Div(Field('phone', css_class='input-integer'), css_class='col-md-6'), ), Row(Div(Field('address', ), css_class='col-md-6'), ), Row(FormActions( smtSave(), btnCancel(), btnReset(), ), ), )
def __init__(self, *args, **kwargs): super(PostForm, self).__init__(*args, **kwargs) self.fields[ 'title'].help_text = u'<small class="help-error"></small> %s' % ( u' ') self.fields[ 'body'].help_text = u'<small class="help-error"></small> %s' % ( u' ') self.fields['body'].widget.attrs = { 'rows': 3, } self.fields['body'].label = 'Cuerpo' self.helper = FormHelper() self.helper.form_class = 'js-validate form-vertical' self.helper.form_id = 'form' self.helper.layout = Layout( Row( Div(Field('title', css_class='input-required'), css_class='col-md-6'), Div(Field('body', css_class="input-required"), css_class='col-md-6'), ), Row( Div(Field('asd', css_class='input-required'), css_class='col-md-6'), ), Row(FormActions( smtSave(), btnCancel(), btnReset(), ), ), )
def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) self.object = kwargs.pop('object', None) super(ProductoForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Div(Field('nombre', placeholder="username"), css_class='col-md-6'), Div(Field('codigo', placeholder="username"), css_class='col-md-3'), Div(Field('fechaVencimiento', placeholder="YYYY-MM-DD"), css_class='col-md-3'), ), Row( Div(FieldWithButtons( 'categoria', StrictButton("Agregar", id='addCategoria')), css_class='col-md-4'), Div(FieldWithButtons('unidad_medida', StrictButton("Agregar", id='addUnidad')), css_class='col-md-4'), Div(Field('precioC', placeholder="username"), css_class='col-md-2'), Div(Field('precioV', placeholder="username"), css_class='col-md-2'), ), Div( Row(FormActions( smtSave(), btnCancel(), btnReset(), ), ), css_class='modal-footer', ), )
def __init__(self, *args, **kwargs): super(HeadquarAssociationForm, self).__init__(*args, **kwargs) self.fields['association_name'] = forms.CharField( label=capfirst(_(u'Association')), required=True, help_text=u'<small class="help-error"></small> %s' % _(u' '), ) self.helper = FormHelper() self.helper.form_id = 'form' self.helper.form_class = 'js-validate form-vertical' self.helper.layout = Layout( Row( Div(Field('association_name', css_class='input-required', autocomplete='off'), css_class='col-md-6'), ), # Row( # Div(Field('association',), # css_class='col-md-6'), #), Row(FormActions( smtSave(), btnCancel(), btnReset(), ), ), )
def get_crispy_helper(self, form_class, fieldsets): # TODO extract to mixin from crispy_forms.helper import FormHelper, Layout from crispy_forms.layout import Div, Fieldset helper = getattr(form_class, 'helper', None) if helper and isinstance(helper, FormHelper): return helper helper = FormHelper() helper_args = [] for header, _fieldset in fieldsets: _fieldset_args = [] for _field in _fieldset['fields']: if isinstance(_field, (tuple, list)): row = Div( *_field, css_class='form-row form-group field-box col-sm-%s' % (12 / len(_field))) else: row = Div(*_field, css_class='form-row form-group') _fieldset_args.append(row) helper_args.append( Fieldset(header, *_fieldset_args, css_class=_fieldset.get('classes'))) helper.add_layout(Layout(*helper_args)) return helper
def __init__(self, *args, **kwargs): super(ContactForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_class = 'col-xs-12 col-md-6' self.helper.layout = Layout( HTML (''' <p> {% if messages %} {% for message in messages %} <p {% if message.tags %} class="alert alert-{{ message.tags }}"{% endif %}> {{ message }} </p> {% endfor %} {% endif %} </p> '''), Fieldset ( 'Contact Us', Field('email'), Field('subject'), Field('message'), ), FormActions(Submit('submit', 'Send', css_class='pull-right')) )
def __init__(self, payload, *args, **kwargs): super(GameEditForm, self).__init__(payload, *args, **kwargs) self.fields["name"].label = "Title" self.fields["year"].label = "Release year" self.fields["title_logo"] = CroppieField( options={ "viewport": {"width": 875, "height": 345}, "boundary": {"width": 875, "height": 345}, "showZoomer": True, "url": payload["title_logo"].url if payload.get("title_logo") else "", } ) self.fields["title_logo"].label = "Upload an image" self.fields["title_logo"].required = False self.helper = FormHelper() self.helper.include_media = False self.helper.layout = Layout( Fieldset( None, "name", "year", "developer", "publisher", "website", "platforms", "genres", "description", Field("title_logo", template="includes/upload_button.html"), "reason", ), ButtonHolder(Submit("submit", "Submit")), )
def __init__(self, *args, **kwargs): # get layer object from kwargs if 'layer' in kwargs: self.layer = kwargs['layer'] del (kwargs['layer']) super(ActiveEditingLayerForm, self).__init__(*args, **kwargs) # set choices self._set_viewer_users_choices() self._set_viewer_user_groups_choices() self._set_add_edit_user_field_choices() self.helper = FormHelper(self) self.helper.form_tag = False self.helper.layout = Layout( HTML( _('Check on uncheck to attive/deactive editing layer capabilities:' )), 'active', 'scale', Field('add_user_field', css_class='select2', style="width:100%;"), Field('edit_user_field', css_class='select2', style="width:100%;"), HTML( _('Select viewers with \'view permission\' on project that can edit layer:' )), Field('viewer_users', css_class='select2', style="width:100%;"), Div(css_class='users_atomic_capabilities'), Field('user_groups_viewer', css_class='select2', style="width:100%;"), Div(css_class='user_groups_atomic_capabilities'))
class SetPasswordForm(auth_forms.SetPasswordForm): def __init__(self, *args, **kwargs): super(SetPasswordForm, self).__init__(*args, **kwargs) for fieldname in ['new_password1', 'new_password2']: self.fields[fieldname].help_text = None helper = FormHelper() helper.form_method = 'POST' helper.form_class = 'login-form' helper.form_show_labels = False helper.layout = Layout( HTML('<h3 class="login-head">' 'Set New Password</h3> '), Div(Field('new_password1', css_class='form-control text-center', placeholder='Enter New Password', autofocus=True), css_class='form-group'), Div(Field('new_password2', css_class='form-control text-center', placeholder='Confirm New Password'), css_class='form-group'), Div(FormActions( Submit('send', 'SUBMIT', css_class='btn btn-primary btn-block')), css_class='form-group'), Div(Div( HTML('<br />\ <p class="semibold-text mb-0">' "<a href='{% url 'signin' %}'>\ <i class='fa fa-angle-left fa-fw'></i>\ Back to Login\ </a>\ </p>")), css_class='form-group text-center mt-20'))
def __init__(self, *args, **kwargs): super(DownloadForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'download_form' self.helper.form_method = 'post' self.helper.form_class = 'form-horizontal col-xs-12 col-sm-12 ' \ 'col-md-8 col-lg-8 col-md-offset-2 ' \ 'col-lg-offset-2' self.helper.field_class = 'col-lg-12' self.helper.form_show_labels = False self.helper.layout = Layout( Fieldset( "Enter the video URL to convert to MP3", Div( css_id='result', ), Field('url', placeholder='e.g. https://www.youtube.com/watch?v=JAFQFvSPhQ8', onclick='select("id_url");', autofocus=True, ), FormActions( HTML("""<p class="text-center">"""), Submit('submit', 'Start Conversion', css_class='btn-lg'), ), ), )
class ForgotPassForm(auth_forms.PasswordResetForm): helper = FormHelper() helper.form_method = 'POST' helper.form_class = 'login-form' helper.form_show_labels = False helper.layout = Layout( HTML('<h3 class="login-head">' 'Forgot Password?</h3> <br />'), Div(Field('email', css_class='form-control text-center', placeholder='Email Address', autofocus=True), css_class='form-group'), Div(HTML('<br />'), FormActions( Submit('send', 'RESET', css_class='btn btn-primary btn-block')), css_class='form-group'), Div(Div( HTML('<br />\ <p class="semibold-text mb-0">' "<a href='{% url 'signin' %}'>\ <i class='fa fa-angle-left fa-fw'></i>\ Back to Login\ </a>\ </p>")), css_class='form-group text-center mt-20'))
class UserListFormHelper(FormHelper): def __init__(self, *args, **kwargs): super(UserListFormHelper, self).__init__(*args, **kwargs) # InlineField.fields = '' form_id = 'user_list_form' form_class = 'form-inline' field_template = 'bootstrap3/layout/inline_field.html' # field_class = 'col-xs-3' # label_class = 'col-xs-3' form_show_errors = True help_text_inline = False html5_required = True layout = Layout( Fieldset( '<i class="fa fa-search"></i> Search Staff Records', InlineField('first_name'), InlineField('last_name'), InlineField('username'), InlineField('email'), ), FormActions( Submit('search', 'Search', css_class='btn btn-primary'), HTML(""" <a href="{% url 'accounts:user-list'%}"> <input type="button" class="btn btn-default" value="Reset"> </a> """) ) )
class AddComponentForm(forms.Form): COMPOS = (['solar_panel', 'SOLAR PANEL'], ['solar_battery', 'SOLAR BATTERY']) components = forms.ChoiceField(choices=COMPOS, required=True) helper = FormHelper() helper.form_method = 'POST' helper.form_show_labels = False helper.layout = Layout( Div(Div(Field('components', css_class='form-control selectpicker text-center', multiple='true', data_done_button='true', id='done'), css_class='col-md-12'), css_class='row mb-20'), Div(Div(HTML("<a class='btn btn-warning btn-block icon-btn' \ href='{% url 'component-order' %}'> Cancel</a>"), css_class='col-md-6'), Div(FormActions( Submit('okay', 'Okay', css_class='btn btn-primary btn-block')), css_class='form-group col-md-6'), css_class='card-footer col-md-12'), )
def __init__(self, *args, **kwargs): super(UserSettingsForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_class = 'form-horizontal col-xs-12 col-md-6 col-lg-6' self.helper.label_class = 'col-xs-4 col-md-4 col-lg-4' self.helper.field_class = 'col-xs-8 col-md-8 col-lg-8' self.helper.help_text_inline = False self. helper.layout = Layout( HTML(''' {% if messages %} {% for message in messages %} <p {% if message.tags %} class="alert alert-{{ message.tags }}"\ {% endif %}>{{ message }}</p>{% endfor %}{% endif %} </p> '''), Fieldset( 'Profile', Field('username', readonly=True), Field('credit', readonly=True), Field('email'), Field('first_name'), Field('last_name'), ), FormActions( Submit('submit', 'Save'), Button('cancel', 'Cancel', onclick='location.href="%s";' \ % reverse('index')), ), )
class NewProductForm(forms.Form): new_name = forms.CharField(max_length=100) new_price = forms.FloatField() helper = FormHelper() helper.form_method = 'POST' helper.form_show_labels = False helper.form_id = "new_product_form" helper.layout = Layout( Div(Div(Field('new_name', id='new_prod_name', placeholder='Product name', css_class='form-control text-center'), css_class='col-md-12 text-center'), css_class='row mb-20'), Div(Div(Field('new_price', id='new_price_name', placeholder='Product price, e.g., R100.50', css_class='form-control text-center'), css_class='col-md-12 text-center'), css_class='row mb-20'), Div(Div(HTML("<a class='btn btn-warning btn-block icon-btn' \ href='{% url 'my-products' %}'> Cancel</a>"), css_class='col-md-6'), Div(FormActions( Submit('okay', 'Okay', css_class='btn btn-primary btn-block')), css_class='form-group col-md-6'), css_class='card-footer col-md-12'), )
def __init__(self, *args, **kwargs): super(GlucoseImportForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.layout = Layout( MultiField( None, HTML(''' {% if messages %} {% for message in messages %} <p {% if message.tags %} class="alert alert-{{ message.tags }}" {% endif %}>{{ message }}</p>{% endfor %}{% endif %} '''), Div( 'file', FormActions( Submit('submit', 'Import'), css_class='pull-right', ), css_class='well col-xs-10 col-sm-8 col-md-8', ), ), )
def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) self.object = kwargs.pop('object', None) super(UserActiveUpdateForm, self).__init__(*args, **kwargs) self.fields['description'] = forms.CharField( label=capfirst(_(u'Description')), required=True, help_text=u'<small class="help-error"></small> %s' % _(u' '), ) self.helper = FormHelper() self.helper.layout = Layout( Row( Div(Field('username', readonly=True), css_class='col-md-6'), Div(Field('is_active'), css_class='col-md-6'), ), Row(Div(Field('description', ), css_class='col-md-6'), ), Row(FormActions( smtSave(), btnCancel(), btnReset(), ), ), )
def __init__(self, *args, **kwargs): super(GlucoseQuickAddForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_id = 'quick_add_form' self.helper.form_method = 'post' self.helper.form_class = 'form-inline' self.helper.form_show_labels = False # Remove the blank option from the select widget. self.fields['category'].empty_label = None self.helper.layout = Layout( HTML(''' <div id="div_id_value" class="form-group"> <div class="controls"> <input autofocus="True" class="numberinput form-control" id="id_value" name="value" placeholder="Value ({{ user.settings.glucose_unit.name }})" required="True" type="number" step="any" min="0"/></div></div> '''), Field('category'), Field('record_date', type='hidden'), Field('record_time', type='hidden'), Submit('submit', 'Quick Add'), )
def __init__(self, *args, **kwargs): self.store_code = kwargs.pop('store_code', 'default') self.page = kwargs.pop('page', 1) super(TestimonialsForm, self).__init__(*args, **kwargs) self.fields['title'].help_text = False self.helper = FormHelper() self.helper.include_media = False self.helper.form_class = 'form' self.helper.layout = Layout( Fieldset( '', # Hide the legend of fieldset (HTML tag) 'title', 'content', ), HTML(''' <button type="submit" class="btn btn-block btn-lg btn-primary my-2"> <i class="fas fa-pencil-alt"></i> {} </button> <hr> <a href="{}?page={}" class="btn btn-block btn-lg btn-outline-secondary my-2"> <i class="fas fa-list"></i> {} </a> '''.format( _('Write'), reverse('help:testimonials-list', args=(self.store_code, )), self.page, _('List'))), )
def __init__(self, *args, **kwargs): super(ActiveCachingLayerForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_tag = False self.helper.layout = Layout( Div(HTML( _('Check on uncheck to attive/desctive caching layer capabilities:' )), Div(Div('active', 'reset_layer_cache_url', css_class='col-md-3'), Div(Div( HTML( "<button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>Action <span class='caret'></span></button>" ), HTML( "<ul class='dropdown-menu'>" "<li><a id='resetcache' href='#'><i class='fa fa-eraser'></i> {}</a></li>" "<li><a id='resetcache_for_project' href='#'><i class='fa fa-eraser'></i> {}</a></li>" "</ul>".format(_('Reset cache'), _('Reset cache for project'))), css_class='btn-group'), css_class='col-md-9'), css_class='row'), css_class='col-md-12'))
def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) self.object = kwargs.pop('object', None) super(TrabajadorForm, self).__init__(*args, **kwargs) self.fields['photo'] = forms.ImageField( label='', required=False, initial='persons/default.png', help_text=u'<small class="help-error"></small> %s' % _(u'JPG, GIF, o PNG.'), ) self.helper = FormHelper() self.helper.layout = Layout( Row( Div(Div(Field('photo'), css_class='text-center'), css_class='col-md-4'), Div(Div(Field('nombre', placeholder='Ingrese un nombre')), Div( Field('apellidos', placeholder='Ingrese sus apellidos'), ), Div(Field('tipo_documento', ), ), Div(Field('numero', placeholder='Ingrese un número'), ), Div(Field('fecha_de_nacimiento', placeholder='YYYY-MM-DD'), ), FormActions( smtSave(), btnCancel(), ), css_class='col-md-8'), ), )
def __init__(self, *args, **kwargs): super(CompetitionCreateFormHelper, self).__init__(*args, **kwargs) self.layout = Layout( Fieldset( _('Basic competition data'), 'title', 'slug', 'start', 'end', 'duration', 'motd', ), Fieldset( "<a data-toggle='collapse' href='#competition_advanced'>" + str(_('Advanced competition data')) + "</a>", Div( 'promoted', 'competitor_code_format', 'competitor_salt', 'admin_code_format', 'admin_salt', css_class="competition_advanced collapse", id="competition_advanced", )), )
def __init__(self, *args, **kwargs): super(MemberResetPasswordForm, self).__init__(*args, **kwargs) self.fields['email'].label = False self.helper = FormHelper() self.helper.include_media = False self.helper.form_show_errors = False self.helper.form_class = 'form' self.helper.layout = Layout( Fieldset( '', # Hide the legend of fieldset (HTML tag) Field( PrependedText('email', '<i class="fas fa-envelope"></i>', placeholder=self.fields['email'].widget. attrs['placeholder'])), HTML( '<div class="g-recaptcha" data-sitekey="{}"></div>'.format( settings.GOOGLE_RECAPTCHA['site_key'])), ), HTML('<hr>'), ButtonHolder( Submit('submit', _('Reset My Password'), css_class='btn btn-block btn-lg btn-primary')), )