def __init__(self, report_name, app_id, source_type, report_source_id, existing_report=None, *args, **kwargs):
        """
        This form can be used to create a new ReportConfiguration, or to modify
        an existing one if existing_report is set.
        """
        super(ConfigureNewReportBase, self).__init__(*args, **kwargs)
        self.existing_report = existing_report

        if self.existing_report:
            self._bootstrap(self.existing_report)
            self.button_text = _('Update Report')
        else:
            self.report_name = report_name
            assert source_type in ['case', 'form']
            self.source_type = source_type
            self.report_source_id = report_source_id
            self.app = Application.get(app_id)

        self.domain = self.app.domain
        self.ds_builder = DataSourceBuilder(
            self.domain, self.app, self.source_type, self.report_source_id
        )
        self.data_source_properties = self.ds_builder.data_source_properties
        self._properties_by_column = {
            p.column_id: p for p in self.data_source_properties.values()
        }

        # NOTE: The corresponding knockout view model is defined in:
        #       templates/userreports/partials/report_builder_configure_report.html
        self.helper = FormHelper()
        self.helper.form_class = "form form-horizontal"
        self.helper.label_class = 'col-sm-3 col-md-2 col-lg-2'
        self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6'
        self.helper.attrs['data_bind'] = "submit: submitHandler"
        self.helper.form_id = "report-config-form"

        buttons = [
            StrictButton(
                _(self.button_text),
                css_class="btn btn-primary disable-on-submit",
                type="submit",
            )
        ]
        # Add a back button if we aren't editing an existing report
        if not self.existing_report:
            buttons.insert(
                0,
                crispy.HTML(
                    '<a class="btn btn-default" href="{}" style="margin-right: 4px">{}</a>'.format(
                        reverse(
                            'report_builder_select_source',
                            args=(self.domain, self.report_type),
                        ),
                        _('Back')
                    )
                ),
            )
        # Add a "delete report" button if we are editing an existing report
        else:
            buttons.insert(
                0,
                crispy.HTML(
                    '<a id="delete-report-button" class="btn btn-danger pull-right" href="{}">{}</a>'.format(
                        reverse(
                            'delete_configurable_report',
                            args=(self.domain, self.existing_report._id),
                        ) + "?{}".format(urlencode(
                            {'redirect': reverse('reports_home', args=[self.domain])}
                        )),
                        _('Delete Report')
                    )
                )
            )
        self.helper.layout = crispy.Layout(
            self.container_fieldset,
            hqcrispy.FormActions(crispy.ButtonHolder(*buttons)),
        )
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/userreports/reports/builder/forms.py/ConfigureNewReportBase.__init__/original