Exemple #1
0
    def __init__(self, *args, **kwargs):
        self.user = kwargs['existing_user']
        api_key = kwargs.pop('api_key') if 'api_key' in kwargs else None
        super(UpdateMyAccountInfoForm, self).__init__(*args, **kwargs)
        self.username = self.user.username

        username_controls = []
        if self.username:
            username_controls.append(
                hqcrispy.StaticField(ugettext_lazy('Username'), self.username))

        api_key_controls = [
            hqcrispy.StaticField(ugettext_lazy('API Key'), api_key),
            hqcrispy.FormActions(twbscrispy.StrictButton(
                ugettext_lazy('Generate API Key'),
                type="button",
                id='generate-api-key',
                css_class='btn-default',
            ),
                                 css_class="form-group"),
        ]

        self.fields['language'].label = ugettext_lazy("My Language")

        self.new_helper = cb3_helper.FormHelper()
        self.new_helper.form_method = 'POST'
        self.new_helper.form_class = 'form-horizontal'
        self.new_helper.attrs = {
            'name': 'user_information',
        }
        self.new_helper.label_class = 'col-sm-3 col-md-2 col-lg-2'
        self.new_helper.field_class = 'col-sm-9 col-md-8 col-lg-6'

        basic_fields = [
            cb3_layout.Div(*username_controls),
            hqcrispy.Field('first_name'),
            hqcrispy.Field('last_name'),
            hqcrispy.Field('email'),
        ]
        if self.set_analytics_enabled:
            basic_fields.append(
                twbscrispy.PrependedText('analytics_enabled', ''), )
        if self.set_email_opt_out:
            basic_fields.append(twbscrispy.PrependedText('email_opt_out', ''))

        self.new_helper.layout = cb3_layout.Layout(
            cb3_layout.Fieldset(ugettext_lazy("Basic"), *basic_fields),
            (hqcrispy.FieldsetAccordionGroup
             if self.collapse_other_options else cb3_layout.Fieldset)(
                 ugettext_lazy("Other Options"),
                 hqcrispy.Field('language'),
                 cb3_layout.Div(*api_key_controls),
             ),
            hqcrispy.FormActions(
                twbscrispy.StrictButton(
                    ugettext_lazy("Update My Information"),
                    type='submit',
                    css_class='btn-primary',
                )))
Exemple #2
0
    def __init__(self, *args, **kwargs):
        from corehq.apps.settings.views import ApiKeyView
        self.user = kwargs['existing_user']
        super(UpdateMyAccountInfoForm, self).__init__(*args, **kwargs)
        self.username = self.user.username

        username_controls = []
        if self.username:
            username_controls.append(hqcrispy.StaticField(
                ugettext_lazy('Username'), self.username)
            )

        self.fields['language'].label = ugettext_lazy("My Language")

        self.new_helper = FormHelper()
        self.new_helper.form_method = 'POST'
        self.new_helper.form_class = 'form-horizontal'
        self.new_helper.attrs = {
            'name': 'user_information',
        }
        self.new_helper.label_class = 'col-sm-3 col-md-2 col-lg-2'
        self.new_helper.field_class = 'col-sm-9 col-md-8 col-lg-6'

        basic_fields = [
            crispy.Div(*username_controls),
            hqcrispy.Field('first_name'),
            hqcrispy.Field('last_name'),
            hqcrispy.Field('email'),
        ]
        if self.set_analytics_enabled:
            basic_fields.append(twbscrispy.PrependedText('analytics_enabled', ''),)

        self.new_helper.layout = crispy.Layout(
            crispy.Fieldset(
                ugettext_lazy("Basic"),
                *basic_fields
            ),
            (hqcrispy.FieldsetAccordionGroup if self.collapse_other_options else crispy.Fieldset)(
                ugettext_lazy("Other Options"),
                hqcrispy.Field('language'),
                crispy.Div(hqcrispy.StaticField(
                    ugettext_lazy('API Key'),
                    mark_safe(
                        ugettext_lazy('API key management has moved <a href="{}">here</a>.')
                        .format(reverse(ApiKeyView.urlname))
                    ),
                )),
            ),
            hqcrispy.FormActions(
                twbscrispy.StrictButton(
                    ugettext_lazy("Update My Information"),
                    type='submit',
                    css_class='btn-primary',
                )
            )
        )