Python crispy_forms.layout.Layout() Examples

The following are 30 code examples of crispy_forms.layout.Layout(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module crispy_forms.layout , or try the search function .
Example #1
Source File: forms.py    From tom_base with GNU General Public License v3.0 7 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_action = reverse('tom_observations:add-existing')
        self.helper.layout = Layout(
            'target_id',
            'confirm',
            Row(
                Column(
                    'facility'
                ),
                Column(
                    'observation_id'
                ),
                Column(
                    ButtonHolder(
                        Submit('submit', 'Add Existing Observation')
                    )
                )
            )
        ) 
Example #2
Source File: views.py    From tom_base with GNU General Public License v3.0 6 votes vote down vote up
def get_form(self):
        form = super().get_form()
        form.fields['facility'].widget = forms.HiddenInput()
        form.fields['observation_id'].widget = forms.HiddenInput()
        if self.request.method == 'GET':
            target_id = self.request.GET.get('target_id')
        elif self.request.method == 'POST':
            target_id = self.request.POST.get('target_id')
        cancel_url = reverse('home')
        if target_id:
            cancel_url = reverse('tom_targets:detail', kwargs={'pk': target_id})
        form.helper.layout = Layout(
            HTML('''<p>An observation record already exists in your TOM for this combination of observation ID,
                 facility, and target. Are you sure you want to create this record?</p>'''),
            'target_id',
            'facility',
            'observation_id',
            'confirm',
            FormActions(
                Submit('confirm', 'Confirm'),
                HTML(f'<a class="btn btn-outline-primary" href={cancel_url}>Cancel</a>')
            )
        )
        return form 
Example #3
Source File: forms.py    From sfm-ui with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.collection = kwargs.pop("collection", None)
        super(BaseBulkSeedForm, self).__init__(*args, **kwargs)
        self.fields['history_note'].help_text = HISTORY_NOTE_HELP_ADD
        cancel_url = reverse('collection_detail', args=[self.collection])
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Fieldset(
                '',
                'seeds_type',
                'tokens',
                'history_note',
                css_class='crispy-form-custom'
            ),
            FormActions(
                Submit('submit', 'Save'),
                Button('cancel', 'Cancel',
                       onclick="window.location.href='{0}'".format(cancel_url))
            )
        ) 
Example #4
Source File: forms.py    From happinesspackets with Apache License 2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(MessageRecipientForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-md-3'
        self.helper.field_class = 'col-md-8'

        self.fields['recipient_approved_public'].label = "I agree to publish this message and display it publicly in the Happiness Archive."
        self.fields['recipient_approved_public_named'].label = "... and I agree to display our names publicly too."
        self.fields['recipient_approved_public_named'].help_text = "Note: We only publish information if both the sender and the recipients agree."

        self.helper.layout = Layout(
            Fieldset("Privacy and permissions", 'recipient_approved_public', 'recipient_approved_public_named'),
            HTML("<br>"),
            Submit('submit', 'Save privacy choices', css_class='btn-lg centered'),
        ) 
Example #5
Source File: forms.py    From sfm-ui with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(UserProfileForm, self).__init__(*args, **kwargs)
        # set up crispy forms helper
        self.helper = FormHelper(self)
        # set up crispy forms helper
        self.helper.layout = Layout(
            Fieldset(
                '',
                'username',
                'email',
                'email_frequency',
                'harvest_notifications',
                Div(),
                css_class='crispy-form-custom'
            ),
            FormActions(
                Submit('submit', 'Save'),
                Button('cancel', 'Cancel', onclick="window.history.back()")
            )
        ) 
Example #6
Source File: filterset.py    From Dailyfresh-B2C with Apache License 2.0 6 votes vote down vote up
def form(self):
        form = super(FilterSet, self).form

        if compat.is_crispy():
            from crispy_forms.helper import FormHelper
            from crispy_forms.layout import Layout, Submit

            layout_components = list(form.fields.keys()) + [
                Submit('', _('Submit'), css_class='btn-default'),
            ]
            helper = FormHelper()
            helper.form_method = 'GET'
            helper.template_pack = 'bootstrap3'
            helper.layout = Layout(*layout_components)

            form.helper = helper

        return form 
Example #7
Source File: lco.py    From tom_base with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for field_name in ['groups', 'target_id']:
            self.fields.pop(field_name, None)
        for field in self.fields:
            if field != 'strategy_name':
                self.fields[field].required = False
        self.helper.layout = Layout(
            self.common_layout,
            Div(
                Div(
                    'proposal', 'ipp_value', 'filter', 'instrument_type',
                    css_class='col'
                ),
                Div(
                    'exposure_count', 'exposure_time', 'max_airmass',
                    css_class='col'
                ),
                css_class='form-row',
            )
        ) 
Example #8
Source File: forms.py    From osler with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):

        super(ActionItemForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)

        self.helper.layout = Layout(
            Row(
                Column(css_class='form-group col-md-3 col-xs-4'),
                Column('due_date', css_class='form-group col-md-3 col-xs-4'),
                Column('instruction', css_class='form-group col-md-3 col-xs-4'),
                css_class='form-row'
            ),
            Row(
                Column(css_class='form-group col-md-3 col-xs-4'),
                Column('comments', css_class='form-group col-md-6 col-xs-6')
            ),
            CustomCheckbox('priority'),
            Row(
                Column(Submit('submit', 'Submit'),
                    css_class='formgroup col-md-offset-3 col-xs-offset-4')
            )
        )

        self.fields['instruction'].queryset = models.ActionInstruction.objects.filter(
            active=True) 
Example #9
Source File: forms.py    From osler with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(DemographicsForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_method = 'post'

        self.helper.layout = Layout(
                Fieldset('Medical',
                         'has_insurance',
                         'ER_visit_last_year',
                         'last_date_physician_visit',
                         'chronic_condition'),
                Fieldset('Social',
                         'lives_alone',
                         'dependents',
                         'resource_access',
                         'transportation'),
                Fieldset('Employment',
                         'currently_employed',
                         'education_level',
                         'work_status',
                         'annual_income')
        )

        self.helper.add_input(Submit('submit', 'Submit')) 
Example #10
Source File: forms.py    From conf_site with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        self.user = kwargs.pop("user")
        kwargs.update(
            {
                "initial": {
                    "contact_name": self.user.get_full_name,
                    "contact_email": self.user.email,
                }
            }
        )
        super(SponsorApplicationForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.field_class = "col-sm-10 col-lg-10"
        self.helper.form_tag = False
        self.helper.label_class = "col-sm-2 col-lg-2"
        self.helper.layout = Layout(
            "name",
            "external_url",
            "contact_name",
            "contact_email",
            "level",
        ) 
Example #11
Source File: forms.py    From TWLight with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(SuggestionForm, self).__init__(*args, **kwargs)
        # Translators: This labels a textfield where users can enter the name of the potential partner they'll suggest
        self.fields["suggested_company_name"].label = _("Name of the potential partner")
        # Translators: This labels a textfield where users can enter the description of the potential partner they'll suggest
        self.fields["description"].label = _("Description")
        # Translators: This labels a textfield where users can enter the website URL of the potential partner they'll suggest
        self.fields["company_url"].label = _("Website")
        # @TODO: This sort of gets repeated in PartnerSuggestionView.
        # We could probably be factored out to a common place for DRYness.
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.form_class = "form-horizontal"
        self.helper.label_class = "col-lg-3"
        self.helper.field_class = "col-lg-7"
        self.helper.layout = Layout(
            "suggested_company_name",
            "description",
            "company_url",
            "next",
            # Translators: This labels a button which users click to submit their suggestion.
            Submit("submit", _("Submit"), css_class="center-block"),
        ) 
Example #12
Source File: forms.py    From tom_base with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_action = reverse('tom_observations:update', kwargs={'pk': self.initial.get('obsr_id')})
        self.helper.layout = Layout(
            'obsr_id',
            Row(
                Column(
                    'observation_id'
                ),
                Column(
                    ButtonHolder(
                        Submit('submit', 'Update Observation Id')
                    ),
                )
            )
        ) 
Example #13
Source File: forms.py    From advanced-crispy-forms-examples with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Row(
                Column('email', css_class='form-group col-md-6 mb-0'),
                Column('password', css_class='form-group col-md-6 mb-0'),
                css_class='form-row'
            ),
            'address_1',
            'address_2',
            Row(
                Column('city', css_class='form-group col-md-6 mb-0'),
                Column('state', css_class='form-group col-md-4 mb-0'),
                Column('zip_code', css_class='form-group col-md-2 mb-0'),
                css_class='form-row'
            ),
            CustomCheckbox('check_me_out'),
            Submit('submit', 'Sign in')
        ) 
Example #14
Source File: compact.py    From DCRM with GNU Affero General Public License v3.0 6 votes vote down vote up
def helper(self):
        # As extra service, auto-adjust the layout based on the project settings.
        # This allows defining the top-row, and still get either 2 or 3 columns
        compact_fields = [name for name in self.fields.keys() if name in self.top_row_fields]
        other_fields = [name for name in self.fields.keys() if name not in self.top_row_fields]
        col_size = int(self.top_row_columns / len(compact_fields))
        col_class = self.top_column_class.format(size=col_size)

        compact_row = Row(*[Column(name, css_class=col_class) for name in compact_fields])

        # The fields are already ordered by the AbstractCommentForm.__init__ method.
        # See where the compact row should be.
        pos = list(self.fields.keys()).index(compact_fields[0])
        new_fields = other_fields
        new_fields.insert(pos, compact_row)

        helper = CompactLabelsCommentFormHelper()
        helper.layout = Layout(*new_fields)
        helper.add_input(SubmitButton())
        helper.add_input(PreviewButton())
        return helper 
Example #15
Source File: forms.py    From swarfarm with Apache License 2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(IssueForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.form_method = 'post'
        self.helper.form_action = 'feedback:issue_add'
        self.helper.layout = Layout(
            Div(
                Field('subject'),
                Field('description', data_provide='markdown'),
                Field('public'),
                Field('captcha'),
            ),
            Div(
                FormActions(
                    Submit('save', 'Save', css_class='btn btn-primary'),
                ),
            )
        ) 
Example #16
Source File: forms.py    From django-leonardo with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(PageMassChangeForm, self).__init__(*args, **kwargs)

        color_scheme_fields = self.init_color_scheme_switch(
            color_scheme=kwargs['initial'].get('color_scheme', None),
            field_kwargs={'widget': Select2Widget})

        self.helper.layout = Layout(
            TabHolder(
                Tab(_('Options'),
                    'depth',
                    'page_id',
                    'from_root',
                    'site',
                    'language',
                    ),
                Tab(_('Styles'),
                    'layout',
                    Fieldset(
                        'Themes', 'theme', *color_scheme_fields),
                    ),
            ),
        ) 
Example #17
Source File: forms.py    From advanced-crispy-forms-examples with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Row(
                Column('email', css_class='form-group col-md-6 mb-0'),
                Column('password', css_class='form-group col-md-6 mb-0'),
                css_class='form-row'
            ),
            'address_1',
            'address_2',
            Row(
                Column('city', css_class='form-group col-md-6 mb-0'),
                Column('state', css_class='form-group col-md-4 mb-0'),
                Column('zip_code', css_class='form-group col-md-2 mb-0'),
                css_class='form-row'
            ),
            'check_me_out',
            Submit('submit', 'Sign in')
        ) 
Example #18
Source File: forms.py    From oxidizr with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(KeywordCreateForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id_form_keywords_create'
        self.helper.layout = Layout(
            Div(
                Div(
                    'term',
                    css_class='col-sm-6 col-sm-offset-3'
                ),
                css_class='row'
            ),
            HTML('''<hr class="full">'''),
            Div(
                Div(
                    HTML('''<a href="{% url 'keywords_manage' %}">{{ _('Cancel') }}</a>&nbsp;&nbsp;'''),
                    Submit('submit', _('Save'), css_class='btn-success btn-lg'),
                    css_class='pull-right'
                ),
                css_class='row',
            )
        ) 
Example #19
Source File: forms.py    From oxidizr with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(ResetPasswordForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id_form_reset_password'
        self.helper.layout = Layout(
            Div(
                'verification_code',
                'password',
                'repeat_password',
            ),
            HTML('''<hr class="full">'''),
            Div(
                Div(
                    HTML('''<a href="{% url 'accounts_login' %}"> {{ _('Cancel and login') }}</a>&nbsp;&nbsp;'''),
                    Submit('submit', _('Reset password'), css_class='btn-success btn-lg'),
                    css_class='pull-right'
                )
            )
        ) 
Example #20
Source File: forms.py    From oxidizr with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(ForgotPasswordForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id_form_forgot_password'
        self.helper.layout = Layout(
            Div(
                'email',
            ),
            HTML('''<hr class="full">'''),
            Div(
                Div(
                    HTML('''<a href="{% url 'accounts_login' %}"> {{ _('Cancel and login') }}</a>&nbsp;&nbsp;'''),
                    Submit('submit', _('Continue'), css_class='btn-success btn-lg'),
                    css_class='pull-right'
                )
            )
        ) 
Example #21
Source File: forms.py    From oxidizr with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        self._email_token = kwargs.pop('email_token', None)
        self._verification_code = self._email_token.verification_code
        super(EmailVerificationForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id_form_email_verification'
        self.helper.form_action = reverse_lazy('accounts_email_verification', args=(self._email_token.id,))
        self.helper.layout = Layout(
            Div(
                'code',
            ),
            HTML('''<hr class="full">'''),
            Div(
                Div(
                    HTML('''<a href="{% url 'accounts_register' %}">
                    {{ _('Cancel and sign up again') }}</a>&nbsp;&nbsp;'''),
                    Submit('submit', _('Verify Email address'), css_class='btn-success btn-lg'),
                    css_class='pull-right'
                )
            )
        ) 
Example #22
Source File: forms.py    From django-lb-workflow with MIT License 5 votes vote down vote up
def layout(self):
        self.helper.layout = Layout(
            'q_quick_search_kw',
            StrictButton('Search', type="submit", css_class='btn-sm btn-default'),
            StrictButton('Export', type="submit", name="export", css_class='btn-sm btn-default'),
        ) 
Example #23
Source File: forms.py    From memex-explorer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def set_layout(self):
        """Called in __init__ to register a custom layout."""
        self.helper.layout = Layout(
            Fieldset(None,
                HTML("<p hidden id='file_error' style='color:#990000'></p>"),
                'uploaded_data',
                FormActions(Submit('submit', "Submit"))
            )
        )
        self.helper.form_id="upload_data" 
Example #24
Source File: forms.py    From ontask_b with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.fields['username'].widget.input_type = 'email'  # ugly hack
        self.fields['username'].label = _('Email address')

        self.helper.layout = Layout(
            Field('username', placeholder=_('Enter Email'), autofocus=''),
            Field('password', placeholder=_('Enter Password')),
            Submit('sign_in', _('Log in'),
                   css_class='btn btn-lg btn-outline-primary btn-block'),
            # HTML('<a href="{}">Forgot Password?</a>'.format(
            #    reverse('accounts:password-reset'))),
            Field('remember_me'),
        ) 
Example #25
Source File: forms.py    From ontask_b with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.fields['email'].widget.input_type = 'email'  # ugly hack

        self.helper.layout = Layout(
            Field('email', placeholder='Enter Email', autofocus=''),
            Field('name', placeholder='Enter Full Name'),
            Field('password1', placeholder='Enter Password'),
            Field('password2', placeholder='Re-enter Password'),
            Submit('sign_up', 'Sign up', css_class='btn-warning'),
        ) 
Example #26
Source File: forms.py    From ontask_b with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Field('picture'),
            Field('bio'),
            Submit('update', 'Update', css_class="shadow btn-success"),
        ) 
Example #27
Source File: forms.py    From ontask_b with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.helper.layout = Layout(
            Field('old_password', placeholder='Enter old password',
                  autofocus=''),
            Field('new_password1', placeholder='Enter new password'),
            Field('new_password2', placeholder='Enter new password (again)'),
            Submit('pass_change',
                   'Change Password',
                   css_class='btn-outline-primary'),
        ) 
Example #28
Source File: forms.py    From memex-explorer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def set_layout(self):
        """Called in __init__ to register a custom layout."""
        self.helper.layout = Layout(
            Fieldset(None,
                HTML("<p hidden id='name_error' style='color:#990000'></p>"),
                'name',
                HTML("<p hidden id='file_error' style='color:#990000'></p>"),
                'uploaded_data',
                FormActions(Submit('submit', "Submit"))
            ),
        )
        self.helper.form_id="upload_data" 
Example #29
Source File: forms.py    From ontask_b with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.helper.layout = Layout(
            Field('email', placeholder='Enter email',
                  autofocus=''),
            Submit('pass_reset',
                   'Reset Password',
                   css_class='btn-outline-primary'),
        ) 
Example #30
Source File: forms.py    From memex-explorer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def set_layout(self):
        """Called in __init__ to register a custom layout."""
        self.helper.layout = Layout(
            Fieldset(None,
                'name',
                'description',
                'seeds_list',
                HTML(
                '''
                    <label for="id_textseeds" class="">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Or, paste  urls to crawl.
                    </label>
                    <div class="controls ">
                        <textarea class="textarea form-control"
                            cols="10"
                            id="id_textseeds"
                            name="textseeds"
                            rows="10">
                        </textarea>
                    </div>
                    <br>
                '''
                ),
                InlineRadios('crawler'),
                "rounds_left",
                'crawl_model',
                FormActions(Submit('submit', "Create")),
                HTML(
                """
                    <a class="add_index btn btn-primary link-button"
                        id="cancelSubmit"
                        target="_blank"
                        href="#">
                        Cancel
                    </a>
                """
                ),
            )
        )