def validate(self, required=True): from corehq.apps.userreports.reports.data_source import ConfigurableReportDataSource def _check_for_duplicates(supposedly_unique_list, error_msg): # http://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-python-list duplicate_items = set([ item for item in supposedly_unique_list if supposedly_unique_list.count(item) > 1 ]) if len(duplicate_items) > 0: raise BadSpecError( _(error_msg).format(', '.join(sorted(duplicate_items)))) super(ReportConfiguration, self).validate(required) # check duplicates before passing to factory since it chokes on them _check_for_duplicates( [FilterSpec.wrap(f).slug for f in self.filters], 'Filters cannot contain duplicate slugs: {}', ) _check_for_duplicates( [ column_id for c in self.report_columns for column_id in c.get_column_ids() ], 'Columns cannot contain duplicate column_ids: {}', ) # these calls all implicitly do validation ConfigurableReportDataSource.from_spec(self) self.ui_filters self.charts self.sort_order
def validate(self, required=True): def _check_for_duplicates(supposedly_unique_list, error_msg): # http://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-python-list duplicate_items = set( [item for item in supposedly_unique_list if supposedly_unique_list.count(item) > 1] ) if len(duplicate_items) > 0: raise BadSpecError( _(error_msg).format(', '.join(sorted(duplicate_items))) ) super(ReportConfiguration, self).validate(required) # check duplicates before passing to factory since it chokes on them _check_for_duplicates( [FilterSpec.wrap(f).slug for f in self.filters], 'Filters cannot contain duplicate slugs: {}', ) _check_for_duplicates( [column_id for c in self.report_columns for column_id in c.get_column_ids()], 'Columns cannot contain duplicate column_ids: {}', ) # these calls all implicitly do validation ReportFactory.from_spec(self) self.ui_filters self.charts self.sort_order
def _build_enikshay_location_hierarchy(spec, report): wrapped = FilterSpec.wrap(spec) choice_provider = LocationChoiceProvider(report, wrapped.slug) choice_provider.configure({}) return EnikshayLocationHiearachyFilter( name=wrapped.slug, label=wrapped.get_display(), choice_provider=choice_provider, url_generator=dynamic_choice_list_url, )