def __init__(self, *args, **kwargs): super(FundReviewForm, self).__init__(*args, **kwargs) self.helper.layout = Layout( Fieldset( '', "status", "category", "focus", "mandatory", "grant", "grant_heading", "activity", HTML( """Visit <a href="/pages/guide/activities-tag/">Activities Tag Taxonomy</a> for a description about the tags.""" ), "required_blog_posts", PrependedText( "budget_approved", '£', min=0.00, step=0.01, onblur="this.value = parseFloat(this.value).toFixed(2);"), "notes_from_admin", "email", 'not_send_email_field' if self.is_staff else None, 'not_copy_email_field' if self.is_staff else None, )) self.helper.add_input(Submit('submit', 'Submit'))
def layout(self): if settings.TARGET_PERMISSIONS_ONLY: groups = Div() else: groups = Row('groups') # Add filters to layout filter_layout = Layout( Row( Column(HTML('Exposure Time')), Column(HTML('No. of Exposures')), Column(HTML('Block No.')), )) for filter_name in self.filters: filter_layout.append(Row(filter_name)) return Div(Div(filter_layout, css_class='col-md-6'), Div(Row('max_airmass'), Row(PrependedText('min_lunar_distance', '>')), Row('instrument_type'), Row('proposal'), Row('observation_mode'), Row('ipp_value'), groups, css_class='col-md-6'), css_class='form-row')
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')), )
def __init__(self, *args, **kwargs): super(MemberAddEmailForm, self).__init__(*args, **kwargs) self.fields['email'].label = False self.helper = FormHelper() self.helper.include_media = False self.helper.form_action = reverse('account_email') 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'])), ), ButtonHolder( # NOTE: Button name must be `action_add`. Otherwise, it does not work. Submit('action_add', _('Add E-mail'), css_class='btn btn-block btn-lg btn-primary')), )
class AddBid(ModelForm): def __init__(self, *args, **kwargs): self.auction_pk = kwargs.pop('auction_pk', False) self.auction = Auction.objects.get(pk=self.auction_pk) super(AddBid, self).__init__(*args, **kwargs) self.fields['auction'].initial = self.auction helper = FormHelper() helper.form_method = 'POST' helper.layout = Layout(PrependedText('amount', '$'), Field('auction', type='hidden'), FormActions(Submit('Submit', 'Submit this bid'))) def clean(self): if 'amount' in self.cleaned_data: current_price = self.auction.end_price if self.cleaned_data['amount'] <= current_price: raise ValidationError( "Bid amount must be greater than current price.") else: raise ValidationError("Form is empty.") class Meta: model = Bid fields = ['amount', 'auction'] labels = {'amount': 'Place a bid on this item:'}
def test_error_text_inline(self): form = TestForm({'email': 'invalidemail'}) form.helper = FormHelper() layout = Layout( AppendedText('first_name', 'wat'), PrependedText('email', '@'), PrependedAppendedText('last_name', '@', 'wat'), ) form.helper.layout = layout form.is_valid() html = render_crispy_form(form) help_class = 'help-inline' if self.current_template_pack == 'bootstrap3': help_class = 'help-block' matches = re.findall('<span id="error_\d_\w*" class="%s"' % help_class, html, re.MULTILINE) self.assertEqual(len(matches), 3) form = TestForm({'email': 'invalidemail'}) form.helper = FormHelper() form.helper.layout = layout form.helper.error_text_inline = False html = render_crispy_form(form) matches = re.findall('<p id="error_\d_\w*" class="help-block"', html, re.MULTILINE) self.assertEqual(len(matches), 3)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.use_custom_control = True self.helper.layout = Layout( Fieldset( '', Div(Div(PrependedText('title', '<b>Listing Title: </b>'), css_id='titleUpload'), Div(Div('vehicles', css_id='p_v_left'), Div(HTML(""" <p><i class="fas fa-chevron-left"></i> What vehicles can your spot fit?</p> <p> What type of spot is it?<i class="fas fa-chevron-right"></i></p> """), css_id='p_v_middle'), Div('parking', css_id='p_v_right'), css_id='listingUpload2'), Div(Div(HTML(""" <h2>Your Listing Rates</h2> <i class="fas fa-dollar-sign"></i> """), css_id='rateSide'), Div(PrependedAppendedText('hourly_Rate', '$', '.00'), PrependedAppendedText('day_Rate', '$', '.00'), css_id='rateInput'), css_id='listingUpload3'), Div(Div(HTML(""" <h2>Customize</h2> """), css_id='peopleIcon'), Div(HTML(""" <p>Is parking overnight allowed?</p> """), 'overNight', css_class='radioOptions'), Div(HTML(""" <p>Will you meed to meet renters?</p> """), 'meet_Renter', css_class='radioOptions'), Div(HTML(""" <p>Do they need a parking pass?</p> """), 'parking_Pass', css_class='radioOptions'), css_id="listingUpload4"), Div(Div(HTML(""" <h2>Describe your listing for renters</h2> <i class="far fa-laugh-beam"></i> """), css_id='descripSide'), 'description', css_id='listingUpload5'), Div(FormActions( Submit('Preview Listing', 'Preview Listing')), css_id='btnListing'), css_id="listingUploadDiv")))
def __init__(self, *args, **kwargs): # Grab that host info self.host = kwargs.pop('host', None) super(URLForm, self).__init__(*args, **kwargs) # Define the basics for crispy-forms self.helper = FormHelper() self.helper.form_method = 'POST' # Some xtra vars for form css purposes self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-md-1' self.helper.field_class = 'col-md-6' # The main "layout" defined self.helper.layout = Layout( Fieldset('', ####################### Accordion( # Step 1: Long URL AccordionGroup('Step 1: Long URL', Div( HTML(""" <h4>Paste the URL you would like to shorten:</h4> <br />"""), 'target', style="background: rgb(#F6F6F6);"), active=True, template='crispy/accordian-group.html'), # Step 2: Short URL AccordionGroup('Step 2: Short URL', Div( HTML(""" <h4>Create a custom Go address:</h4> <br />"""), PrependedText( 'short', 'https://go.gmu.edu/', template='crispy/customPrepended.html'), style="background: rgb(#F6F6F6);"), active=True, template='crispy/accordian-group.html',), # Step 3: Expiration AccordionGroup('Step 3: URL Expiration', Div( HTML(""" <h4>Set when you would like your Go address to expire:</h4> <br />"""), 'expires', Field('expires_custom', template="crispy/customDateField.html"), style="background: rgb(#F6F6F6);"), active=True, template='crispy/accordian-group.html'), # FIN template='crispy/accordian.html'), ####################### HTML(""" <br />"""), StrictButton('Shorten', css_class="btn btn-primary btn-md col-md-4", type='submit')))
def __init__(self, *args, **kwargs): super(AnnouncementFormFrontEnd, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.layout = Layout( Field('title', 'body'), PrependedText( 'publish_start_date', '<i class="fa fa-calendar"></i>', css_class="dateinput"), PrependedText( 'publish_end_date', '<i class="fa fa-calendar"></i>', css_class="dateinput"), Field('category', 'link', ), Field('contact'), FormActions( Submit('save', 'Save changes'), HTML( '<a class="btn" href={% url "under_review_front_end" %}>Cancel</a>'), ) )
class StudentProfileForm(forms.ModelForm): class Meta: model = Eleve fields = ('user', 'date_de_naissance', 'ma_classe') widgets = {'user': forms.HiddenInput()} #Crispy FormHelper helper = FormHelper() helper.form_method = 'POST' helper.layout = Layout( PrependedText('date_de_naissance', '<span class="glyphicon glyphicon-user"></span> ', css_class='input-sma'), PrependedText('ma_classe', '<span class="glyphicon glyphicon-home"></span> ', css_class='input-sm'), FormActions(Submit('save', 'continue', css_class='btn-primary'), ))
def __init__(self, *args, **kwargs): super(AddFixedProductForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = False self.helper.layout = Layout( u'fixed_provider', u'account_type', PrependedText(u'balance', u'£', placeholder=1), u'rate', u'maturity_date')
def __init__(self, *args, **kwargs): super(DecryptionForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_show_labels = False self.helper.form_tag = False self.layout = Layout( PrependedText('text', 'Cipher'), )
def __init__(self, *args, **kwargs): super(DecryptionFormSetHelper, self).__init__(*args, **kwargs) self.form_show_labels = False self.layout = Layout( Div( PrependedText('text', 'Cipher '), css_class="formset_object") )
def __init__(self, *args, **kwargs): """ Override to change the display for a Model(Multi)ChoiceField, using the field name and the 'label_from_instance' attribute. :param args: :param kwargs: """ super().__init__(*args, **kwargs) self.fields[ 'publisher'].label_from_instance = lambda obj: "%s" % obj.name self.fields['isbn'].label = 'ISBN' self.fields['format'].empty_label = None self.helper = FormHelper() self.helper.form_id = 'id-add-book-form' self.helper.form_method = 'post' self.helper.form_action = 'create-book' # modify the layout for the form self.helper.layout = Layout( Field('title'), # use this layout to add a '+' button inline with the select widget (for authors); used to add a new author. # This opens a new form for adding an author, and the success (and cancel) route is back to this 'add book' form. # If the 'add author' for is to be used from a different context, e.g. an 'Add Author' button on the Authors List page, # then changes are necessary, e.g. to add a '?next' query string to the route url, etc. # See this SO for how to make the select and link appear inline: http://stackoverflow.com/a/31226655/2152249 Div(Field('authors', style='display: inline-block;'), HTML( """<span class="input-group-btn"><a href="{% url 'create-author' %}" class="btn btn-link"><span class="glyphicon glyphicon-plus"></span></a></span>""" ), css_class="input-group"), # use this to group the publisher and pub_date in a fieldset. # use the same technique as above to add a '+' button (for adding a new Publisher instance). Fieldset( 'Publishing', Div(Field('publisher', style='display: inline-block;'), HTML( """<span class="input-group-btn"><a href="{% url 'create-publisher' %}" class="btn btn-link"><span class="glyphicon glyphicon-plus"></span></a></span>""" ), css_class="input-group"), # 'publisher', 'pub_date'), # Use this fieldset to group 'book information' Fieldset( 'Book Info', # name of the fieldset # the 'isbn' field is supposed to be numeric (not validated) and it is prefixed with 'isbn' string PrependedText('isbn', 'ISBN'), # use inline radio button instead of the default select widget (single selection) InlineRadios('format'), # use inline checkboxes instead of the default select widget (multiple selection) InlineCheckboxes('category'), 'book_cover'), # group the buttons FormActions( Submit('save', 'Save'), # use a link for Cancel HTML( """<a href="{% url 'books' %}" class="btn btn-secondary">Cancel</a>""" )))
def __init__(self, *args, **kwargs): super(participante_crear_form, self).__init__(*args, **kwargs) self.fields["dni"].validators.append(MinLengthValidator(8)) self.fields["dni"].validators.append(RegexValidator(regex="^[0-9]+$")) self.fields["edad"].validators.append(MinValueValidator(12)) self.fields["edad"].validators.append(MaxValueValidator(128)) self.fields["edad"].required=False self.fields["email"].validators.append(validate_email) self.fields["fijo"].validators.append(RegexValidator(regex="^[0-9]+$")) self.fields["fijo"].required=False self.fields["movil"].validators.append(RegexValidator(regex="^[0-9]+$")) self.fields["movil"].required=False self.fields["titulo"].required=False self.fields["investigacion"].required=False self.helper = FormHelper(self) self.helper.form_method = 'POST' self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-md-3' self.helper.field_class = 'col-md-9' self.helper.layout = Layout( Fieldset(u'<span class="glyphicon glyphicon-pencil"></span> Formato de Inscripción', PrependedText('dni', '#'), 'paterno', 'materno', 'nombre', PrependedText('edad', '#'), 'direccion', PrependedText('email', '@'), PrependedText('fijo', '#'), PrependedText('movil', '#'), 'universidad', 'facultad', 'carrera', 'titulo', 'cargo', 'grado', 'investigacion', ), FormActions( Submit('submit', u'Inscripción'), css_class='text-right' ), )
def __init__(self, *args, **kwargs): super(ProjectFilter, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = False # Layout the form for Bootstrap self.helper.layout = Layout( Div( Row( Column( PrependedText("codename", '<i class="fas fa-filter"></i>'), css_class="form-group col-md-4 mb-0", ), Column("complete", css_class="form-group col-md-4 mb-0"), Column("start_date_range", css_class="form-group col-md-4 mb-0"), ), Row( Column( PrependedText( "start_date", '<i class="fas fa-hourglass-start"></i>'), css_class="form-group col-md-6 mb-0", ), Column( PrependedText( "end_date", '<i class="fas fa-hourglass-end"></i>', ), css_class="form-group col-md-6 mb-0", ), css_class="form-row", ), ButtonHolder( Submit("submit_btn", "Filter", css_class="btn btn-primary col-md-2"), HTML(""" <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'rolodex:projects' %}">Reset</a> """), ), css_class="justify-content-center", ), )
def __init__(self): super(ReminderEditForm, self).__init__() self.form_helper = FormHelper() self.form_helper.form_tag = False self.form_helper.layout = Layout( 'id', PrependedText('balance', '£'), AppendedText('rate', '%'), )
def __init__(self, *args, **kwargs): super(EventForm, self).__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.layout = Layout( Field('title'), Field('description'), PrependedText('date_start', '<i class="fa fa-calendar"></i>', css_class="dateinput"), PrependedText('date_end', '<i class="fa fa-calendar"></i>', css_class="dateinput"), Field('display_override', title="Display"), Field('track_rsvp', title="Enable RSVP"), FormActions( Submit('save', 'Save changes'), HTML( '<a class="btn" href={% url "event_list" %}>Cancel</a>'), ) )
def __init__(self, *args, **kwargs): super(PessoasEnvolvidasAgendaForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.add_input(Submit('submit', 'gravar')) self.helper.add_input( Submit( 'cancel', 'Cancelar', css_class='btn-danger', formnovalidate='formnovalidate', )) self.helper.layout = Layout( Field('nome'), Field(PrependedText( 'telefone', '<i class="glyphicon glyphicon-earphone"></i>'), help_text='teste'), Field(PrependedText('email', '@')), Field('funcionario'))
def __init__(self, request, *args, **kwargs): self.request = request self.helper = FormHelper() self.helper.form_show_labels = False self.helper.form_tag = False self.helper.layout = Layout( PrependedText('email', '<i class="fas fa-user-circle text-info"></i>', active=True, css_class="rounded-0"), ) super(GuestForm, self).__init__(*args, **kwargs)
def __init__(self, *args, editing='', collect_ing, **kwargs): super(RecipeForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_show_labels = False self.helper.form_tag = False self.collect_ing = collect_ing self.editing = editing self.helper.layout = Layout( Field(PrependedText('servings', 'Number of servings:')))
def test_select_prepended(): form = InputsFrom() form.helper = FormHelper() form.helper.layout = Layout( PrependedText("select_input", "bar"), AppendedText("select_input", "bar"), PrependedAppendedText("select_input", "£", ".00"), ) assert parse_form(form) == parse_expected("test_prepended_appended_select.html")
def __init__(self, *args, **kwargs): from .views import StockLevelsView domain = kwargs.pop('domain') self.helper = FormHelper() self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-sm-3 col-md-4 col-lg-2' self.helper.field_class = 'col-sm-4 col-md-5 col-lg-3' self.helper.layout = Layout( Fieldset( _('Stock Levels'), 'stock_emergency_level', 'stock_understock_threshold', 'stock_overstock_threshold' ) if not LOCATION_TYPE_STOCK_RATES.enabled(domain) else None, Fieldset( _('Consumption Settings'), PrependedText('use_auto_consumption', ''), 'consumption_min_transactions', 'consumption_min_window', 'consumption_optimal_window', PrependedText('individual_consumption_defaults', ''), ), Fieldset( _('Phone Settings'), PrependedText('sync_consumption_fixtures', ''), ), hqcrispy.FormActions( ButtonHolder( Submit('submit', ugettext_lazy('Submit')) ) ) ) from corehq.apps.locations.views import LocationImportView url = reverse( LocationImportView.urlname, args=[domain] ) forms.Form.__init__(self, *args, **kwargs) self.fields['individual_consumption_defaults'].help_text = _( "This is configured by <a href='{url}'>bulk importing your organization structure</a>." ).format(url=url)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper.label_class = "col-lg-3" self.helper.field_class = "col-lg-9" self.helper.layout = Layout( "first_name", "last_name", PrependedText("username", '<i class="fa fa-user"></i>'), PrependedText("email", "@"), PrependedText("password1", '<i class="fa fa-key"></i>', type="password"), PrependedText("password2", '<i class="fa fa-key"></i>', type="password"), "giodo", ) self.helper.add_input( Submit("signup", _("Signup"), css_class="btn-primary"))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.error_text_inline = False self.helper.help_text_inline = False self.helper.layout = Layout( PrependedText('profile_URL', 'furry.nz/directory/'), Submit('create', 'Create Profile'), )
def __init__(self, *args, **kwargs): super(SignupForm, self).__init__(*args, **kwargs) self.helper.label_class = 'col-lg-3' self.helper.field_class = 'col-lg-9' self.helper.layout = Layout( 'first_name', 'last_name', PrependedText('username', '<i class="fa fa-user"></i>'), PrependedText('email', '@'), PrependedText('password1', '<i class="fa fa-key"></i>', type='password'), PrependedText('password2', '<i class="fa fa-key"></i>', type='password'), 'giodo', ) self.helper.add_input( Submit('signup', _('Signup'), css_class="btn-primary"))
def __init__(self, *args, **kwargs): super(ChildForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-lg-2' self.helper.field_class = 'col-lg-8' self.helper.layout = Layout( Fieldset( 'ID', PrependedText('child_id', 'ID'), PrependedText('babylab_id', 'B'), PrependedText('kid_neurolab_id', 'K'), ), Fieldset( 'Demographics', 'name_first_text', 'name_last_text', 'gender_type', 'dob_date', UneditableField('age'), 'ethnicity', 'race', Field('family', type='hidden'), ), Fieldset( 'Medical', 'handedness', 'fmri', 'fmri_date', 'dob_early', 'disability', 'disability_notes', ), Fieldset( 'Misc', 'breastfed', 'breastfeeding_duration', 'bottle_fed', 'notes', ), SubmitCommonLayout() ) self.helper.form_tag = True
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.add_input(Submit('submit', 'Filter')) self.helper.layout = Layout( Div( Div(PrependedText('name', 'Name like'), css_class='col-md-4'), Div(PrependedText('source_group', 'Discovered by'), css_class='col-md-4'), Div('in_tess', css_class='col-md-4'), css_class='form-row' ), Div( Div(PrependedText('disc_mag', 'Discovery mag brighter than', placeholder='19'), css_class='col-md-6'), Div(PrependedAppendedText('lnd_jd', 'Last non-detection within the last', 'days', placeholder='5'), css_class='col-md-6'), css_class='form-row' ), )
def __init__(self, request, *args, **kwargs): self.request = request self.helper = FormHelper() self.helper.form_show_labels = False self.helper.form_tag = False self.helper.layout = Layout( PrependedText('email', '<i class="fas fa-user-circle text-info"></i>', active=True, css_class="rounded-0"), PrependedAppendedText('password', '<i class="fas fa-key text-info"></i>', '<button type="button" @click="passwordshow($event)" class="btn btn-sm bg-transparent remove-outline p-0"><i class="fas fa-eye-slash text-info"></i></button>', active=True, css_class="rounded-0 border-right-0"), ) super(LoginForm, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['proposal'] = forms.ChoiceField( choices=self.proposal_choices(), initial='SOAR2022A-002') self.fields['instrument_type'] = forms.ChoiceField( choices=self.instrument_choices(), initial='SOAR_GHTS_REDCAM', label='') self.fields['grating'] = forms.ChoiceField( choices=self.grating_choices(), initial='400_SYGY', label='') self.fields['filter'] = forms.ChoiceField( choices=list(self.filter_choices()), initial=list(self.filter_choices())[0][0], label='') self.fields['readout'] = forms.ChoiceField( choices=self.readout_choices(), initial='GHTS_R_400m1_2x2', label='') for field_name in ['start', 'end', 'name', 'groups']: self.fields[field_name].widget = forms.HiddenInput() self.helper.layout = Layout( self.common_layout, Div( Div(HTML("<p></p>"), PrependedAppendedText('window', 'Once in the next', 'days'), Div(Column('delay_start'), Column(AppendedText('delay_amount', 'days')), css_class='form_row'), PrependedText('exposure_time', 'Exposure Time'), PrependedText('exposure_count', 'Exposure Count'), PrependedText('rotator_angle', 'Rotator Angle'), PrependedText('instrument_type', 'Camera'), PrependedText('grating', 'Grating'), PrependedText('filter', 'Slit Width'), PrependedText('readout', 'Readout Mode'), css_class='col'), Div(HTML("<p></p>"), PrependedText('max_airmass', 'Airmass <'), PrependedText('ipp_value', 'IPP'), 'proposal', 'observation_mode', css_class='col'), css_class='form-row', ), self.button_layout())