Ejemplo n.º 1
0
class ConfigurableDataSourceFromAppForm(forms.Form):

    app_id = forms.ChoiceField()
    case_type = forms.ChoiceField()

    def __init__(self, domain, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', _('Save Changes')))
        super(ConfigurableDataSourceFromAppForm, self).__init__(*args, **kwargs)
        apps = get_apps_in_domain(domain, full=True, include_remote=False)
        self.fields['app_id'] = forms.ChoiceField(
            label=_('Application'),
            choices=[(app._id, app.name) for app in apps]
        )
        self.fields['case_type'] = forms.ChoiceField(
            choices=[(ct, ct) for ct in set([c for app in apps for c in app.get_case_types() if c])]
        )

    def clean(self):
        cleaned_data = super(ConfigurableDataSourceFromAppForm, self).clean()
        app = Application.get(cleaned_data['app_id'])
        if cleaned_data['case_type'] not in app.get_case_types():
            raise ValidationError(_('Case type {} not found in application {}!'.format(
                cleaned_data['case_type'],
                app.name,
            )))
        # set the app property on the form so we don't have to go back to the DB for it
        # there may be a better way to do this.
        self.app = app
        return cleaned_data
Ejemplo n.º 2
0
class ConfigurableFormDataSourceFromAppForm(forms.Form):

    app_id = forms.ChoiceField()
    form_id = forms.ChoiceField()

    def __init__(self, domain, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', _('Save Changes')))
        super(ConfigurableFormDataSourceFromAppForm, self).__init__(*args, **kwargs)
        apps = get_apps_in_domain(domain, full=True, include_remote=False)
        self.fields['app_id'] = forms.ChoiceField(
            label=_('Application'),
            choices=[(app._id, app.name) for app in apps]
        )
        self.fields['form_id'] = forms.ChoiceField(
            label=_('Module - Form'),
            choices=[(form.get_unique_id(), form.get_module().default_name() + ' - ' + form.default_name())
                     for form in set([form for app in apps for form in app.get_forms()])]
        )

    def clean(self):
        cleaned_data = super(ConfigurableFormDataSourceFromAppForm, self).clean()
        app = Application.get(cleaned_data['app_id'])
        form = Form.get_form(cleaned_data['form_id'])
        if form.get_app()._id != app._id:
            raise ValidationError(_('Form name {} not found in application {}').format(
                form.default_name(),
                app.name
            ))
        self.app = app
        self.form = form
        return cleaned_data
Ejemplo n.º 3
0
 def __init__(self, instance=None, *args, **kwargs):
     self.instance = instance
     object_data = instance._doc if instance is not None else {}
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.add_input(Submit('submit', _('Save Changes')))
     super(DocumentFormBase, self).__init__(initial=object_data, *args, **kwargs)
Ejemplo n.º 4
0
 def __init__(self, instance=None, read_only=False, *args, **kwargs):
     self.instance = instance
     object_data = instance._doc if instance is not None else {}
     self.helper = FormHelper()
     self.helper.form_method = "post"
     if not read_only:
         self.helper.add_input(Submit("submit", _("Save Changes")))
     super(DocumentFormBase, self).__init__(initial=object_data, *args, **kwargs)
Ejemplo n.º 5
0
 def __init__(self, domain, *args, **kwargs):
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.add_input(Submit('submit', _('Save Changes')))
     super(ConfigurableDataSourceFromAppForm, self).__init__(*args, **kwargs)
     apps = get_apps_in_domain(domain, full=True, include_remote=False)
     self.fields['app_id'] = forms.ChoiceField(
         label=_('Application'),
         choices=[(app._id, app.name) for app in apps]
     )
     self.fields['case_type'] = forms.ChoiceField(
         choices=[(ct, ct) for ct in set([c for app in apps for c in app.get_case_types() if c])]
     )
Ejemplo n.º 6
0
class DocumentFormBase(forms.Form):
    """
    HQ specific document base form. Loosely modeled off of Django's ModelForm
    """

    def __init__(self, instance=None, *args, **kwargs):
        self.instance = instance
        object_data = instance._doc if instance is not None else {}
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', _('Save Changes')))
        super(DocumentFormBase, self).__init__(initial=object_data, *args, **kwargs)

    def save(self, commit=False):
        self.populate_instance(self.instance, self.cleaned_data)
        if commit:
            self.instance.save()
        return self.instance

    def populate_instance(self, instance, cleaned_data):
        for field in self.fields:
            setattr(instance, field, cleaned_data[field])
        return instance
Ejemplo n.º 7
0
 def __init__(self, domain, *args, **kwargs):
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.add_input(Submit('submit', _('Save Changes')))
     super(ConfigurableFormDataSourceFromAppForm, self).__init__(*args, **kwargs)
     apps = get_apps_in_domain(domain, full=True, include_remote=False)
     self.fields['app_id'] = forms.ChoiceField(
         label=_('Application'),
         choices=[(app._id, app.name) for app in apps]
     )
     self.fields['form_id'] = forms.ChoiceField(
         label=_('Module - Form'),
         choices=[(form.get_unique_id(), form.get_module().default_name() + ' - ' + form.default_name())
                  for form in set([form for app in apps for form in app.get_forms()])]
     )
Ejemplo n.º 8
0
    def __init__(self, *args, **kwargs):
        super(ExampleUserLoginForm, self).__init__(*args, **kwargs)

        # Here's what makes the form a Crispy Form:
        self.helper = FormHelper()

        # This is necessary to make the form a horizontal form
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-3'
        self.helper.field_class = 'col-lg-6'

        # This is the layout of the form where we can explicitly specify the
        # order of fields and group fields into fieldsets.
        self.helper.layout = crispy.Layout(
            crispy.Fieldset(
                # This is the title for the group of fields that follows:
                _("Basic Information"),
                'full_name',  # crispy.Field is used as the default display component
                crispy.Field(
                    'email'),  # effectively the same as the line above
                'password',
                'password_repeat',
            ),
            crispy.Fieldset(
                _("Advanced Information"),
                'is_staff',
                twbs.PrependedText('phone_number',
                                   '+',
                                   placeholder='15555555555'),
            ),
            FormActions(
                twbs.StrictButton(_("Create User"),
                                  type='submit',
                                  css_class='btn-primary'),
                twbs.StrictButton(_("Cancel"), css_class='btn-default'),
            ),
        )