Esempio n. 1
0
File: forms.py Progetto: audax/pypo
    def __init__(self, *args, **kwargs):
        h = FormHelper()
        h.form_id = 'user-profile-form'
        h.form_class = 'form-horizontal'
        h.label_class = 'col-lg-2'
        h.field_class = 'col-lg-4'
        h.layout = layout.Layout(
            'theme',
            'new_window',
            'items_per_page',
            'excluded_tags',
            'show_excluded',
            layout.Div(
                layout.Div(
                    layout.Submit('Save', value='Save', css_class='btn-default'),
                    css_class='col-lg-offset-2 col-lg-4'
                ),
                css_class='form-group',
            )
        )
        h.help_text_inline = True
        h.error_text_inline = True
        h.html5_required = True

        self.helper = h
        super(UserProfileForm, self).__init__(*args, **kwargs)
Esempio n. 2
0
def inline_catalog_helper(instance=None, form_tag=True):
    """
    Form helper to create a new catalog
    """
    helper = FormHelper()
    helper.form_action = '.'
    helper.form_class = "hide-label"
    helper.attrs = {'data_abide': ''}
    helper.form_tag = form_tag
    
    # Build the full layout
    helper.layout = Layout(
        Row(
            Field(
                'locale', 
                placeholder=_("Type a locale like 'fr'"), 
                wrapper_class='small-10 columns'
            ),
            Column(
                Submit(
                    'submit',
                    _('Create'),
                    css_class='postfix',
                ),
                css_class='small-2'
            ),
            css_class='collapse postfix-radius',
        )
    )
    
    return helper
Esempio n. 3
0
def get_formhelper():
    """Get the default formhelper for seeddb forms"""
    helper = FormHelper()
    helper.form_action = ''
    helper.form_method = 'GET'
    helper.form_class = 'custom'
    return helper
Esempio n. 4
0
def quiz_form_helper(quiz, form_to_use=None, select_to_radio=False):
    if form_to_use:
        form = form_to_use
    else:
        form = make_quiz_form(quiz, select_to_radio)
    helper = FormHelper()
    helper.form_id = 'quiz-{}-form'.format(quiz.id)
    helper.form_class = 'form quiz_form quiz-{}'.format(quiz.id)
    helper.form_method = 'post'
    helper.html5_required = True
    helper.render_required_fields = True
    helper.layout = Layout(*form.base_fields.keys())
    if quiz.use_categories:
        #  use fieldsets to separate question categories
        categories = Category.objects.filter(question__quiz=quiz).distinct()
        quiz_cats = {'answer_{}'.format(x.id): x.category for x in quiz.get_questions()}
        layout_items = []
        for cat in categories:
            fieldset_items = [cat.title]
            for answer_field in form.base_fields.keys():
                if quiz_cats[answer_field] == cat:
                    fieldset_items.append(answer_field)
            layout_items.append(Fieldset(*fieldset_items))
        helper.layout = Layout(*layout_items)
    if select_to_radio or quiz.question_widget == quiz.RADIO_WIDGET:
        helper.all().wrap(Field, css_class="question-field",
                          template="answers/bootstrap3/multichoice_radio_field.html")
    else:
        helper.all().wrap(Field, css_class="question-field")
    helper.add_input(Submit('submit', _('Submit'), css_class='btn-success btn-block btn-lg'))
    return helper
Esempio n. 5
0
def make_site_filter_form_helper():
    helper = FormHelper()
    helper.form_action = reverse_lazy('sites')
    helper.form_class = 'form-horizontal'
    helper.form_method = 'post'
    helper.layout = Layout(
        Fieldset(
            '',
            # 'Filter displayed sites',
            Field('location'),
            FormActions(
                HTML(
                    '<button class="btn btn-warning form-submit" '
                    'data-dismiss="modal" aria-hidden="true">'
                    '<i class="icon-filter"></i> Filter</button>'
                ),
                HTML(
                    '<a class="btn form-reset" data-dismiss="modal" '
                    'aria-hidden="true">Reset</a>'
                ),
            )
        )
    )

    return helper
Esempio n. 6
0
    def __init__(self, *args, **kwargs):
        super(AuthenticationForm, self).__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_class = "form-inline"
        helper.add_input(Submit("submit", "Login"))
        self.helper = helper
Esempio n. 7
0
    def helper(self):
        helper = FormHelper()
        helper.form_class = 'form-horizontal datacenter-search-form'
        helper.label_class = 'col-lg-4'
        # self.helper.field_template = 'bootstrap3/layout/inline_field.html'
        helper.field_class = 'col-lg-8'
        wc = 'form-group-sm col-lg-6 col-md-6 col-sm-12 row'
        helper.wrapper_class = wc
        helper.form_method = 'get'

        helper.layout = Layout(

                Div(Fieldset(_('Search Projects'),
                             Field('name', wrapper_class=wc),
                             Field('act', css_class="", wrapper_class=wc),
                             Field('inv', css_class="", wrapper_class=wc),
                             Field('ben', css_class="", wrapper_class=wc),
                             Field('inactive', css_class="", wrapper_class=wc),
                             Field('status', css_class="", wrapper_class=wc),
                             Field('orgtype', css_class="applyselectize", wrapper_class=wc),
                             Field('enddateafter', css_class="datepicker", wrapper_class=wc),
                             Field('startdateafter', css_class="datepicker", wrapper_class=wc),
                             Field('pcode', wrapper_class=wc)
                             ),
                    Submit('search', u_('Search'), css_class="btn btn-success btn"),
                    )
        )

        return helper
Esempio n. 8
0
def test_formset_with_helper_without_layout(settings):
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy testFormSet formset_helper %}
    """)

    form_helper = FormHelper()
    form_helper.form_id = 'thisFormsetRocks'
    form_helper.form_class = 'formsets-that-rock'
    form_helper.form_method = 'POST'
    form_helper.form_action = 'simpleAction'

    SampleFormSet = formset_factory(SampleForm, extra=3)
    testFormSet = SampleFormSet()

    c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
    html = template.render(c)

    assert html.count('<form') == 1
    assert html.count("<input type='hidden' name='csrfmiddlewaretoken'") == 1

    # Check formset management form
    assert 'form-TOTAL_FORMS' in html
    assert 'form-INITIAL_FORMS' in html
    assert 'form-MAX_NUM_FORMS' in html

    assert 'formsets-that-rock' in html
    assert 'method="post"' in html
    assert 'id="thisFormsetRocks"' in html
    assert 'action="%s"' % reverse('simpleAction') in html
    if settings.CRISPY_TEMPLATE_PACK == 'uni_form':
        assert 'class="uniForm' in html
Esempio n. 9
0
    def __init__(self, *args, **kwargs):
        super(ContinueForm, self).__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_class = "form-inline"
        helper.add_input(Submit("continue_form_submit", u"Continue"))
        self.helper = helper
Esempio n. 10
0
    def test_formset_with_helper_without_layout(self):
        template = loader.get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy testFormSet formset_helper %}
        """)

        form_helper = FormHelper()
        form_helper.form_id = 'thisFormsetRocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'POST'
        form_helper.form_action = 'simpleAction'

        TestFormSet = formset_factory(TestForm, extra = 3)
        testFormSet = TestFormSet()

        c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
        html = template.render(c)

        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        # Check formset management form
        self.assertTrue('form-TOTAL_FORMS' in html)
        self.assertTrue('form-INITIAL_FORMS' in html)
        self.assertTrue('form-MAX_NUM_FORMS' in html)

        self.assertTrue('formsets-that-rock' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks"' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        if (self.current_template_pack == 'uni_form'):
            self.assertTrue('class="uniForm' in html)
Esempio n. 11
0
    def __init__(self, *args, **kwargs):
        super(EnvironmentForm, self).__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_class = 'form-inline'
        helper.add_input(Submit('submit', 'Submit'))
        self.helper = helper
Esempio n. 12
0
File: forms.py Progetto: audax/pypo
    def __init__(self, *args, **kwargs):
        h = FormHelper()
        h.form_id = 'item-search-form'
        h.form_method = 'GET'
        h.form_class = 'form-horizontal'
        h.label_class = 'col-lg-2'
        h.field_class = 'col-lg-8'
        h.layout = layout.Layout(
            'q',
            layout.Div(
                layout.Div(
                    layout.Button('Search', value='Search', css_class='btn-primary'),
                    layout.Div(
                        layout.HTML('<button id="id_oldest" class="btn btn-default" name="sort"'
                                    ' value="oldest" type="submit">'
                                    '<i class="fa fa-sort-asc"></i> Oldest first'
                                    '</button>'),
                        layout.HTML('<button id="id_newest" class="btn btn-default" name="sort"'
                                    ' value="newest" type="submit">'
                                    '<i class="fa fa-sort-desc"></i> Newest first'
                                    '</button>'),
                        css_class="pull-right"),
                    css_class='col-lg-offset-2 col-lg-8'
                ),
                css_class='form-group',
            )
        )
        h.help_text_inline = True
        h.error_text_inline = True
        h.html5_required = True

        self.helper = h
        super(SearchForm, self).__init__(*args, **kwargs)
Esempio n. 13
0
    def __init__(self, *args, **kwargs):
        super(SchemaVersionGenerateForm, self).__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_class = 'form-inline'
        helper.add_input(Submit('submit', 'Submit'))
        self.helper = helper
def test_formset_with_helper_without_layout(settings):
    template = get_template_from_string(
        """
        {% load crispy_forms_tags %}
        {% crispy testFormSet formset_helper %}
    """
    )

    form_helper = FormHelper()
    form_helper.form_id = "thisFormsetRocks"
    form_helper.form_class = "formsets-that-rock"
    form_helper.form_method = "POST"
    form_helper.form_action = "simpleAction"

    TestFormSet = formset_factory(TestForm, extra=3)
    testFormSet = TestFormSet()

    c = Context({"testFormSet": testFormSet, "formset_helper": form_helper, "csrf_token": _get_new_csrf_key()})
    html = template.render(c)

    assert html.count("<form") == 1
    assert html.count("<input type='hidden' name='csrfmiddlewaretoken'") == 1

    # Check formset management form
    assert "form-TOTAL_FORMS" in html
    assert "form-INITIAL_FORMS" in html
    assert "form-MAX_NUM_FORMS" in html

    assert "formsets-that-rock" in html
    assert 'method="post"' in html
    assert 'id="thisFormsetRocks"' in html
    assert 'action="%s"' % reverse("simpleAction") in html
    if settings.CRISPY_TEMPLATE_PACK == "uni_form":
        assert 'class="uniForm' in html
Esempio n. 15
0
    def __init__(self, *args, **kwargs):
        super(SchemaVersionActionsForm, self).__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_class = 'form-inline'
        helper.add_input(Submit('schema_check', 'Schema Check'))
        self.helper = helper
Esempio n. 16
0
def make_stock_filter_form_helper():
    helper = FormHelper()
    helper.form_action = reverse_lazy('stock_reports')
    helper.form_class = 'form-horizontal'
    helper.label_class = 'col-sm-4'
    helper.field_class = 'col-sm-8'
    helper.form_method = 'post'
    helper.layout = Layout(
        Fieldset(
            '',
            # 'Filter source records',
            Field('location'),
            Field('start', placeholder='dd/mm/yyyy'),
            Field('end', placeholder='dd/mm/yyyy'),
            FormActions(
                HTML(
                    '<button class="btn btn-warning form-submit" '
                    'data-dismiss="modal" aria-hidden="true">'
                    '<i class="icon-filter"></i> Filter</button>'
                ),
                HTML(
                    '<a class="btn form-reset" data-dismiss="modal" '
                    'aria-hidden="true">Reset</a>'
                ),
            )
        )
    )

    return helper
Esempio n. 17
0
 def give_feedback(self):
     helper = FormHelper()
     helper.form_id = 'feedback-create-form'
     helper.form_class = 'feedback-create-form'
     helper.form_tag = True
     helper.layout = Layout(
         Layout(
             'good',
             'bad',
             'ugly',
             HTML(u"""<p class="control-group-label feedback-form-award-info">
                         Has this project met all of the criteria for this Badge?
                         If so, go ahead and award it!
                     </p>
                     <div class="control-group checkbox-group award-badge">
                         <input type="checkbox" id="award-badge-input" class="checkboxinput" name="award_badge">
                         <label for="award-badge-input"></label>
                     </div>
                  """),
         ),
         ButtonHolder(
             HTML("""
             <p for="give-feedback" class="control-group-label feedback-form-award-info">Or you can choose to submit your feedback and ask the learner to revise and submit.</p>
             """),
             Submit('submit', _('Submit feedback'), css_class='btn btn-primary btn-large'),
         )
     )
     return helper
Esempio n. 18
0
 def helper(self):
     helper = FormHelper()
     helper.form_class = 'form-horizontal'
     helper.form_id = self.Meta.model._meta.model_name + '-form'
     helper.label_class = 'col-lg-3'
     helper.field_class = 'col-lg-9'
     return helper
Esempio n. 19
0
 def helper(self):
     helper = FormHelper()
     helper.form_method = 'POST'
     helper.add_input(Submit('submit', '注册'))
     helper.form_class = 'form-horizontal'
     helper.label_class = 'col-md-2'
     helper.field_class = 'col-md-7'
     return helper
Esempio n. 20
0
def _get_default_form_helper():
    helper = FormHelper()
    helper.label_class = 'col-sm-3 col-md-2'
    helper.field_class = 'col-sm-9 col-md-8 col-lg-6'
    helper.form_class = "form-horizontal"
    helper.form_id = "performance-form"
    helper.form_method = 'post'
    return helper
Esempio n. 21
0
 def get_layout_helper(self, submit_button_txt):
     helper = FormHelper()
     helper.form_class = 'form-horizontal'
     helper.label_class = 'col-lg-2'
     helper.field_class = 'col-lg-8'
     if (self.add_submit):
         helper.add_input(Submit('submit', submit_button_txt))
     return helper
Esempio n. 22
0
    def helper(self):
        helper = FormHelper()
        helper.attrs = {'action': '/nhdb/downloadexcel/'}
        helper.form_id = "excel-download-form"
        helper.form_class = 'form-horizontal'
        helper.label_class = 'col-lg-3'
        helper.field_class = 'col-lg-9'

        return helper
Esempio n. 23
0
    def __init__(self, *args, **kwargs):
        super(EnvironmentForm, self).__init__(*args, **kwargs)

        self.fields["name"].required = True

        helper = FormHelper()
        helper.form_class = "form-inline"
        helper.add_input(Submit(u"environment_form_submit", u"Submit"))
        self.helper = helper
Esempio n. 24
0
 def __init__(self, *args, **kwargs):
     super(CityInfoFilter, self).__init__(*args, **kwargs)
     helper = FormHelper()
     helper.form_class = 'form-inline'
     helper.field_template = 'bootstrap3/layout/inline_field.html'
     helper.layout = Layout(
         'name',
         Submit('submit', 'Filter', css_class='btn-primary'),
     )
     self.form.helper = helper
Esempio n. 25
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_method = 'POST'
        helper.form_action = 'update/'
        helper.form_class = 'dj-ajax-form'
        helper.add_input(Button('reset', _('Reset'), css_class='btn btn-warning'))
        helper.add_input(Submit('update', _('Update')))
        self.helper = helper
Esempio n. 26
0
 def helper(self):
     helper = FormHelper()
     helper.form_method = 'GET'
     helper.form_class = 'form-inline well'
     helper.field_template = 'bootstrap3/layout/inline_field.html'
     helper.layout = Layout(
         'q',
         StrictButton(_('Search'), type='submit', css_class='btn-primary'),
     )
     return helper
Esempio n. 27
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        helper = FormHelper()
        helper.form_class = 'form-horizontal'
        helper.label_class = 'col-lg-2'
        helper.field_class = 'col-lg-8'
        helper.add_input(Submit('submit', 'Submit'))

        context['helper'] = helper
        return context
Esempio n. 28
0
def _default_crispy_helper(submit_text=None):
    if not submit_text:
        submit_text = _('Save')

    helper = FormHelper()
    helper.form_class = 'form-horizontal'
    helper.label_class = 'col-md-2'
    helper.field_class = 'col-md-10 col-lg-8'
    helper.add_input(Submit('submit', submit_text))
    return helper
Esempio n. 29
0
 def helper(self):
     helper = FormHelper()
     helper.form_method = 'post'
     helper.form_class = 'form-container select-subscription-form'
     helper.layout = Layout(
         'subscription',
         Submit('_select', _(u'Continue with checkout'),
                css_class='large-')
     )
     return helper
Esempio n. 30
0
    def __init__(self, *args, **kwargs):
        super(SubDomainForm, self).__init__(*args, **kwargs)
        helper = FormHelper()
        helper.form_class = 'form-horizontal'
        helper.label_class = 'col-lg-2'
        helper.field_class = 'col-lg-6'
        helper.form_tag = False
        helper.disable_csrf = True

        self.helper = helper
Esempio n. 31
0
def test_formset_with_helper_without_layout(settings):
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy testFormSet formset_helper %}
    """)

    form_helper = FormHelper()
    form_helper.form_id = "thisFormsetRocks"
    form_helper.form_class = "formsets-that-rock"
    form_helper.form_method = "POST"
    form_helper.form_action = "simpleAction"

    SampleFormSet = formset_factory(SampleForm, extra=3)
    testFormSet = SampleFormSet()

    c = Context({
        "testFormSet": testFormSet,
        "formset_helper": form_helper,
        "csrf_token": _get_new_csrf_string()
    })
    html = template.render(c)

    assert html.count("<form") == 1
    assert html.count("csrfmiddlewaretoken") == 1

    # Check formset management form
    assert "form-TOTAL_FORMS" in html
    assert "form-INITIAL_FORMS" in html
    assert "form-MAX_NUM_FORMS" in html

    assert "formsets-that-rock" in html
    assert 'method="post"' in html
    assert 'id="thisFormsetRocks"' in html
    assert 'action="%s"' % reverse("simpleAction") in html
    if settings.CRISPY_TEMPLATE_PACK == "uni_form":
        assert 'class="uniForm' in html
Esempio n. 32
0
    def form_helper(self):
        helper = FormHelper()
        helper.form_class = 'form-horizontal'
        helper.label_class = 'col-lg-2'
        helper.field_class = 'col-lg-8'
        helper.layout = Layout(
            'notes',
            Row(HTML('<hr>')),
            Div(
                StrictButton(_('Approve'), name='approved', value=1, type="submit",
                       css_class='btn btn-success'),
                StrictButton(_('Reject'), name='approved', type="submit",
                       css_class='btn btn-warning'),

                HTML(
                    "<a class='btn btn-danger' href='{}'>{}</a>".format(
                        reverse('orb_delete_resource', kwargs={'resource_id': self.resource.pk}),
                        _('Delete'),
                    )
                ),
                css_class='col-lg-offset-2 col-lg-8',
            ),
        )
        return helper
    def get_crispy_helper(self, foreign_keys_map=None, crosstab_model=None, **kwargs):
        from crispy_forms.helper import FormHelper
        from crispy_forms.layout import Column, Layout, Div, Row, Field

        helper = FormHelper()
        helper.form_class = 'form-horizontal'
        helper.label_class = 'col-sm-2 col-md-2 col-lg-2'
        helper.field_class = 'col-sm-10 col-md-10 col-lg-10'
        helper.form_tag = False
        helper.disable_csrf = True

        foreign_keys_map = foreign_keys_map or self.foreign_keys

        helper.layout = Layout(
            Row(
                Column(
                    Field('start_date'), css_class='col-sm-6'),
                Column(
                    Field('end_date'), css_class='col-sm-6'),

                css_class='raReportDateRange'),
            Div(css_class="mt-20", style='margin-top:20px')
        )

        # if crosstab_model:
        #     entry_point.append(Row(
        #         Div('matrix_entities', css_class='col-sm-9'),
        #         Div('matrix_show_other', css_class='col-sm-3')
        #         , css_class='matrixField')
        #     )

        for k in foreign_keys_map:
            if k[:-3] != crosstab_model:
                helper.layout.fields[1].append(Field(k))

        return helper
Esempio n. 34
0
 def helper(self):
     helper = FormHelper()
     helper.form_tag = False
     helper.form_class = "form-group"
     helper.form_method = "post"
     helper.layout = Layout(
         Fieldset(
             "Basics",
             HTML('<div class="row">'),
             Div('name', css_class="col-7"),
             Div('website', css_class="col"),
             HTML('</div>'),
             HTML('<div class="row">'),
             Div('iata_code', css_class="col-3"),
             Div('icao_code', css_class="col-3"),
             Div('main_phone', css_class="col"),
             HTML('</div>'),
             "local_police",
         ),
         # BERWARE! hard-coding ids for Aviation and Airport here...
         Hidden("mode", 1),
         Hidden("type", 1),
     )
     return helper
Esempio n. 35
0
def test_formset_with_helper_without_layout(settings):
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy testFormSet formset_helper %}
    """)

    form_helper = FormHelper()
    form_helper.form_id = 'thisFormsetRocks'
    form_helper.form_class = 'formsets-that-rock'
    form_helper.form_method = 'POST'
    form_helper.form_action = 'simpleAction'

    SampleFormSet = formset_factory(SampleForm, extra=3)
    testFormSet = SampleFormSet()

    c = Context({
        'testFormSet': testFormSet,
        'formset_helper': form_helper,
        'csrf_token': _get_new_csrf_key()
    })
    html = template.render(c)

    assert html.count('<form') == 1
    assert html.count('csrfmiddlewaretoken') == 1

    # Check formset management form
    assert 'form-TOTAL_FORMS' in html
    assert 'form-INITIAL_FORMS' in html
    assert 'form-MAX_NUM_FORMS' in html

    assert 'formsets-that-rock' in html
    assert 'method="post"' in html
    assert 'id="thisFormsetRocks"' in html
    assert 'action="%s"' % reverse('simpleAction') in html
    if settings.CRISPY_TEMPLATE_PACK == 'uni_form':
        assert 'class="uniForm' in html
Esempio n. 36
0
    def helper(self):
        helper = FormHelper()
        helper.attrs = {
            'action': '/contactlist/api/person/{ edit.id }/',
            'onsubmit': '{ submit_edit }',
            'method': 'PUT'
        }
        helper.form_id = "person-edit-form"
        helper.form_class = 'form-horizontal'

        helper.layout = Layout(
            Field('person',
                  id="person_edit_name",
                  value='{ edit.person }',
                  rows=1,
                  cols=20),
            Field('email',
                  id="person_edit_email",
                  value='{ edit.email }',
                  rows=1,
                  cols=20),
            Field('phone',
                  id="person_edit_phone",
                  value='{ edit.phone }',
                  rows=1,
                  cols=20),
        )

        helper.layout.append(
            ButtonHolder(
                Submit('submit', 'Edit', css_class='btn btn-sm btn-default'),
                Button('cancel',
                       'Cancel',
                       css_class='btn btn-sm btn-default',
                       onclick='{ person_edit_hide }')))
        return helper
Esempio n. 37
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     helper = FormHelper()
     helper.layout = Layout(
         Div(
             Field(
                 "gm",
                 template="crispy/floating-labels.html",
                 wrapper_class="col-12 col-md-6 col-lg px-1 mb-lg-0",
                 title=__("GM") + " (" + __("active") + ")"
                 if "gm" in self.active_filters
                 else __("GM"),
                 css_class="filter-active" if "gm" in self.active_filters else "",
             ),
             Field(
                 "workweek",
                 template="crispy/floating-labels.html",
                 wrapper_class="col-12 col-md-6 col-lg px-1 mb-lg-0",
                 title=__("Workweek") + " (" + __("active") + ")"
                 if "workweek" in self.active_filters
                 else __("Workweek"),
                 css_class="filter-active"
                 if "workweek" in self.active_filters
                 else "",
             ),
             Field(
                 "categories",
                 template="crispy/floating-labels.html",
                 wrapper_class="col-12 col-md-6 col-lg px-1 mb-lg-0",
                 title=__("Categories") + " (" + __("active") + ")"
                 if "categories" in self.active_filters
                 else __("Categories"),
                 css_class="filter-active"
                 if "categories" in self.active_filters
                 else "",
             ),
             Field(
                 "is_custom_material",
                 template="crispy/floating-labels.html",
                 wrapper_class="col-12 col-md-6 col-lg px-1 mb-lg-0",
                 title=__("Custom material") + " (" + __("active") + ")"
                 if "is_custom_material" in self.active_filters
                 else __("Custom material"),
                 css_class="filter-active"
                 if "is_custom_material" in self.active_filters
                 else "",
             ),
             Div(
                 Submit(
                     "filter",
                     _("Apply filters"),
                     css_class="btn-secondary",
                 ),
                 HTML(
                     '<a href="?" class="btn btn-outline-secondary">{}</a>'.format(
                         _("Clear")
                     )
                 ),
                 css_class="col-12 col-lg-auto px-1 mb-xl-0 form-label-group mb-md-0",
             ),
             css_class="row mx-0",
         ),
     )
     helper.form_class = "form-inline"
     helper.disable_csrf = True
     self.helper = helper
Esempio n. 38
0
from django.core.urlresolvers import reverse_lazy
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Field, HTML, Submit
from crispy_forms.layout import *
# from crispy_forms.bootstrap import PrependedText, FormActions, StrictButton, InlineField
from crispy_forms.bootstrap import *

add_book_helper = FormHelper()
add_book_helper.form_tag = True
# add_book_helper.form_id = 'id-registerform'
add_book_helper.form_class = 'form-horizontal'
add_book_helper.form_method = 'POST'
# add_book_helper.form_action = '/'
add_book_helper.form_show_labels = True  # default = True
add_book_helper.label_class = 'col-lg-2'
add_book_helper.field_class = 'col-lg-4'
add_book_helper.layout = Layout(
    Field('name', css_class='form-control'),
    Field('image', css_class='form-control'),
    Field('author', css_class='form-control'),
    Field('pub', css_class='form-control'),
    PrependedText(
        'price',
        "₹",
        css_class='form-control',
    ), Field('published_date', css_class='form-control'),
    Div(FormActions(
        Submit('Save changes',
               value="Save",
               css_class="btn-primary align-right"), ),
        css_class="container"))
Esempio n. 39
0
 def helper(self):
     helper = FormHelper()
     helper.form_id = 'AModel-form'
     helper.form_class = 'AModel-form'
     helper.add_input(Submit('save', 'Save'))
     return helper
Esempio n. 40
0
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
Esempio n. 41
0
from crispy_forms.helper import FormHelper

DefaultFormHelper = FormHelper()
DefaultFormHelper.form_class = 'form-horizontal'
DefaultFormHelper.label_class = 'col-lg-2'
DefaultFormHelper.field_class = 'col-lg-8'
DefaultFormHelper.form_tag = False

# Base helper
BaseFormHelper = FormHelper()
BaseFormHelper.form_tag = False
Esempio n. 42
0
    def test_formset_layout(self):
        TestFormSet = formset_factory(TestForm, extra=3)
        formset = TestFormSet()
        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_key()})

        # Check formset fields
        django_version = django.VERSION[:3]
        hidden_count = 4  # before Django 1.7 added MIN_NUM_FORM_COUNT
        if django_version < (1, 5):
            self.assertEqual(
                html.count(
                    'type="hidden" name="form-TOTAL_FORMS" value="3" id="id_form-TOTAL_FORMS"'
                ), 1)
            self.assertEqual(
                html.count(
                    'type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS"'
                ), 1)
            if (django_version >= (1, 4) and django_version <
                (1, 4, 4)) or django_version < (1, 3, 6):
                self.assertEqual(
                    html.count(
                        'type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS"'
                    ), 1)
            else:
                self.assertEqual(
                    html.count(
                        'type="hidden" name="form-MAX_NUM_FORMS" value="1000" id="id_form-MAX_NUM_FORMS"'
                    ), 1)
        else:
            self.assertEqual(
                html.count(
                    'id="id_form-TOTAL_FORMS" name="form-TOTAL_FORMS" type="hidden" value="3"'
                ), 1)
            self.assertEqual(
                html.count(
                    'id="id_form-INITIAL_FORMS" name="form-INITIAL_FORMS" type="hidden" value="0"'
                ), 1)
            self.assertEqual(
                html.count(
                    'id="id_form-MAX_NUM_FORMS" name="form-MAX_NUM_FORMS" type="hidden" value="1000"'
                ), 1)
            if hasattr(forms.formsets, 'MIN_NUM_FORM_COUNT'):
                self.assertEqual(
                    html.count(
                        'id="id_form-MIN_NUM_FORMS" name="form-MIN_NUM_FORMS" type="hidden" value="0"'
                    ), 1)
                hidden_count += 1
        self.assertEqual(html.count("hidden"), hidden_count)

        # Check form structure
        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(
            html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)
        self.assertTrue('formsets-that-rock' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks"' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)

        # Check form layout
        self.assertTrue('Item 1' in html)
        self.assertTrue('Item 2' in html)
        self.assertTrue('Item 3' in html)
        self.assertEqual(html.count('Note for first form only'), 1)
        if self.current_template_pack == 'uni_form':
            self.assertEqual(html.count('formRow'), 3)
        else:
            self.assertEqual(html.count('row'), 3)
Esempio n. 43
0
from crispy_forms.helper import FormHelper
from crispy_forms.layout import *
from crispy_forms.bootstrap import *
from django.forms.widgets import PasswordInput

create_company_helper = FormHelper()
create_company_helper.form_tag = False
create_company_helper.form_class = ''
create_company_helper.form_method = 'POST'
create_company_helper.layout = Layout(
    Div(Field('contact_number',
              css_class='form-control',
              placeholder='Mobile Number (used as Username)'),
        Field('profile_image',
              css_class='form-control',
              placeholder='Company Logo'),
        Field('name', css_class='form-control', placeholder='Company Name'),
        Field('country', css_class='form-control', placeholder='Country'),
        Field('first_name',
              css_class='form-control',
              placeholder='Owner First Name'),
        Field('last_name',
              css_class='form-control',
              placeholder='Owner Last Name'),
        Field('email', css_class='form-control', placeholder='Email'),
        Field('alternate_email',
              css_class='form-control',
              placeholder='Alternate Email'),
        Field('alternate_contact_no',
              css_class='form-control',
              placeholder='Mobile Number'),
Esempio n. 44
0
def test_formset_layout(settings):
    TestFormSet = formset_factory(TestForm, extra=3)
    formset = TestFormSet()
    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_key()}
    )

    # Check formset fields
    hidden_count = 4  # before Django 1.7 added MIN_NUM_FORM_COUNT
    assert html.count(
        'id="id_form-TOTAL_FORMS" name="form-TOTAL_FORMS" type="hidden" value="3"'
    ) == 1
    assert html.count(
        'id="id_form-INITIAL_FORMS" name="form-INITIAL_FORMS" type="hidden" value="0"'
    ) == 1
    assert html.count(
        'id="id_form-MAX_NUM_FORMS" name="form-MAX_NUM_FORMS" type="hidden" value="1000"'
    ) == 1
    if hasattr(forms.formsets, 'MIN_NUM_FORM_COUNT'):
        assert html.count(
            'id="id_form-MIN_NUM_FORMS" name="form-MIN_NUM_FORMS" type="hidden" value="0"'
        ) == 1
        hidden_count += 1
    assert html.count("hidden") == hidden_count

    # Check form structure
    assert html.count('<form') == 1
    assert html.count("<input type='hidden' name='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 == 'bootstrap4':
        assert html.count('row') == 21
    else:
        assert html.count('row') == 3
Esempio n. 45
0
from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth.views import login
from django.urls import reverse_lazy
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _

from utils.views import render_js

login_helper = FormHelper()
login_helper.form_action = reverse_lazy("login_page")
login_helper.form_method = "POST"
login_helper.form_class = "form-signin"
login_helper.html5_required = True
login_helper.layout = layout.Layout(
    layout.HTML(string_concat("""<h2 class="form-signin-heading">""", _("Please Sign In"), """</h2>""")),
    layout.Field("username", placeholder=_("username")),
    layout.Field("password", placeholder=_("password")),
    layout.HTML("""<input type="hidden" name="next" value="{{ next }}" />"""),
    layout.Submit("submit", _("Login"), css_class="btn-lg")
)

# class CrispySearchView(SearchView):
#     def extra_context(self):
#         helper = FormHelper()
#         helper.form_tag = False
#         helper.disable_csrf = True
#         return {"search_helper": helper}
Esempio n. 46
0
def translation_helper(instance=None, prefix='', form_tag=False):
    """
    Catalog's message translations form layout helper
    """
    helper = FormHelper()
    helper.form_action = '.'
    helper.form_class = 'catalog-messages-form'
    helper.form_tag = form_tag
    helper.disable_csrf = True # Does not seems to have real effect
    helper.render_required_fields = True
    
    # Define base css classes
    row_css_classes = ['message-row', 'clearfix']
    if instance.fuzzy:
        row_css_classes.append('fuzzy')
    elif not instance.message:
        row_css_classes.append('disabled empty')
    else:
        row_css_classes.append('enabled')
        
    # Build anchor link and id
    anchor_link = ''
    if prefix:
        prefix_id = int(prefix[len('form-'):]) + 1
        anchor_link = '<a href="#item-{0}" id="item-{0}">#{0}</a>'.format(prefix_id)
    
    # Build messages, at least the singular message
    message_contents = [Div(
            Div(
                HTML(
                    source_formatter(instance.template.message)
                ),
                css_class='flex-item source',
            ),
            Field(
                'message',
                placeholder=_("Type your translation here else the original text will be used"),
                wrapper_class='flex-item edit',
            ),
            css_class='flex-container',
        ),
        # Little trick to hide the field because formset requires the same 
        # fields for all items
        HiddenField('plural_message')
    ]
            
    # If plural is enabled, build the plural message and append it
    if instance.pluralizable:
        row_css_classes.append('pluralizable')
        # Remove hidden field
        message_contents.pop()
        # Append plural field
        message_contents.append(Div(
            Div(
                HTML(
                    source_formatter(instance.template.plural_message)
                ),
                css_class='flex-item source',
            ),
            Field(
                'plural_message',
                placeholder=_("Type your translation here else the original text will be used"),
                wrapper_class='flex-item edit',
            ),
            css_class='flex-container',
        ))

    
    helper.layout = Layout(
        Div(
            Div(
                HTML(anchor_link),
                css_class='anchor',
            ),
            Div(
                Div(
                    'fuzzy',
                    css_class='fuzzy-field',
                ),
                *message_contents,
                css_class=' '.join(row_css_classes)
            ),
            Div(
                HTML('<p class="title"><i class="icon-eye"></i> '),
                HTML(_('Locations')),
                HTML('</p>'),
                HTML(
                    build_locations(instance.template.get_locations_set()),
                ),
                css_class='locations',
            ),
            css_class='row-wrapper',
        ),
    )
    
    return helper
Esempio n. 47
0
def test_formset_layout():
    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
    assert html.count("row") == 3

    assert html.count("mb-3") == 21
Esempio n. 48
0
    def __init__(self, *args, **kwargs):
        readonly = kwargs.pop('readonly', False)
        super(CompanyModelForm, self).__init__(*args, **kwargs)

        helper = FormHelper()
        helper.form_class = 'form-horizontal'
        helper.form_method = 'POST'
        helper.label_class = 'col-lg-2'
        helper.form_tag = False
        helper.field_class = 'col-lg-10'
        Fieldset.template = 'crm/fieldset.html'
        helper.layout = Layout(
            Fieldset(
                '公司信息', 'title', 'industry', 'type', 'scale_size',
                'taxpayer_type', 'rating', 'status', 'ic_status',
                'has_customer_files', 'registered_capital', 'address',
                'op_address', 'uscc', 'business_license', 'website',
                'salesman', 'bookkeeper', 'legal_people', 'legal_phone',
                PrependedText('registered_at',
                              '<i class="fa fa-calendar"></i>'),
                PrependedText('expired_at', '<i class="fa fa-calendar"></i>'),
                PrependedText('tax_declared_begin',
                              '<i class="fa fa-calendar"></i>'),
                'special_taxes',
                PrependedText('contactor',
                              '<i class="fa fa-user-circle"></i>'),
                PrependedText('contactor_phone',
                              '<i class="fa fa-phone"></i>'),
                PrependedText('tags',
                              '<i class="fa fa-tags"></i>',
                              css_class="tagsinput"), 'note'),
            Fieldset(
                '申报区', 'alias',
                PrependedText('tax_username', '<i class="fa fa-user"></i>'),
                PrependedText('tax_password', '<i class="fa fa-key"></i>'),
                'batch', 'ss_declared', 'tax_disk', 'added_value_tax',
                'income_tax', 'cut_tax', 'invoice', 'const_tax',
                'special_taxes', 'declare_info'),
            Fieldset(
                '银行信息',
                'has_czk',
                'ss_number',
                'taxpayer_bank',
                'taxpayer_account',
                'ss_bank',
                'ss_account',
                'individual_bank',
                'individual_account',
                PrependedText('ss_date', '<i class="fa fa-calendar"></i>'),
            ),
            Fieldset(
                '国税信息', 'national_tax_office', 'national_tax_id',
                PrependedText('national_tax_staff',
                              '<i class="fa fa-user"></i>'),
                PrependedText('national_tax_phone',
                              '<i class="fa fa-phone"></i>')),
            Fieldset(
                '地税信息', 'local_tax_office', 'local_tax_id', 'local_tax_sn',
                PrependedText('local_tax_staff', '<i class="fa fa-user"></i>'),
                PrependedText('local_tax_phone',
                              '<i class="fa fa-phone"></i>')),
            Fieldset(
                '海关信息',
                'has_custom_info',
                'custom_register_no',
                'credit_rating',
                PrependedText('custom_registered_at',
                              '<i class="fa fa-calendar"></i>'),
                PrependedText('custom_expired_at',
                              '<i class="fa fa-calendar"></i>'),
            ))
        self.helper = helper

        if readonly:
            for field in self.fields:
                self.fields[field].disabled = True