def __init__(self, *args, **kwargs): super(RandomItemDrawForm, self).__init__(*args, **kwargs) # Add "protected" class to the input that will be read-only when the draw is shared self.fields['number_of_results'].widget.attrs.update({ 'class': 'protected', 'min': 1 }) self.fields['items'].widget.attrs.update( {'class': 'protected eas-tokenfield'}) self.fields['allow_repeat'].widget.attrs.update({'class': 'protected'}) self.helper.label_class = 'col-xs-6 text-right' self.helper.field_class = 'col-xs-6' self.helper.layout = Layout( Row( HTML( _("<div id='info-comma-separated' class='alert alert-info' role='alert'>Separate items by commas. e.g: Maria, David S, Leo, ...</div>" )), 'items', Row('number_of_results'), 'allow_repeat', ), )
def test_formset_layout(settings): SampleFormSet = formset_factory(SampleForm, extra=3) formset = SampleFormSet() helper = FormHelper() helper.form_id = "thisFormsetRocks" helper.form_class = "formsets-that-rock" helper.form_method = "POST" helper.form_action = "simpleAction" helper.layout = Layout( Fieldset("Item {{ forloop.counter }}", "is_company", "email",), HTML("{% if forloop.first %}Note for first form only{% endif %}"), Row("password1", "password2"), Fieldset("", "first_name", "last_name"), ) html = render_crispy_form(form=formset, helper=helper, context={"csrf_token": _get_new_csrf_string()}) # Check formset fields assert contains_partial(html, '<input id="id_form-TOTAL_FORMS" name="form-TOTAL_FORMS" type="hidden" value="3"/>') assert contains_partial( html, '<input id="id_form-INITIAL_FORMS" name="form-INITIAL_FORMS" type="hidden" value="0"/>' ) assert contains_partial( html, '<input id="id_form-MAX_NUM_FORMS" name="form-MAX_NUM_FORMS" type="hidden" value="1000"/>' ) assert contains_partial( html, '<input id="id_form-MIN_NUM_FORMS" name="form-MIN_NUM_FORMS" type="hidden" value="0"/>' ) assert html.count("hidden") == 5 # Check form structure assert html.count("<form") == 1 assert html.count("csrfmiddlewaretoken") == 1 assert "formsets-that-rock" in html assert 'method="post"' in html assert 'id="thisFormsetRocks"' in html assert 'action="%s"' % reverse("simpleAction") in html # Check form layout assert "Item 1" in html assert "Item 2" in html assert "Item 3" in html assert html.count("Note for first form only") == 1 if settings.CRISPY_TEMPLATE_PACK == "uni_form": assert html.count("formRow") == 3 elif settings.CRISPY_TEMPLATE_PACK in ("bootstrap3", "bootstrap4"): assert html.count("row") == 3 if settings.CRISPY_TEMPLATE_PACK == "bootstrap4": assert html.count("form-group") == 18
def __init__(self, *args, group, **kwargs): super().__init__(*args, group=group, **kwargs) self.instance.group = group self.helper = FormHelper() self.helper.form_tag = False self.helper.disable_csrf = True self.helper.layout = Layout( "title", "event", Row( Div("category", css_class="col-md-4"), Div("category_precisions", css_class="col-md-8"), ), "explanation", Row( Div("amount", css_class="col-md-4"), Div("spending_date", css_class="col-md-8"), ), "provider", "iban", )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = False # self.helper.field_template = 'bootstrap3/layout/inline_field.html' self.helper.layout = Layout( Row( Column('article', css_class='col-md-2'), Column('amount', css_class='col-md-1'), Column('unit', css_class='col-md-1'), Column('price_without_vat', css_class='col-md-2'), Column('vat', css_class='col-md-1'), Column('comment', css_class='col-md-4'), ))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.form_method = 'post' self.layout = Layout( Row(Column('reps', css_class='form-group col-2 mb-0'), Column('repetition_unit', css_class='form-group col-3 mb-0'), Column('weight', css_class='form-group col-2 mb-0'), Column('weight_unit', css_class='form-group col-3 mb-0'), Column('rir', css_class='form-group col-2 mb-0'), css_class='form-row'), ) self.form_show_labels = False self.form_tag = False self.disable_csrf = True self.render_required_fields = True
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Column('date', 'adjusted_by', 'warehouse', css_class="col-sm-6"), Column('comments', css_class="col-sm-6") ) ) self.helper.add_input(Submit('submit', 'Submit'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row(Column("title", css_class="input-group col-md-12"), Column("email", css_class="input-group col-md-12"), Column("content", css_class="input-group col-md-12"), css_class="row mb-0"), HTML("<div class='w-100'></div>", ), Submit( "submit", "Comment", css_class= "btn btn-block text-white block rounded-lg py-3 font-weight-semibold text-uppercase mt-3 button-black" ))
def __init__(self, **kwargs): super().__init__(**kwargs) self.helper = FormHelper() self.helper.layout = Layout( 'description', 'category', 'activity', Row( Column('unit', css_class='col-4'), Column('unit_cost', css_class='col-4'), Column('quantity', css_class='col-4') ) ) self.helper.add_input(Submit('Submit', 'submit'))
def __init__(self, **kwargs): super().__init__(**kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Column('name', css_class='col-6'), Column('start_date', css_class='col-6'), ), 'description', 'estimated_cost', 'project', 'responsible', ) self.helper.add_input(Submit('Submit', 'submit'))
def __init__(self, *args, **kwargs): super(UserForm, self).__init__(*args, **kwargs) self.fields['sourcesystemcreatedby'].disabled = True self.helper = FormHelper() self.helper.form_method = 'POST' self.helper.form_action = 'adduser/' self.helper.layout = Layout( Row(Column('username', css_class='form-group col-md-6 mb-0'), Column('resourcepool', css_class='form-group col-md-6 mb-0'), css_class='form-row'), 'sourcesystemcreatedby', HTML('<br>'), Submit('submit', 'Submit', css_class='btn btn-sm btn-block'), )
def __init__(self, *args, **kwargs): super(ProcessEngineForm, self).__init__(*args, **kwargs) self.fields['sourcesystemcreatedby'].disabled = True self.helper = FormHelper() self.helper.form_method = 'POST' self.helper.form_action = 'addprocessengine/' self.helper.layout = Layout( Row(Column('processhashkey', css_class='form-group col-md-6 mb-0'), Column('enginehashkey', css_class='form-group col-md-6 mb-0'), css_class='form-row'), 'sourcesystemcreatedby', HTML('<br>'), Submit('submit', 'Submit', css_class='btn btn-sm btn-block'), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Column(HTML("<h4>Vehicle Details</h4>"), css_class='col-6'), Column(HTML("<h4>Pesonal Details</h4>"), css_class='col-6'), ), Row( Column('vehicle', 'liter', 'Price_per_litre', 'total_price', 'odometer_Value', css_class='form_group col-md-6'), Column('date', 'purchaser', 'invoice_reference', 'vendor', css_class='form_group col-md-6'), ), ) self.helper.add_input(Submit('submit', "Submit"))
def __init__(self, project=None, *args, **kwargs): super(DomainLinkForm, self).__init__(*args, **kwargs) if project: self.fields[ "static_server"].queryset = ServerHistory.objects.filter( project=project) self.fields[ "transient_server"].queryset = TransientServer.objects.filter( project=project) for field in self.fields: self.fields[field].widget.attrs["autocomplete"] = "off" self.fields["domain"].queryset = History.objects.filter( project=project) self.fields["domain"].empty_label = "-- Select a Domain [Required] --" self.fields["static_server"].empty_label = "-- Select Static Server --" self.fields["transient_server"].empty_label = "-- Select VPS --" self.helper = FormHelper() self.helper.form_method = "post" self.helper.form_class = "newitem" self.helper.form_show_errors = False self.helper.form_show_labels = False self.helper.layout = Layout( HTML(""" <p>First, select a domain checked-out for this project:</p> """), "domain", HTML(""" <p>Then set your subdomain (or "*" for a wildcard) and CDN endpoint (if any) used with this link:</p> """), "subdomain", "endpoint", HTML(""" <p>Finally, select either a static server checked-out for this project <em>or</em> a transient server to associate with the selected domain:</p> """), Row( Column("static_server", css_class="form-group col-md-6 mb-0"), Column("transient_server", css_class="form-group col-md-6 mb-0"), css_class="form-row", ), "project", ButtonHolder( Submit("submit", "Submit", css_class="btn btn-primary col-md-4"), HTML(""" <button onclick="window.location.href='{{ cancel_link }}'" class="btn btn-outline-secondary col-md-4" type="button">Cancel</button> """), ), )
def __init__(self, *args, **kwargs): super(TagObservationForm, self).__init__(*args, **kwargs) formtag_prefix = re.sub('-[0-9]+$', '', kwargs.get('prefix', '')) self.helper = FormHelper() self.helper.form_tag = False self.fields['name'].help_text = None self.helper.layout = Layout( Row( Field('name'), Field('tag_location'), Field('DELETE', type='hidden'), css_class='formset_row-{}'.format(formtag_prefix) ) )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.form_class = 'form-horizontal' self.label_class = "col-sm-2" self.field_class = "col-sm-5" self.layout = Layout( Fieldset( '{{ order }}', 'customer', 'pindex', Row( Column(HTML(_('city').capitalize()), css_class="col-sm-2"), Column(HTML("{{ order.customer.city.city }}"), css_id="city", css_class="col-sm-5")), Row( Column(HTML(_('address').capitalize()), css_class="col-sm-2"), Column(HTML("{{ order.customer.address }}"), css_id="customer_address", css_class="col-sm-5")), 'delivery_type', 'address'), HTML( "{% load crispy_forms_tags %} {% crispy order_items order_items_formset_helper %}" ), Submit('submit', _('save').title()))
def __init__(self, *args, **kwargs): super(ChoicesForm, self).__init__(*args, **kwargs) self.fields['choice_text'].label = "Nueva Respuesta: " self.fields['is_correct_answer'].label = "¿Es respuesta correcta?" self.helper = FormHelper() self.helper.form_show_labels = True self.helper.form_tag = False self.helper.form_action = "post_question" self.form_method = 'POST' self.helper.layout = Layout( Row(Column('choice_text', css_class=" mb-2 mr-sm-2"), Column('is_correct_answer', css_class='custom-control custom-radio'), css_class='row'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row(Column('title', css_class='form-group col-md-2 mb-0'), Column('name', css_class='form-group col-md-5 mb-0'), Column('surname', css_class='form-group col-md-5 mb-0'), css_class='form-row'), 'photo', # HTML('{% if form.photo.value %}<img class="img-responsive" src="{{ MEDIA_URL }}{{ form.photo.value }}">{% endif %}'), 'address', Row(Column('country', css_class='form-group col-md-6 mb-0'), Column('language', css_class='form-group col-md-6 mb-0'), css_class='form-row'), 'email', # Field('email', readonly=kwargs[]), Row(Column('mobile', css_class='form-group col-md-6 mb-0'), Column('telephone', css_class='form-group col-md-6 mb-0'), css_class='form-row'), 'remarks', Submit('submit', 'Submit', css_class='btn-success btn-lg btn-block'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['email'].widget.attrs.update({ 'autofocus': 'autofocus', 'placeholder': _('Email') }) self.helper = FormHelper() self.helper.layout = Layout( 'email', Row(Column('first_name', css_class='form-group col-md-6 mb-0'), Column('last_name', css_class='form-group col-md-6 mb-0'), css_class='form-row'), Row(Column('password1', css_class='form-group col-md-6 mb-0'), Column('password2', css_class='form-group col-md-6 mb-0'), css_class='form-row'), Row(Column('phone_number', css_class='form-group col-md-4 mb-0'), Column('birth_day', css_class='form-group col-md-4 mb-0'), Column('gender', css_class='form-group col-md-4 mb-0'), css_class='form-row'), Row( Column('address', css_class='form-group col-md-6 mb-0'), Column('country', css_class='form-group col-md-6 mb-0'), ), 'health_condition', Submit('submit', _('Save')))
def __init__(self, **kwargs): super().__init__(**kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Column( Row( Column('date', css_class='col-6'), Column('due', css_class='col-6'), ), 'vendor',css_class='col-6'), Column('reference', 'warehouse', 'paid_in_full', css_class='col-6') ), 'memo', 'data', HTML(""" <div id='purchase-table'></div> {% load render_bundle from webpack_loader %} {% render_bundle 'inventory' %} """) ) self.helper.add_input(Submit('submit', 'Submit'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.attrs = {'novalidate': ''} self.helper.form_class = 'form-horizontal' self.helper.layout = Layout( Row(Column('category', css_class='form-group col-md-3 mb-0'), Column('warehouse', css_class='form-group col-md-2 mb-0'), Column('forecast_date', css_class='form-group col-md-2 mb-0'), Column('forecasted_quantity', css_class='form-group col-md-3 mb-0'), css_class='form-row'), Submit('submit', _('Submit')))
def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) self.object = kwargs.pop('object', None) super(VacunacionForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Div(Field('motivo', placeholder='Ingrese el motivo de vacunación'), css_class='col-md-12'), Div(Field('vacuna',), css_class='col-md-12'), Div(Field('observacion', placeholder='Ingrese un la nota'), css_class='col-md-12'), ), Div(Row( FormActions( smtSave(), btnCancel(), btnReset(), ), ),), )
def __init__(self, *args, **kwargs): super(SessionForm, self).__init__(*args, **kwargs) self.fields['description'].widget.attrs['rows'] = 2 self.helper = FormHelper(self) self.helper.layout = Layout( Row(Column('title', css_class='form-group col-md-4 mb-0'), Column('seed_query', css_class='form-group col-md-8 mb-0'), css_class='form-row'), 'description', Row(Column('max_number_of_judgments', css_class='form-group col-md-6 mb-0'), Column('strategy', css_class='form-group col-md-6 mb-0'), css_class='form-row'), Div(Field('show_full_document_content'), css_class='d-none', css_id="topic-show_full_document_content"), StrictButton(u'Create session', name=self.submit_name, type="submit", css_class='btn btn-outline-secondary') # Alternative to StrictButton # Submit(self.submit_name, u'Create topic and start judging', # css_class='btn') )
def __init__(self, *args, **kwargs): super(PatientForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.use_custom_control = True self.helper.layout = Layout( 'image', Row( Column('first_name', css_class='form-group col-md-6 mb-0'), Column('last_name', css_class='form-group col-md-6 mb-0'), ), Row( Column('address', css_class='form-group col-md-6 mb-0'), Column('street_address', css_class='form-group col-md-6 mb-0'), ), Row( Column('city', css_class='form-group col-md-4 mb-0'), Column('state', css_class='form-group col-md-4 mb-0'), Column('phone', css_class='form-group col-md-4 mb-0'), ), 'email', InlineRadios('gender'), Submit('submit', 'Save', css_class='btn btn-block btn-primary') )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper self.helper.form_method = 'post' self.helper.form_action = 'criar-transacao' self.helper.layout = Layout( 'valor', Row(Column('recebedor_1_id', css_class='form-group col-md-6 mb-0'), Column('recebedor_1_valor', css_class='form-group col-md-6 mb-0'), css_class='form-row'), Row(Column('recebedor_2_id', css_class='form-group col-md-6 mb-0'), Column('recebedor_2_valor', css_class='form-group col-md-6 mb-0'), css_class='form-row'), Row( Column(Submit( 'submit', 'Realizar transação', css_class='d-inline-block px-4 mb-2 py-2 btn-primary'), css_class='form-group col-md-12 mb-0 text-center')))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( HTML( "<h3>Facility Form </h3>" ), Row( Column(HTML('<h4>Basic</h4>'),css_class='col-6'), Column(HTML("<h4>Area Detail</h4>"), css_class='col-6'), ), Row( Column('facility_name', 'address', 'primary_purpose', css_class='form-group col-md-6'), Column('floor_area', 'site_area', css_class='form-group col-md-6') ), Row( Column('length', css_class='form-group col-md-4'), Column('width', css_class='form-group col-md-4'), Column('height', css_class='form-group col-md-4'), ), 'description', ) self.helper.add_input(Submit('submit', "Submit"))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( Row( Column('received_by', 'receive_date', 'order', 'warehouse', css_class="col-sm-6"), Column('note', css_class="col-sm-6"))) self.helper.add_input(Submit('submit', 'Submit'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( 'username', 'email', 'Gender', Row( Column('password1', css_class='form-group col-md-6 mb-0'), Column('password2', css_class='form-group col-md-6 mb-0'), css_class='form-row' ), Submit('submit', 'Register') )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_action = reverse_lazy('girvi_loan_create') self.helper.attrs = { 'hx-post': reverse_lazy('girvi_loan_create'), 'hx-target': '#loancontent', 'hx-swap': 'innerHTML', 'hx-push-url': 'true', } self.helper.layout = Layout( Row(Column('series', css_class='form-group col-md-3 mb-0'), Column('lid', css_class='form-group col-md-3 mb-0'), Column('created', css_class='form-group col-md-3 mb-0'), css_class='form-row'), Row(Column('customer', css_class='form-group col-md-3 mb-0'), Column('itemtype', css_class='form-group col-md-3 mb-0'), Column('interestrate', css_class='form-group col-md-3 mb-0'), css_class='form-row'), Row(Column('itemweight', css_class='form-group col-md-3 mb-0'), Column('loanamount', css_class='form-group col-md-3 mb-0'), Column('itemdesc', css_class='form-group col-md-3 mb-0'), css_class='form-row'), Submit('submit', 'Submit'))
def __init__(self, *args, **kwargs): super(AddWellForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( HTML('<h2>General well info</h2>'), Row(Column('network', css_class='form-group col-md-3 mb-0'), Column('name', css_class='form-group col-md-3 mb-0'), Column('date', css_class='form-group col-md-2 mb-0'), css_class='form-row'), HTML('<h2>Coordinates</h2>'), Row(Column('srid', css_class='form-group col-md-3 mb-0'), Column('xcoord', css_class='form-group col-md-2 mb-0'), Column('ycoord', css_class='form-group col-md-2 mb-0'), Column('zcoord', css_class='form-group col-md-2 mb-0'), css_class='form-row'), HTML('<h2>Casing and screen info</h2>'), Row(Column('refpnt', css_class='form-group col-md-2 mb-0'), Column('depth', css_class='form-group col-md-2 mb-0'), Column('top', css_class='form-group col-md-2 mb-0'), Column('bottom', css_class='form-group col-md-2 mb-0'), css_class='form-row'), HTML('<h2>Logger info</h2>'), Row(Column('logger_type', css_class='form-group col-md-4 mb-0'), Column('serial', css_class='form-group col-md-2 mb-0'), Column('logger_depth', css_class='form-group col-md-2 mb-0'), css_class='form-row'), Submit('submit', 'Submit'))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['end_date'].required = False self.fields['start_date'].required = False self.helper = FormHelper() self.helper.form_tag = False self.helper.layout = Layout( Row( Column( HTML('<p>{{ concept.description_short }}</p>'), css_class='col', ), ), )