Python crispy_forms.layout.Fieldset() Examples

The following are 30 code examples of crispy_forms.layout.Fieldset(). 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 Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 6 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)

        id_field = layout.Field("id")
        language_field = layout.Field("language", css_class="input-block-level")
        title_field = layout.Field("title", css_class="input-block-level")
        content_field = layout.Field("content", css_class="input-block-level", rows="3")
        delete_field = layout.Field("DELETE")
        main_fieldset = layout.Fieldset(
            _("Main data"),
            id_field,
            language_field,
            title_field,
            content_field,
            delete_field,
        )

        self.helper = helper.FormHelper()
        self.helper.form_tag = False
        self.helper.disable_csrf = True
        self.helper.layout = layout.Layout(main_fieldset) 
Example #2
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        author_field = layout.Field("author")
        category_field = layout.Field("category")
        rating_field = layout.Field("rating")
        submit_button = layout.Submit("filter", _("Filter"))
        actions = bootstrap.FormActions(submit_button)

        main_fieldset = layout.Fieldset(
            _("Filter"),
            author_field,
            category_field,
            rating_field,
            actions,
        )

        self.helper = helper.FormHelper()
        self.helper.form_method = "GET"
        self.helper.layout = layout.Layout(main_fieldset) 
Example #3
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 6 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)

        id_field = layout.Field("id")
        language_field = layout.Field("language", css_class="input-block-level")
        title_field = layout.Field("title", css_class="input-block-level")
        content_field = layout.Field("content", css_class="input-block-level", rows="3")
        delete_field = layout.Field("DELETE")
        main_fieldset = layout.Fieldset(
            _("Main data"),
            id_field,
            language_field,
            title_field,
            content_field,
            delete_field,
        )

        self.helper = helper.FormHelper()
        self.helper.form_tag = False
        self.helper.disable_csrf = True
        self.helper.layout = layout.Layout(main_fieldset) 
Example #4
Source File: forms.py    From HELPeR with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(TaskPairChooseEffectTaskForm, self).__init__(*args, **kwargs)
        if 'effect_agent' in kwargs.get('initial', {}):
            self.fields['effect_task'].choices = [
                (task_name, getattr(task, 'label', task_name))
                for task_name, task in AgentConfig.objects.get(
                    pk=kwargs['initial']['effect_agent']).agent.effect_tasks.items()]
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(Fieldset(
            'Choose a Effect',
            'cause_agent', 'cause_task', 'cause_options', 'effect_agent',
            *submit_buttons_from_choicefield(
                'effect_task', self.fields['effect_task'], kwargs.get('prefix')
            )
        )) 
Example #5
Source File: forms.py    From django-marketplace with MIT License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            layout.Fieldset(
                '',
                layout.Field('recipient', readonly=True),
                'subject',
                'body',
                'referenced_post',
            ),
            bootstrap.FormActions(
                Submit('submit', 'Send Message', css_class='btn btn-success'),
            )
        )
        self.helper.form_tag = False 
Example #6
Source File: forms.py    From HELPeR with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(TaskPairChooseCauseTaskForm, self).__init__(*args, **kwargs)
        if 'cause_agent' in kwargs.get('initial', {}):
            self.fields['cause_task'].choices = [
                (task_name, getattr(task, 'label', task_name))
                for task_name, task in AgentConfig.objects.get(
                    pk=kwargs['initial']['cause_agent']).agent.cause_tasks.items()]
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(Fieldset(
            'Choose a Cause',
            'cause_agent',
            *submit_buttons_from_choicefield(
                'cause_task', self.fields['cause_task'], kwargs.get('prefix')
            )
        )) 
Example #7
Source File: layout.py    From weibo-analysis-system with MIT License 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #8
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 5 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)

        title_field = layout.Field("title")
        content_field = layout.Field("content", rows="3")
        main_fieldset = layout.Fieldset(_("Main data"), title_field, content_field)

        picture_field = layout.Field("picture")
        format_html = layout.HTML(
            """{% include "ideas1/includes/picture_guidelines.html" %}"""
        )

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            format_html,
            title=_("Image upload"),
            css_id="picture_fieldset",
        )

        categories_field = layout.Field(
            "categories",
            template="core/includes/checkboxselectmultiple_tree.html"
        )
        categories_fieldset = layout.Fieldset(
            _("Categories"), categories_field, css_id="categories_fieldset"
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(submit_button, css_class="my-4")

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.layout = layout.Layout(
            main_fieldset,
            picture_fieldset,
            categories_fieldset,
            actions,
        ) 
Example #9
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 5 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)

        self.fields["categories"].widget = forms.CheckboxSelectMultiple()

        title_field = layout.Field("title")
        content_field = layout.Field("content", rows="3")
        main_fieldset = layout.Fieldset(_("Main data"), title_field, content_field)

        picture_field = layout.Field("picture")
        format_html = layout.HTML(
            """{% include "ideas2/includes/picture_guidelines.html" %}"""
        )

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            format_html,
            title=_("Image upload"),
            css_id="picture_fieldset",
        )

        categories_field = layout.Field("categories")
        categories_fieldset = layout.Fieldset(
            _("Categories"), categories_field, css_id="categories_fieldset"
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(submit_button)

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.layout = layout.Layout(
            main_fieldset,
            picture_fieldset,
            categories_fieldset,
            actions,
        ) 
Example #10
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 5 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)

        title_field = layout.Field("title", css_class="input-block-level")
        content_field = layout.Field("content", css_class="input-block-level", rows="3")
        main_fieldset = layout.Fieldset(_("Main data"), title_field, content_field)

        picture_field = layout.Field("picture", css_class="input-block-level")
        format_html = layout.HTML(
            """{% include "ideas/includes/picture_guidelines.html" %}"""
        )

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            format_html,
            title=_("Image upload"),
            css_id="picture_fieldset",
        )

        inline_translations = layout.HTML(
            """{% include "ideas/forms/translations.html" %}"""
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(submit_button)

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.layout = layout.Layout(
            main_fieldset,
            inline_translations,
            picture_fieldset,
            actions,
        ) 
Example #11
Source File: layout.py    From ImitationTmall_Django with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #12
Source File: forms.py    From HELPeR with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(TaskPairChooseCauseAgentForm, self).__init__(*args, **kwargs)
        self.fields['effect_agent'].queryset = AgentConfig.objects.filter(
            pk__in=[agent.pk for agent in AgentConfig.objects.all()
                    if len(agent.agent.effect_tasks) > 0]
        )
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(Fieldset(
            'Choose a Effect Agent',
            'cause_agent', 'cause_task', 'cause_options',
            *agent_buttons('effect_agent', self.fields['effect_agent'].queryset,
                           kwargs.get('prefix'))
        )) 
Example #13
Source File: forms.py    From HELPeR with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(TaskPairCauseOptionsForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.label_class = 'col-md-2'
        self.helper.field_class = 'col-md-8'
        fields = ['cause_agent', 'cause_task']

        predefined_fields = {}
        for key in ['cause_agent', 'cause_task']:
            if key in kwargs.get('initial', {}):
                predefined_fields[key] = kwargs['initial'][key]
            elif 'prefix' in kwargs and '{}-{}'.format(kwargs['prefix'], key) in self.data:
                predefined_fields[key] = self.data['{}-{}'.format(kwargs['prefix'], key)]
            elif key in self.data:
                predefined_fields[key] = self.data[key]

        if set(['cause_agent', 'cause_task']) <= set(predefined_fields):
            task = Agent.registry[predefined_fields['cause_agent']]\
                .cause_tasks[predefined_fields['cause_task']]
            if getattr(task, 'help', False):
                fields.append(HTML("""
                                <div class="alert alert-info" role="alert">
                                {help}
                                </div>
                                """.format(help=task.help)))
            for option, field in getattr(task, 'options', {}).items():
                self.fields['cause-opt-'+option] = field
                fields.append('cause-opt-'+option)
            if not getattr(task, 'options', False):
                fields.append(HTML("""
                                <div class="alert alert-success" role="alert">
                                No options to complete
                                </div>
                                """))
        fields.append(FormActions(Submit('submit', 'Continue')))
        self.helper.layout = Layout(Fieldset('Task Options', *fields)) 
Example #14
Source File: forms.py    From HELPeR with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(TaskPairChooseCauseAgentForm, self).__init__(*args, **kwargs)
        self.fields['cause_agent'].queryset = AgentConfig.objects.filter(
            pk__in=[agent.pk for agent in AgentConfig.objects.all()
                    if len(agent.agent.cause_tasks) > 0]
        )
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(Fieldset(
            'Choose a Cause Agent',
            *agent_buttons('cause_agent', self.fields['cause_agent'].queryset,
                           kwargs.get('prefix'))
        )) 
Example #15
Source File: forms.py    From TWLight with MIT License 5 votes vote down vote up
def _add_user_data_subform(self, user_data):
        self._validate_user_data(user_data)

        if user_data:
            # Translators: This labels a section of a form where we ask users to enter personal information (such as their country of residence) when making an application.
            user_data_layout = Fieldset(_("About you"))
            for datum in user_data:
                self.fields[datum] = FIELD_TYPES[datum]
                self.fields[datum].label = FIELD_LABELS[datum]
                # Show which partner wants which personal data if applying
                # for more than one.
                if len(self.field_params) > 1:
                    # fmt: off
                    # Translators: This text is shown in the application form under each piece of personal information requested. {partner_list} will be a list of 2 or more organisations that require this personal data, and should not be translated.
                    self.fields[datum].help_text = _("Requested by: {partner_list}").format(
                        partner_list=", ".join(user_data[datum])
                    ),
                    # fmt: on
                user_data_layout.append(datum)

            self.helper.layout.append(user_data_layout)
            # fmt: off
            # Translators: This note appears in a section of a form where we ask users to enter info (like country of residence) when applying for resource access.
            disclaimer_html = _("<p><small><i>Your personal data will be processed according to our <a href='{terms_url}'> privacy policy</a>.</i></small></p>").format(
                terms_url=reverse("terms")
            )
            # fmt: on
            self.helper.layout.append(HTML(disclaimer_html)) 
Example #16
Source File: layout.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #17
Source File: layout.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #18
Source File: layout.py    From devops with MIT License 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #19
Source File: layout.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #20
Source File: layout.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #21
Source File: layout.py    From StormOnline with Apache License 2.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #22
Source File: layout.py    From django_OA with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #23
Source File: layout.py    From CTF_AWD_Platform with MIT License 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #24
Source File: layout.py    From myblog with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, legend, *fields, **kwargs):
        self.description = kwargs.pop('description', None)
        self.collapsed = kwargs.pop('collapsed', None)
        super(Fieldset, self).__init__(legend, *fields, **kwargs) 
Example #25
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 4 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)
        geoposition = self.instance.get_geoposition()
        if geoposition:
            self.fields["latitude"].initial = geoposition.latitude
            self.fields["longitude"].initial = geoposition.longitude

        name_field = layout.Field("name", css_class="input-block-level")
        description_field = layout.Field(
            "description", css_class="input-block-level", rows="3"
        )
        main_fieldset = layout.Fieldset(_("Main data"), name_field, description_field)

        picture_field = layout.Field(
            "picture",
            data_url=reverse("upload_file"),
            template="core/includes/file_upload_field.html",
        )
        picture_path_field = layout.Field("picture_path")

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            picture_path_field,
            title=_("Picture upload"),
            css_id="picture_fieldset",
        )

        street_address_field = layout.Field(
            "street_address", css_class="input-block-level"
        )
        street_address2_field = layout.Field(
            "street_address2", css_class="input-block-level"
        )
        postal_code_field = layout.Field("postal_code", css_class="input-block-level")
        city_field = layout.Field("city", css_class="input-block-level")
        country_field = layout.Field("country", css_class="input-block-level")
        latitude_field = layout.Field("latitude", css_class="input-block-level")
        longitude_field = layout.Field("longitude", css_class="input-block-level")
        address_fieldset = layout.Fieldset(
            _("Address"),
            street_address_field,
            street_address2_field,
            postal_code_field,
            city_field,
            country_field,
            latitude_field,
            longitude_field,
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(layout.Div(submit_button, css_class="col"))

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.attrs = {"noValidate": "noValidate"}
        self.helper.layout = layout.Layout(main_fieldset, picture_fieldset, address_fieldset, actions) 
Example #26
Source File: forms.py    From TWLight with MIT License 4 votes vote down vote up
def __init__(self, *args, **kwargs):
        try:
            self.field_params = kwargs.pop("field_params")
        except KeyError:
            logger.exception(
                "Tried to instantiate a RenewalForm but did not have field_params"
            )
            raise
        super(RenewalForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        # Translators: This will be the title of the page where users will have to confirm their renewal request of an application.
        fieldset = Fieldset(_("Renewal confirmation"))

        account_email = False
        if (
            "account_email" in self.field_params
            and self.field_params["account_email"] is not None
        ):
            self.fields["account_email"] = forms.EmailField(
                initial=self.field_params["account_email"]
            )
            account_email = True
        elif "account_email" in self.field_params:
            self.fields["account_email"] = forms.EmailField()
            account_email = True
        if account_email:
            # fmt: off
            # Translators: This labels an email field where users will be asked to enter their emails as part of the application renewal confirmation.
            self.fields["account_email"].label = _("The email for your account on the partner's website")
            # fmt: on
            fieldset.append("account_email")

        if "requested_access_duration" in self.field_params:
            self.fields["requested_access_duration"] = forms.ChoiceField(
                choices=Application.REQUESTED_ACCESS_DURATION_CHOICES
            )
            # fmt: off
            # Translators: This labels a choice field where users will have to select the number of months they wish to have their access for as part of the application renewal confirmation.
            self.fields["requested_access_duration"].label = _("The number of months you wish to have this access for before renewal is required")
            # fmt: on
            fieldset.append("requested_access_duration")

        self.fields["return_url"] = forms.CharField(
            widget=forms.HiddenInput, max_length=70
        )
        self.fields["return_url"].initial = self.field_params["return_url"]
        fieldset.append("return_url")

        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-4"

        self.helper.layout = Layout()
        self.helper.layout.append(fieldset) 
Example #27
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 4 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)

        self.fields["categories"].widget = forms.CheckboxSelectMultiple()

        title_field = layout.Field("title", css_class="input-block-level")
        content_field = layout.Field("content", css_class="input-block-level", rows="3")
        main_fieldset = layout.Fieldset(_("Main data"), title_field, content_field)

        picture_field = layout.Field("picture", css_class="input-block-level")
        format_html = layout.HTML(
            """{% include "ideas/includes/picture_guidelines.html" %}"""
        )

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            format_html,
            title=_("Image upload"),
            css_id="picture_fieldset",
        )

        categories_field = layout.Field("categories", css_class="input-block-level")
        categories_fieldset = layout.Fieldset(
            _("Categories"), categories_field, css_id="categories_fieldset"
        )

        inline_translations = layout.HTML(
            """{% include "ideas/forms/translations.html" %}"""
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(submit_button)

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.layout = layout.Layout(
            main_fieldset,
            inline_translations,
            picture_fieldset,
            categories_fieldset,
            actions,
        ) 
Example #28
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 4 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)
        geoposition = self.instance.get_geoposition()
        if geoposition:
            self.fields["latitude"].initial = geoposition.latitude
            self.fields["longitude"].initial = geoposition.longitude

        name_field = layout.Field("name", css_class="input-block-level")
        description_field = layout.Field(
            "description", css_class="input-block-level", rows="3"
        )
        main_fieldset = layout.Fieldset(_("Main data"), name_field, description_field)

        picture_field = layout.Field(
            "picture",
            data_url=reverse("upload_file"),
            template="core/includes/file_upload_field.html",
        )
        picture_path_field = layout.Field("picture_path")

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            picture_path_field,
            title=_("Picture upload"),
            css_id="picture_fieldset",
        )

        street_address_field = layout.Field(
            "street_address", css_class="input-block-level"
        )
        street_address2_field = layout.Field(
            "street_address2", css_class="input-block-level"
        )
        postal_code_field = layout.Field("postal_code", css_class="input-block-level")
        city_field = layout.Field("city", css_class="input-block-level")
        country_field = layout.Field("country", css_class="input-block-level")
        latitude_field = layout.Field("latitude", css_class="input-block-level")
        longitude_field = layout.Field("longitude", css_class="input-block-level")
        address_fieldset = layout.Fieldset(
            _("Address"),
            street_address_field,
            street_address2_field,
            postal_code_field,
            city_field,
            country_field,
            latitude_field,
            longitude_field,
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(layout.Div(submit_button, css_class="col"))

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.attrs = {"noValidate": "noValidate"}
        self.helper.layout = layout.Layout(main_fieldset, picture_fieldset, address_fieldset, actions) 
Example #29
Source File: forms.py    From Django-3-Web-Development-Cookbook-Fourth-Edition with MIT License 4 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        self.request = request
        super().__init__(*args, **kwargs)
        geoposition = self.instance.get_geoposition()
        if geoposition:
            self.fields["latitude"].initial = geoposition.latitude
            self.fields["longitude"].initial = geoposition.longitude

        name_field = layout.Field("name", css_class="input-block-level")
        description_field = layout.Field(
            "description", css_class="input-block-level", rows="3"
        )
        main_fieldset = layout.Fieldset(_("Main data"), name_field, description_field)

        picture_field = layout.Field(
            "picture",
            data_url=reverse("upload_file"),
            template="core/includes/file_upload_field.html",
        )
        picture_path_field = layout.Field("picture_path")

        picture_fieldset = layout.Fieldset(
            _("Picture"),
            picture_field,
            picture_path_field,
            title=_("Picture upload"),
            css_id="picture_fieldset",
        )

        street_address_field = layout.Field(
            "street_address", css_class="input-block-level"
        )
        street_address2_field = layout.Field(
            "street_address2", css_class="input-block-level"
        )
        postal_code_field = layout.Field("postal_code", css_class="input-block-level")
        city_field = layout.Field("city", css_class="input-block-level")
        country_field = layout.Field("country", css_class="input-block-level")
        latitude_field = layout.Field("latitude", css_class="input-block-level")
        longitude_field = layout.Field("longitude", css_class="input-block-level")
        address_fieldset = layout.Fieldset(
            _("Address"),
            street_address_field,
            street_address2_field,
            postal_code_field,
            city_field,
            country_field,
            latitude_field,
            longitude_field,
        )

        submit_button = layout.Submit("save", _("Save"))
        actions = bootstrap.FormActions(layout.Div(submit_button, css_class="col"))

        self.helper = helper.FormHelper()
        self.helper.form_action = self.request.path
        self.helper.form_method = "POST"
        self.helper.attrs = {"noValidate": "noValidate"}
        self.helper.layout = layout.Layout(main_fieldset, picture_fieldset, address_fieldset, actions) 
Example #30
Source File: forms.py    From django-leonardo with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def __init__(self, request, *args, **kwargs):
        parent = kwargs.pop('parent', None)
        super(PageCreateForm, self).__init__(*args, **kwargs)

        if parent:
            self.fields['parent'].initial = parent

        if request.method == 'GET':
            color_scheme_fields = self.init_color_scheme_switch(
                color_scheme=kwargs['initial'].get('color_scheme', None))

            self.helper.layout = Layout(
                TabHolder(
                    Tab(_('Main'),
                        'title',
                        'language',
                        'translation_of',
                        'parent',
                        'site',
                        css_id='page-main'
                        ),
                    Tab(_('Navigation'),
                        'in_navigation', 'slug',
                        'override_url', 'redirect_to',
                        'symlinked_page', 'navigation_extension'
                        ),
                    Tab(_('Heading'),
                        '_content_title', '_page_title',
                        css_id='page-heading'
                        ),
                    Tab(_('Publication'),
                        'active', 'featured', 'publication_date',
                        'publication_end_date', 'meta_description',
                        'meta_keywords'
                        ),
                    Tab(_('Theme'),
                        'template_key', 'layout', Fieldset(
                            'Themes', 'theme', *color_scheme_fields),
                        css_id='page-theme-settings'
                        ),
                )
            )

        self.fields['color_scheme'].required = False