コード例 #1
0
    def __init__(self, domain, *args, **kwargs):
        super(ConfigurableDataSourceFromAppForm,
              self).__init__(*args, **kwargs)
        self.app_source_helper = ApplicationDataSourceUIHelper()
        self.app_source_helper.bootstrap(domain)
        report_source_fields = self.app_source_helper.get_fields()
        self.fields.update(report_source_fields)
        self.helper = FormHelper()
        self.helper.form_id = "data-source-config"

        self.helper.form_method = 'POST'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_action = '#'

        self.helper.label_class = 'col-sm-3 col-md-2'
        self.helper.field_class = 'col-sm-9 col-md-9'

        self.helper.layout = crispy.Layout(
            crispy.Fieldset(_("Create Data Source from Application"),
                            *list(report_source_fields)),
            hqcrispy.FormActions(
                twbscrispy.StrictButton(
                    _("Create Data Source"),
                    type="submit",
                    css_class="btn btn-primary",
                ), ),
        )
コード例 #2
0
    def __init__(self, domain, config, *args, **kwargs):
        self.domain = domain
        self.config = config

        def _to_initial(config):
            initial = copy.copy(config._doc)
            initial['schedule'] = config.schedule.interval
            if config.template_variables:
                initial['application'] = config.template_variables[0].app_id
                initial['source'] = config.template_variables[0].source_id
                initial['time_range'] = config.template_variables[0].time_range
            return initial

        super(PerformanceMessageEditForm,
              self).__init__(initial=_to_initial(config), *args, **kwargs)

        self.fields['recipient_id'] = GroupField(domain=domain,
                                                 label=_('Recipient Group'))

        self.app_source_helper = ApplicationDataSourceUIHelper(
            enable_cases=False)
        self.app_source_helper.bootstrap(self.domain)
        data_source_fields = self.app_source_helper.get_fields()
        self.fields.update(data_source_fields)

        self.helper = _get_default_form_helper()
        form_layout = self.fields.keys()
        form_layout.append(
            hqcrispy.FormActions(
                StrictButton(
                    _("Save Changes"),
                    type="submit",
                    css_class="btn btn-primary",
                ), ))
        self.helper.layout = Layout(*form_layout)
コード例 #3
0
ファイル: forms.py プロジェクト: ekush/commcare-hq
    def __init__(self, domain, report_type, *args, **kwargs):
        super(DataSourceForm, self).__init__(*args, **kwargs)
        self.domain = domain
        self.report_type = report_type

        self.app_source_helper = ApplicationDataSourceUIHelper()
        self.app_source_helper.bootstrap(self.domain)
        report_source_fields = self.app_source_helper.get_fields()
        report_source_help_texts = {
            "source_type":
            _("<strong>Form</strong>: display data from form submissions.<br/><strong>Case</strong>: display data from your cases. You must be using case management for this option."
              ),
            "application":
            _("Which application should the data come from?"),
            "source":
            _("Choose the case type or form from which to retrieve data for this report."
              ),
        }
        self.fields.update(report_source_fields)

        self.fields['chart_type'].required = self.report_type == "chart"

        self.helper = FormHelper()
        self.helper.form_class = "form-horizontal"
        self.helper.form_id = "report-builder-form"

        chart_type_crispy_field = None
        if self.report_type == 'chart':
            chart_type_crispy_field = FieldWithHelpBubble(
                'chart_type',
                help_bubble_text=
                _("<strong>Bar</strong> shows one vertical bar for each value in your case or form. <strong>Pie</strong> shows what percentage of the total each value is."
                  ))
        report_source_crispy_fields = []
        for k in report_source_fields.keys():
            if k in report_source_help_texts:
                report_source_crispy_fields.append(
                    FieldWithHelpBubble(
                        k, help_bubble_text=report_source_help_texts[k]))
            else:
                report_source_crispy_fields.append(k)

        self.helper.layout = crispy.Layout(
            crispy.Fieldset(
                _('{} Report'.format(self.report_type.capitalize())),
                FieldWithHelpBubble(
                    'report_name',
                    help_bubble_text=
                    _('Web users will see this name in the "Reports" section of CommCareHQ and can click to view the report'
                      )), chart_type_crispy_field),
            crispy.Fieldset(_('Data'), *report_source_crispy_fields),
            FormActions(
                crispy.ButtonHolder(
                    crispy.Submit(
                        'create_new_report_builder_btn',
                        _('Next'),
                    )), ),
        )
コード例 #4
0
 def __init__(self, domain, *args, **kwargs):
     super(ConfigurableDataSourceFromAppForm,
           self).__init__(*args, **kwargs)
     self.app_source_helper = ApplicationDataSourceUIHelper()
     self.app_source_helper.bootstrap(domain)
     report_source_fields = self.app_source_helper.get_fields()
     self.fields.update(report_source_fields)
     self.helper = FormHelper()
     self.helper.form_id = "data-source-config"
     self.helper.layout = crispy.Layout(
         crispy.Div(*report_source_fields.keys() +
                    [Submit('submit', _('Save Changes'))]))