Example #1
0
    def __init__(self, from_domain, app, *args, **kwargs):
        export_zipped_apps_enabled = kwargs.pop('export_zipped_apps_enabled', False)
        super(CopyApplicationForm, self).__init__(*args, **kwargs)
        fields = ['domain', 'name', 'toggles']
        self.from_domain = from_domain
        if app:
            self.fields['name'].initial = app.name
        if export_zipped_apps_enabled:
            self.fields['gzip'] = forms.FileField(required=False)
            fields.append('gzip')
        if LINKED_DOMAINS.enabled(self.from_domain):
            fields.append(PrependedText('linked', ''))

        self.helper = FormHelper()
        self.helper.label_class = 'col-sm-3 col-md-4 col-lg-2'
        self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6'
        self.helper.layout = crispy.Layout(
            crispy.Fieldset(
                _('Copy Application'),
                *fields
            ),
            crispy.Hidden('app', app.get_id),
            hqcrispy.FormActions(
                StrictButton(_('Copy'), type='button', css_class='btn-primary')
            )
        )
Example #2
0
 def column_fieldset(self):
     return crispy.Fieldset(
         _legend(_("Columns"), self.column_legend_fine_print),
         crispy.Div(crispy.HTML(self.column_config_template),
                    id="columns-table",
                    data_bind='with: columnsList'),
         crispy.Hidden('columns',
                       None,
                       data_bind="value: columnsList.serializedProperties"))
Example #3
0
    def __init__(self, *args, **kwargs):  # pragma: no cover
        """Initialize crispy forms."""
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id-LoginForm'
        self.helper.form_class = 'form-group'
        self.form_method = 'post'
        self.helper.form_action = reverse(settings.LOGIN_URL)

        self.helper.add_input(layout.Submit('login', 'Login'))
        self.helper.add_input(layout.Hidden('next', ''))
Example #4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.add_input(
         layout.Submit(
             name="submit",
             value="Submit",
             css_id="submit-labels",
         )
     )
     self.helper.add_input(
         layout.Hidden(
             name="updated-sample",
             value="updated-sample",
         )
     )
     self.helper.add_input(
         layout.Hidden(
             name="label-data",
             value="label-data",
         )
     )
Example #5
0
    def __init__(self, project, request_user, *args, **kwargs):
        super(NewAnonymousMobileWorkerForm, self).__init__(*args, **kwargs)
        self.project = project
        self.request_user = request_user
        self.can_access_all_locations = request_user.has_permission(self.project.name, 'access_all_locations')
        if not self.can_access_all_locations:
            self.fields['location_id'].required = True

        if project.uses_locations:
            self.fields['location_id'].widget = AngularLocationSelectWidget(
                require=not self.can_access_all_locations)
            location_field = crispy.Field(
                'location_id',
                ng_model='mobileWorker.location_id',
            )
        else:
            location_field = crispy.Hidden(
                'location_id',
                '',
                ng_model='mobileWorker.location_id',
            )

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.label_class = 'col-sm-4'
        self.helper.field_class = 'col-sm-8'
        self.helper.layout = Layout(
            Fieldset(
                _('Basic Information'),
                crispy.Field(
                    'username',
                    readonly=True,
                ),
                location_field,
                crispy.Hidden('is_anonymous', 'yes'),
            )
        )
Example #6
0
    def __init__(self, *args, **kwargs):  # pragma: no cover
        """Initialize crispy forms."""
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_id = 'id-LoginForm'
        self.helper.form_class = 'form-group'
        self.form_method = 'post'
        self.helper.form_action = reverse(settings.LOGIN_URL)

        self.helper.layout = layout.Layout(
            'username', 'password',
            layout.Div(layout.Submit('login',
                                     'Login',
                                     css_class='btn-success my-2 px-4'),
                       css_class='text-center'), layout.Hidden('next', ''))
Example #7
0
 def filter_fieldset(self):
     """
     Return a fieldset representing the markup used for configuring the
     report filters.
     """
     return crispy.Fieldset(
         _legend(
             _("Filters"),
             _("Add filters to your report to allow viewers to select which data the report will display. These filters will be displayed at the top of your report."
               )),
         crispy.Div(crispy.HTML(self.column_config_template),
                    id="filters-table",
                    data_bind='with: filtersList'),
         crispy.Hidden('filters',
                       None,
                       data_bind="value: filtersList.serializedProperties"))
Example #8
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = helper.FormHelper()
     self.helper.form_action = "login"
     # self.helper.form_class = 'xxx-form-horizontal'
     # self.helper.label_class = 'xxx-helper-label_class'
     # self.helper.field_class = 'xxx-helper-field_class'
     self.helper.layout = helper.Layout(
         layout.Fieldset(
             'Inicio de sesión',
             'username',
             'password',
             layout.Hidden('next', '{{next}}'),
         ),
         bootstrap.FormActions(layout.Submit('submit', 'Iniciar sesión'), ),
     )
Example #9
0
    def get_hidden_fields(self):
        """
        Get hidden fields for the form.

        If you set :obj:`.roleid_field`, a hidden field named whatever you
        specify in :obj:`.roleid_field` with value set to the current role ID
        is added automatically.

        Returns:
            An iterable of :class:`crispy_forms.layout.Hidden` objects.
        """
        fields = []
        if self.roleid_field:
            roleid = self.request.cradmin_instance.get_roleid(
                self.request.cradmin_role)
            fields.append(layout.Hidden(self.roleid_field, roleid))
        return fields
Example #10
0
    def __init__(self, from_domain, app, *args, **kwargs):
        super(CopyApplicationForm, self).__init__(*args, **kwargs)
        fields = ['domain', 'name', 'toggles', 'build_id']
        self.from_domain = from_domain
        if app:
            self.fields['name'].initial = app.name
        if toggles.LINKED_DOMAINS.enabled(
                self.from_domain) and not is_linked_app(app):
            fields.append(PrependedText('linked', ''))

        self.helper = FormHelper()
        self.helper.label_class = 'col-sm-3 col-md-4 col-lg-2'
        self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6'
        self.helper.layout = crispy.Layout(
            crispy.Fieldset(
                _('Copy Application for Editing')
                if is_linked_app(app) else _('Copy Application'), *fields),
            crispy.Hidden('app', app.get_id),
            hqcrispy.FormActions(
                StrictButton(_('Copy'), type='button',
                             css_class='btn-primary')))
Example #11
0
 def get_field_layout(self):
     form_class = self.get_form_class()
     if self.initial_email_value:
         return [
             layout.Hidden(form_class.username_field,
                           self.initial_email_value),
             layout.Field('password',
                          placeholder=form_class.password_field_placeholder,
                          focusonme='focusonme',
                          css_class='input-lg'),
         ]
     else:
         return [
             layout.Field(form_class.username_field,
                          placeholder=form_class.username_field_placeholder,
                          css_class='input-lg',
                          focusonme='focusonme'),
             layout.Field('password',
                          placeholder=form_class.password_field_placeholder,
                          css_class='input-lg'),
         ]
Example #12
0
    def __init__(self, project, request_user, *args, **kwargs):
        super(NewMobileWorkerForm, self).__init__(*args, **kwargs)
        email_string = "@{}.commcarehq.org".format(project.name)
        max_chars_username = 80 - len(email_string)
        self.project = project
        self.domain = self.project.name
        self.request_user = request_user
        self.can_access_all_locations = request_user.has_permission(
            self.domain, 'access_all_locations')
        if not self.can_access_all_locations:
            self.fields['location_id'].required = True

        if self.project.strong_mobile_passwords:
            # Use normal text input so auto-generated strong password is visible
            self.fields['new_password'].widget = forms.TextInput()
            self.fields['new_password'].help_text = mark_safe_lazy(
                string_concat(
                    '<i class="fa fa-warning"></i>',
                    ugettext_lazy(
                        'This password is automatically generated. Please copy it or create your own. It will not be shown again.'
                    ), '<br />'))

        if project.uses_locations:
            self.fields['location_id'].widget = forms.Select()
            location_field = crispy.Field(
                'location_id',
                data_bind='value: location_id',
                data_query_url=reverse('location_search', args=[self.domain]),
            )
        else:
            location_field = crispy.Hidden(
                'location_id',
                '',
                data_bind='value: location_id',
            )

        self.helper = HQModalFormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Fieldset(
                _('Basic Information'),
                crispy.Div(crispy.Field(
                    'username',
                    data_bind="value: username, valueUpdate: 'keyup'",
                    maxlength=max_chars_username,
                ),
                           data_bind='''
                        css: {
                            'has-pending': $root.usernameAvailabilityStatus() === $root.STATUS.PENDING,
                            'has-success': $root.usernameAvailabilityStatus() === $root.STATUS.SUCCESS,
                            'has-warning': $root.usernameAvailabilityStatus() === $root.STATUS.WARNING,
                            'has-error': $root.usernameAvailabilityStatus() === $root.STATUS.ERROR,
                        },
                    '''),
                crispy.Field(
                    'first_name',
                    data_bind='value: first_name',
                ),
                crispy.Field(
                    'last_name',
                    data_bind='value: last_name',
                ),
                location_field,
                crispy.Div(hqcrispy.B3MultiField(
                    _("Password"),
                    InlineField(
                        'new_password',
                        data_bind="value: password, valueUpdate: 'input'",
                    ),
                    crispy.HTML('''
                            <p class="help-block" data-bind="if: $root.isSuggestedPassword">
                                <i class="fa fa-warning"></i> {suggested}
                            </p>
                            <p class="help-block" data-bind="ifnot: $root.isSuggestedPassword()">
                                <!-- ko if: $root.passwordStatus() === $root.STATUS.SUCCESS -->
                                    <i class="fa fa-check"></i> {strong}
                                <!-- /ko -->
                                <!-- ko ifnot: $root.useDraconianSecurity() -->
                                    <!-- ko if: $root.passwordStatus() === $root.STATUS.WARNING -->
                                        {almost}
                                    <!-- /ko -->
                                    <!-- ko if: $root.passwordStatus() === $root.STATUS.ERROR -->
                                        <i class="fa fa-warning"></i> {weak}
                                    <!-- /ko -->
                                <!-- /ko -->

                                <!-- ko if: $root.useDraconianSecurity() -->
                                    <!-- ko if: $root.passwordStatus() === $root.STATUS.ERROR -->
                                        <i class="fa fa-warning"></i> {rules}
                                    <!-- /ko -->
                                <!-- /ko -->
                            </p>
                        '''.format(
                        suggested=_(
                            "This password is automatically generated. Please copy it or create "
                            "your own. It will not be shown again."),
                        strong=_("Good Job! Your password is strong!"),
                        almost=
                        _("Your password is almost strong enough! Try adding numbers or symbols!"
                          ),
                        weak=
                        _("Your password is too weak! Try adding numbers or symbols!"
                          ),
                        rules=_(
                            "Password Requirements: 1 special character, 1 number, 1 capital letter, "
                            "minimum length of 8 characters."),
                    )),
                    required=True,
                ),
                           data_bind='''
                        css: {
                            'has-success': $root.passwordStatus() === $root.STATUS.SUCCESS,
                            'has-warning': $root.passwordStatus() === $root.STATUS.WARNING,
                            'has-error': $root.passwordStatus() === $root.STATUS.ERROR,
                        }
                    '''),
            ))
 def get_hidden_fields(self):
     return [layout.Hidden(name='post_type_received_data', value='')]
Example #14
0
    def __init__(self, project, request_user, *args, **kwargs):
        super(NewMobileWorkerForm, self).__init__(*args, **kwargs)
        email_string = "@{}.commcarehq.org".format(project.name)
        max_chars_username = 80 - len(email_string)
        self.project = project
        self.domain = self.project.name
        self.request_user = request_user
        self.can_access_all_locations = request_user.has_permission(self.domain, 'access_all_locations')
        if not self.can_access_all_locations:
            self.fields['location_id'].required = True

        if self.project.strong_mobile_passwords:
            if settings.ENABLE_DRACONIAN_SECURITY_FEATURES:
                validator = "validate_password_draconian"
            else:
                validator = "validate_password_standard"
            self.fields['password'].widget = forms.TextInput(attrs={
                validator: "",
                "ng_keydown": "markNonDefault()",
                "class": "default",
            })
            self.fields['password'].help_text = mark_safe_lazy(string_concat('<i class="fa fa-warning"></i>',
                ugettext_lazy('This password is automatically generated. Please copy it or create your own. It will not be shown again.'),
                '<br />'
            ))

        if project.uses_locations:
            self.fields['location_id'].widget = forms.Select(choices=[('', '')])    # blank option for placeholder
            location_field = crispy.Field(
                'location_id',
                ng_model='mobileWorker.location_id',
                ng_required="true" if self.fields['location_id'].required else "false",
            )
        else:
            location_field = crispy.Hidden(
                'location_id',
                '',
                ng_model='mobileWorker.location_id',
            )

        self.helper = HQModalFormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Fieldset(
                _('Basic Information'),
                crispy.Field(
                    'username',
                    ng_required="true",
                    validate_username="",
                    # What this says is, update as normal or when the element
                    # loses focus. If the update is normal, wait 300 ms to
                    # send the request again. If the update is on blur,
                    # send the request.
                    ng_model_options="{ "
                                      " updateOn: 'default blur', "
                                      " debounce: {'default': 300, 'blur': 0} "
                                      "}",
                    ng_model='mobileWorker.username',
                    ng_maxlength=max_chars_username,
                    maxlength=max_chars_username,
                ),
                crispy.Field(
                    'first_name',
                    ng_required="false",
                    ng_model='mobileWorker.first_name',
                    ng_maxlength="30",
                ),
                crispy.Field(
                    'last_name',
                    ng_required="false",
                    ng_model='mobileWorker.last_name',
                    ng_maxlength="30",
                ),
                location_field,
                crispy.Field(
                    'password',
                    ng_required="true",
                    ng_model='mobileWorker.password',
                    data_bind="value: password, valueUpdate: 'input'",
                ),
            )
        )
Example #15
0
 def get_field_layout(self):
     return [
         layout.Hidden('candidates', self.__get_candidate_ids())
     ]
Example #16
0
    def __init__(self, project, *args, **kwargs):
        super(NewMobileWorkerForm, self).__init__(*args, **kwargs)
        email_string = u"@{}.commcarehq.org".format(project.name)
        max_chars_username = 80 - len(email_string)
        self.project = project

        if self.project.strong_mobile_passwords:
            self.fields['password'].widget = forms.TextInput(
                attrs={
                    "validate_password": "",
                    "ng_keydown": "markNonDefault()",
                    "class": "default",
                })
            self.fields['password'].help_text = mark_safe_lazy(
                string_concat(
                    '<i class="fa fa-warning"></i>',
                    ugettext_lazy(
                        'This password is automatically generated. Please copy it or create your own. It will not be shown again.'
                    ), '<br />'))

        if project.uses_locations:
            self.fields['location_id'].widget = AngularLocationSelectWidget()
            location_field = crispy.Field(
                'location_id',
                ng_model='mobileWorker.location_id',
            )
        else:
            location_field = crispy.Hidden(
                'location_id',
                '',
                ng_model='mobileWorker.location_id',
            )

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.label_class = 'col-sm-4'
        self.helper.field_class = 'col-sm-8'
        self.helper.layout = Layout(
            Fieldset(
                _('Basic Information'),
                crispy.Field(
                    'username',
                    ng_required="true",
                    validate_username="",
                    # What this says is, update as normal or when the element
                    # loses focus. If the update is normal, wait 300 ms to
                    # send the request again. If the update is on blur,
                    # send the request.
                    ng_model_options="{ "
                    " updateOn: 'default blur', "
                    " debounce: {'default': 300, 'blur': 0} "
                    "}",
                    ng_model='mobileWorker.username',
                    ng_maxlength=max_chars_username,
                    maxlength=max_chars_username,
                ),
                crispy.Field(
                    'first_name',
                    ng_required="false",
                    ng_model='mobileWorker.first_name',
                    ng_maxlength="50",
                ),
                crispy.Field(
                    'last_name',
                    ng_required="false",
                    ng_model='mobileWorker.last_name',
                    ng_maxlength="50",
                ),
                location_field,
                crispy.Field(
                    'password',
                    ng_required="true",
                    ng_model='mobileWorker.password',
                    data_bind="value: password, valueUpdate: 'input'",
                ),
            ))
Example #17
0
    def __init__(self, project, request_user, *args, **kwargs):
        super(NewMobileWorkerForm, self).__init__(*args, **kwargs)
        email_string = "@{}.{}".format(project.name, settings.HQ_ACCOUNT_ROOT)
        max_chars_username = 80 - len(email_string)
        self.project = project
        self.domain = self.project.name
        self.request_user = request_user
        self.can_access_all_locations = request_user.has_permission(self.domain, 'access_all_locations')
        if not self.can_access_all_locations:
            self.fields['location_id'].required = True

        if self.project.strong_mobile_passwords:
            # Use normal text input so auto-generated strong password is visible
            self.fields['new_password'].widget = forms.TextInput()
            self.fields['new_password'].help_text = mark_safe_lazy(
                format_lazy(
                    '<i class="fa fa-warning"></i>{}<br />',
                    ugettext_lazy(
                        'This password is automatically generated. '
                        'Please copy it or create your own. It will not be shown again.'),
                )
            )

        if project.uses_locations:
            self.fields['location_id'].widget = forms.Select()
            location_field = crispy.Field(
                'location_id',
                data_bind='value: location_id',
                data_query_url=reverse('location_search', args=[self.domain]),
            )
        else:
            location_field = crispy.Hidden(
                'location_id',
                '',
                data_bind='value: location_id',
            )

        self.two_stage_provisioning_enabled = TWO_STAGE_USER_PROVISIONING.enabled(self.domain)
        if self.two_stage_provisioning_enabled:
            confirm_account_field = crispy.Field(
                'force_account_confirmation',
                data_bind='checked: force_account_confirmation',
            )
            email_field = crispy.Div(
                crispy.Field(
                    'email',
                    data_bind="value: email, valueUpdate: 'keyup'",
                ),
                data_bind='''
                    css: {
                        'has-error': $root.emailStatus() === $root.STATUS.ERROR,
                    },
                '''
            )
            send_email_field = crispy.Field(
                'send_account_confirmation_email',
                data_bind='checked: send_account_confirmation_email, enable: sendConfirmationEmailEnabled',
            )
        else:
            confirm_account_field = crispy.Hidden(
                'force_account_confirmation',
                '',
                data_bind='value: force_account_confirmation',
            )
            email_field = crispy.Hidden(
                'email',
                '',
                data_bind='value: email',
            )
            send_email_field = crispy.Hidden(
                'send_account_confirmation_email',
                '',
                data_bind='value: send_account_confirmation_email',
            )


        self.helper = HQModalFormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Fieldset(
                _('Basic Information'),
                crispy.Div(
                    crispy.Field(
                        'username',
                        data_bind="value: username, valueUpdate: 'keyup'",
                        maxlength=max_chars_username,
                    ),
                    data_bind='''
                        css: {
                            'has-pending': $root.usernameAvailabilityStatus() === $root.STATUS.PENDING,
                            'has-success': $root.usernameAvailabilityStatus() === $root.STATUS.SUCCESS,
                            'has-warning': $root.usernameAvailabilityStatus() === $root.STATUS.WARNING,
                            'has-error': $root.usernameAvailabilityStatus() === $root.STATUS.ERROR,
                        },
                    '''
                ),
                crispy.Field(
                    'first_name',
                    data_bind='value: first_name',
                ),
                crispy.Field(
                    'last_name',
                    data_bind='value: last_name',
                ),
                location_field,
                confirm_account_field,
                email_field,
                send_email_field,
                crispy.Div(
                    hqcrispy.B3MultiField(
                        _("Password"),
                        InlineField(
                            'new_password',
                            data_bind="value: password, valueUpdate: 'input', enable: passwordEnabled",
                        ),
                        crispy.HTML('''
                            <p class="help-block" data-bind="if: $root.isSuggestedPassword">
                                <i class="fa fa-warning"></i> {suggested}
                            </p>
                            <p class="help-block" data-bind="ifnot: $root.isSuggestedPassword()">
                                <!-- ko ifnot: $root.skipStandardValidations() -->
                                    <!-- ko if: $root.passwordStatus() === $root.STATUS.SUCCESS -->
                                        <i class="fa fa-check"></i> {strong}
                                    <!-- /ko -->
                                    <!-- ko if: $root.passwordStatus() === $root.STATUS.WARNING -->
                                        {almost}
                                    <!-- /ko -->
                                    <!-- ko if: $root.passwordStatus() === $root.STATUS.ERROR -->
                                        <i class="fa fa-warning"></i> {weak}
                                    <!-- /ko -->
                                <!-- /ko -->

                                <!-- ko if: $root.skipStandardValidations() -->
                                    <i class="fa fa-info-circle"></i> {custom_warning}
                                <!-- /ko -->
                                <!-- ko if: $root.passwordStatus() === $root.STATUS.DISABLED -->
                                    <i class="fa fa-warning"></i> {disabled}
                                <!-- /ko -->
                            </p>
                        '''.format(
                            suggested=_("This password is automatically generated. Please copy it or create "
                                "your own. It will not be shown again."),
                            strong=_("Good Job! Your password is strong!"),
                            almost=_("Your password is almost strong enough! Try adding numbers or symbols!"),
                            weak=_("Your password is too weak! Try adding numbers or symbols!"),
                            custom_warning=_(settings.CUSTOM_PASSWORD_STRENGTH_MESSAGE),
                            disabled=_("Setting a password is disabled. "
                                       "The user will set their own password on confirming their account email."),
                        )),
                        required=True,
                    ),
                    data_bind='''
                        css: {
                            'has-success': $root.passwordStatus() === $root.STATUS.SUCCESS,
                            'has-warning': $root.passwordStatus() === $root.STATUS.WARNING,
                            'has-error': $root.passwordStatus() === $root.STATUS.ERROR,
                        }
                    ''' if not has_custom_clean_password() else ''
                ),
            )
        )