def page_context(self): try: report_form = self.report_form except Exception as e: self.template_name = 'userreports/report_error.html' error_response = { 'report_id': self.existing_report.get_id, 'is_static': self.existing_report.is_static, 'error_message': '', 'details': unicode(e) } return self._handle_exception(error_response, e) return { 'report': { "title": self.page_name }, 'report_type': self.report_type, 'form': report_form, 'editing_existing_report': bool(self.existing_report), 'report_column_options': [p.to_dict() for p in report_form.report_column_options.values()], 'data_source_indicators': [p._asdict() for p in report_form.data_source_properties.values()], # For now only use date ranges that don't require additional parameters 'date_range_options': [r._asdict() for r in get_simple_dateranges()], 'initial_user_filters': [f._asdict() for f in report_form.initial_user_filters], 'initial_default_filters': [f._asdict() for f in report_form.initial_default_filters], 'initial_columns': [ c._asdict() for c in getattr(report_form, 'initial_columns', []) ], 'report_builder_events': self.request.session.pop(REPORT_BUILDER_EVENTS_KEY, []) }
def _get_report_module_context(app, module): def _report_to_config(report): return { 'report_id': report._id, 'title': report.title, 'description': report.description, 'charts': [chart for chart in report.charts if chart.type == 'multibar'], 'filter_structure': report.filters_without_prefilters, } all_reports = ReportConfiguration.by_domain(app.domain) + \ StaticReportConfiguration.by_domain(app.domain) validity = module.check_report_validity() # We're now proactively deleting these references, so after that's been # out for a while, this can be removed (say June 2016 or later) if not validity.is_valid: module.report_configs = validity.valid_report_configs filter_choices = [ {'slug': f.doc_type, 'description': f.short_description} for f in get_all_mobile_filter_configs() ] auto_filter_choices = [ {'slug': f.slug, 'description': f.short_description} for f in get_auto_filter_configurations() ] return { 'all_reports': [_report_to_config(r) for r in all_reports], 'current_reports': [r.to_json() for r in module.report_configs], 'filter_choices': filter_choices, 'auto_filter_choices': auto_filter_choices, 'daterange_choices': [choice._asdict() for choice in get_simple_dateranges()], }
class TemplateVariable(DocumentSchema): slug = StringProperty(required=True, default='forms') type = StringProperty(required=True, choices=['form']) # todo: can extend to cases time_range = StringProperty(choices=[choice.slug for choice in get_simple_dateranges()]) # Either the case type or the form xmlns that this template variable is based on. source_id = StringProperty() # The app that the form belongs to - not currently used, but could be used in the future to prevent # duplicate XMLNSes in the same project app_id = StringProperty()
def _get_report_module_context(app, module): def _report_to_config(report): return { 'report_id': report._id, 'title': report.title, 'description': report.description, 'charts': [chart for chart in report.charts if chart.type == 'multibar'], 'filter_structure': report.filters_without_prefilters, } all_reports = ReportConfiguration.by_domain(app.domain) + \ StaticReportConfiguration.by_domain(app.domain) validity = module.check_report_validity() # We're now proactively deleting these references, so after that's been # out for a while, this can be removed (say June 2016 or later) if not validity.is_valid: module.report_configs = validity.valid_report_configs filter_choices = [ {'slug': f.doc_type, 'description': f.short_description} for f in get_all_mobile_filter_configs() ] auto_filter_choices = [ {'slug': f.slug, 'description': f.short_description} for f in get_auto_filter_configurations() ] from corehq.apps.app_manager.suite_xml.features.mobile_ucr import get_column_xpath_client_template, get_data_path data_path_placeholders = {} for r in module.report_configs: data_path_placeholders[r.report_id] = {} for chart_id in r.complete_graph_configs.keys(): data_path_placeholders[r.report_id][chart_id] = get_data_path(r, app.domain) context = { 'report_module_options': { 'moduleName': module.name, 'moduleFilter': module.module_filter, 'availableReports': [_report_to_config(r) for r in all_reports], # structure for all reports 'currentReports': [r.to_json() for r in module.report_configs], # config data for app reports 'columnXpathTemplate': get_column_xpath_client_template(app.mobile_ucr_restore_version), 'dataPathPlaceholders': data_path_placeholders, 'languages': app.langs, 'mobileUcrV1': app.mobile_ucr_restore_version == MOBILE_UCR_VERSION_1, 'globalSyncDelay': Domain.get_by_name(app.domain).default_mobile_ucr_sync_interval, }, 'static_data_options': { 'filterChoices': filter_choices, 'autoFilterChoices': auto_filter_choices, 'dateRangeOptions': [choice._asdict() for choice in get_simple_dateranges()], }, 'uuids_by_instance_id': get_uuids_by_instance_id(app.domain), 'legacy_select2': True, } return context
def _get_report_module_context(app, module): def _report_to_config(report): return { 'report_id': report._id, 'title': report.title, 'description': report.description, 'charts': [chart for chart in report.charts if chart.type == 'multibar'], 'filter_structure': report.filters_without_prefilters, } all_reports = ReportConfiguration.by_domain(app.domain) + \ StaticReportConfiguration.by_domain(app.domain) validity = module.check_report_validity() # We're now proactively deleting these references, so after that's been # out for a while, this can be removed (say June 2016 or later) if not validity.is_valid: module.report_configs = validity.valid_report_configs filter_choices = [ {'slug': f.doc_type, 'description': f.short_description} for f in get_all_mobile_filter_configs() ] auto_filter_choices = [ {'slug': f.slug, 'description': f.short_description} for f in get_auto_filter_configurations() ] from corehq.apps.app_manager.suite_xml.features.mobile_ucr import get_column_xpath_client_template, get_data_path data_path_placeholders = {} for r in module.report_configs: data_path_placeholders[r.report_id] = {} for chart_id in r.complete_graph_configs.keys(): data_path_placeholders[r.report_id][chart_id] = get_data_path(r, app.domain) context = { 'report_module_options': { 'moduleName': module.name, 'moduleFilter': module.module_filter, 'availableReports': [_report_to_config(r) for r in all_reports], # structure for all reports 'currentReports': [r.to_json() for r in module.report_configs], # config data for app reports 'columnXpathTemplate': get_column_xpath_client_template(app.mobile_ucr_restore_version), 'dataPathPlaceholders': data_path_placeholders, 'languages': app.langs, 'supportSyncDelay': app.mobile_ucr_restore_version != MOBILE_UCR_VERSION_1, 'globalSyncDelay': Domain.get_by_name(app.domain).default_mobile_ucr_sync_interval, }, 'static_data_options': { 'filterChoices': filter_choices, 'autoFilterChoices': auto_filter_choices, 'dateRangeOptions': [choice._asdict() for choice in get_simple_dateranges()], }, } return context
def page_context(self): try: report_form = self.report_form except Exception as e: self.template_name = 'userreports/report_error.html' error_response = {'error_message': '', 'details': six.text_type(e)} if self.existing_report is not None: error_response.update({ 'report_id': self.existing_report.get_id, 'is_static': self.existing_report.is_static, }) return self._handle_exception(error_response, e) field_names = report_form.fields.keys() return { 'report': { "title": self.page_name }, 'report_type': self.report_type, 'form': report_form, 'is_group_by_required': 'group_by' in field_names or 'location' in field_names, 'editing_existing_report': bool(self.existing_report), 'report_column_options': [p.to_dict() for p in report_form.report_column_options.values()], 'data_source_indicators': [p._asdict() for p in report_form.data_source_properties.values()], # For now only use date ranges that don't require additional parameters 'date_range_options': [r._asdict() for r in get_simple_dateranges()], 'initial_user_filters': [f._asdict() for f in report_form.initial_user_filters], 'initial_default_filters': [f._asdict() for f in report_form.initial_default_filters], 'initial_columns': [c._asdict() for c in getattr(report_form, 'initial_columns', [])], 'report_builder_events': self.request.session.pop(REPORT_BUILDER_EVENTS_KEY, []) }
def test_no_exceptions_on_simple_calls(self): for daterange in get_simple_dateranges(): get_daterange_start_end_dates(daterange.slug)
class PerformanceMessageEditForm(forms.Form): recipient_id = forms.CharField() schedule = forms.ChoiceField(choices=[(choice, ugettext_lazy(choice)) for choice in SCHEDULE_CHOICES]) template = forms.CharField(widget=forms.Textarea) time_range = forms.ChoiceField( choices=[(choice.slug, choice.description) for choice in get_simple_dateranges()]) 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) def clean_template(self): return _clean_template(self.cleaned_data['template']) def clean_schedule(self): # todo: support other scheduling options return ScheduleConfiguration(interval=self.cleaned_data['schedule']) def save(self, commit=True): self.config.recipient_id = self.cleaned_data['recipient_id'] self.config.schedule = self.cleaned_data['schedule'] self.config.template = self.cleaned_data['template'] template_variable = TemplateVariable( type=self.cleaned_data['source_type'], time_range=self.cleaned_data['time_range'], source_id=self.cleaned_data['source'], app_id=self.cleaned_data['application'], ) self.config.template_variables = [template_variable] if commit: self.config.save() return self.config @property def app_id(self): if self.config.template_variables: return self.config.template_variables[0].app_id return '' @property def source_id(self): if self.config.template_variables: return self.config.template_variables[0].source_id return ''