def update_custom_export(self): """ Updates custom_export object from the request and saves to the db """ post_data = self.post_data custom_export_json = post_data['custom_export'] if post_data['presave'] and not self.allow_daily_saved: raise BadExportConfiguration(_("This user does not have permission to create Daily Saved Exports")) if custom_export_json['default_format'] == "html" and not self.allow_excel_dashboard: raise BadExportConfiguration(_("This user does not have permission to create an excel dashboard")) if custom_export_json["is_safe"] and not self.allow_deid: raise BadExportConfiguration(_("This user does not have permission to create a de-identified export")) SAFE_KEYS = ('default_format', 'is_safe', 'name', 'schema_id', 'transform_dates') for key in SAFE_KEYS: self.custom_export[key] = custom_export_json[key] # update the custom export index (to stay in sync) schema_id = self.custom_export.schema_id schema = ExportSchema.get(schema_id) self.custom_export.index = schema.index self.presave = post_data['presave'] self.export_stock = post_data['export_stock'] self.custom_export.tables = [ ExportTable.wrap(table) for table in custom_export_json['tables'] ] table_dict = dict((t.index, t) for t in self.custom_export.tables) for table in self.custom_export.tables: if table.index in table_dict: table_dict[table.index].columns = table.columns else: self.custom_export.tables.append( ExportTable( index=table.index, display=self.custom_export.name, columns=table.columns ) ) self.update_custom_params() self.custom_export.custom_validate() self.custom_export.save() touch_exports(self.domain) if self.presave: HQGroupExportConfiguration.add_custom_export(self.domain, self.custom_export.get_id) else: HQGroupExportConfiguration.remove_custom_export(self.domain, self.custom_export.get_id) return self.custom_export.get_id
def update_custom_export(self): """ Updates custom_export object from the request and saves to the db """ post_data = self.post_data custom_export_json = post_data['custom_export'] if post_data['presave'] and not self.allow_daily_saved: raise BadExportConfiguration(_("This user does not have permission to create Daily Saved Exports")) if custom_export_json['default_format'] == "html" and not self.allow_excel_dashboard: raise BadExportConfiguration(_("This user does not have permission to create an excel dashboard")) if custom_export_json["is_safe"] and not self.allow_deid: raise BadExportConfiguration(_("This user does not have permission to create a de-identified export")) SAFE_KEYS = ('default_format', 'is_safe', 'name', 'schema_id', 'transform_dates') for key in SAFE_KEYS: self.custom_export[key] = custom_export_json[key] # update the custom export index (to stay in sync) schema_id = self.custom_export.schema_id schema = ExportSchema.get(schema_id) self.custom_export.index = schema.index self.presave = post_data['presave'] self.export_stock = post_data['export_stock'] self.custom_export.tables = [ ExportTable.wrap(table) for table in custom_export_json['tables'] ] table_dict = dict((t.index, t) for t in self.custom_export.tables) for table in self.custom_export.tables: if table.index in table_dict: table_dict[table.index].columns = table.columns else: self.custom_export.tables.append( ExportTable( index=table.index, display=self.custom_export.name, columns=table.columns ) ) self.update_custom_params() self.custom_export.custom_validate() self.custom_export.save() touch_exports(self.domain) if self.presave: HQGroupExportConfiguration.add_custom_export(self.domain, self.custom_export.get_id) else: HQGroupExportConfiguration.remove_custom_export(self.domain, self.custom_export.get_id) return self.custom_export.get_id
def update_custom_export(self): """ Updates custom_export object from the request and saves to the db """ schema = ExportSchema.get(self.request.POST["schema"]) self.custom_export.index = schema.index self.custom_export.schema_id = self.request.POST["schema"] self.custom_export.name = self.request.POST["name"] self.custom_export.default_format = self.request.POST["format"] or Format.XLS_2007 self.custom_export.is_safe = bool(self.request.POST.get('is_safe')) self.presave = bool(self.request.POST.get('presave')) table = self.request.POST["table"] cols = self.request.POST['order'].strip().split() @list @inline def export_cols(): for col in cols: transform = self.request.POST.get('%s transform' % col) or None if transform: transform = SerializableFunction.loads(transform) yield ExportColumn( index=col, display=self.request.POST["%s display" % col], transform=transform ) export_table = ExportTable(index=table, display=self.request.POST["name"], columns=export_cols) self.custom_export.tables = [export_table] self.custom_export.order = cols table_dict = dict([t.index, t] for t in self.custom_export.tables) if table in table_dict: table_dict[table].columns = export_cols else: self.custom_export.tables.append(ExportTable(index=table, display=self.custom_export.name, columns=export_cols)) if self.export_type == 'form': self.custom_export.include_errors = bool(self.request.POST.get("include-errors")) self.custom_export.app_id = self.request.POST.get('app_id') self.custom_export.save() if self.presave: HQGroupExportConfiguration.add_custom_export(self.domain, self.custom_export.get_id) else: HQGroupExportConfiguration.remove_custom_export(self.domain, self.custom_export.get_id)
def update_custom_export(self): """ Updates custom_export object from the request and saves to the db """ post_data = self.post_data custom_export_json = post_data['custom_export'] SAFE_KEYS = ('default_format', 'is_safe', 'name', 'schema_id', 'transform_dates') for key in SAFE_KEYS: self.custom_export[key] = custom_export_json[key] # update the custom export index (to stay in sync) schema_id = self.custom_export.schema_id schema = ExportSchema.get(schema_id) self.custom_export.index = schema.index self.presave = post_data['presave'] self.export_stock = post_data['export_stock'] self.custom_export.tables = [ ExportTable.wrap(table) for table in custom_export_json['tables'] ] table_dict = dict((t.index, t) for t in self.custom_export.tables) for table in self.custom_export.tables: if table.index in table_dict: table_dict[table.index].columns = table.columns else: self.custom_export.tables.append( ExportTable( index=table.index, display=self.custom_export.name, columns=table.columns ) ) self.update_custom_params() self.custom_export.custom_validate() self.custom_export.save() touch_exports(self.domain) if self.presave: HQGroupExportConfiguration.add_custom_export(self.domain, self.custom_export.get_id) else: HQGroupExportConfiguration.remove_custom_export(self.domain, self.custom_export.get_id) return self.custom_export.get_id
def update_custom_export(self): """ Updates custom_export object from the request and saves to the db """ post_data = self.post_data custom_export_json = post_data['custom_export'] SAFE_KEYS = ('default_format', 'is_safe', 'name', 'schema_id', 'transform_dates') for key in SAFE_KEYS: self.custom_export[key] = custom_export_json[key] # update the custom export index (to stay in sync) schema_id = self.custom_export.schema_id schema = ExportSchema.get(schema_id) self.custom_export.index = schema.index self.presave = post_data['presave'] self.export_stock = post_data['export_stock'] self.custom_export.tables = [ ExportTable.wrap(table) for table in custom_export_json['tables'] ] table_dict = dict((t.index, t) for t in self.custom_export.tables) for table in self.custom_export.tables: if table.index in table_dict: table_dict[table.index].columns = table.columns else: self.custom_export.tables.append( ExportTable( index=table.index, display=self.custom_export.name, columns=table.columns ) ) self.update_custom_params() self.custom_export.custom_validate() self.custom_export.save() touch_exports(self.domain) if self.presave: HQGroupExportConfiguration.add_custom_export(self.domain, self.custom_export.get_id) else: HQGroupExportConfiguration.remove_custom_export(self.domain, self.custom_export.get_id) return self.custom_export.get_id
def test_daily_saved_conversion(self, _): # ID is from corehq/apps/export/tests/data/saved_export_schemas/case.json self.group_config = HQGroupExportConfiguration.add_custom_export( self.domain, '92e5f9a6624a637c2080957475cd446d') self.group_config.save() self.addCleanup(self.group_config.delete) instance, _ = self._convert_case_export('case') self.assertEqual(instance.transform_dates, True) self.assertEqual(instance.name, 'Case Example') self.assertEqual(instance.export_format, 'csv') self.assertEqual(instance.is_deidentified, False) self.assertEqual(instance.is_daily_saved_export, True) table = instance.get_table(MAIN_TABLE) self.assertEqual(table.label, 'Cases') self.assertTrue(table.selected) index, column = table.get_column([PathNode(name='DOB')], 'ExportItem', None) self.assertEqual(column.label, 'DOB Saved') self.assertEqual(column.selected, True)
def test_daily_saved_conversion(self, _): # ID is from corehq/apps/export/tests/data/saved_export_schemas/case.json self.group_config = HQGroupExportConfiguration.add_custom_export( self.domain, "92e5f9a6624a637c2080957475cd446d" ) self.group_config.save() self.addCleanup(self.group_config.delete) instance, _ = self._convert_case_export("case") self.assertEqual(instance.transform_dates, True) self.assertEqual(instance.name, "Case Example") self.assertEqual(instance.export_format, "csv") self.assertEqual(instance.is_deidentified, False) self.assertEqual(instance.is_daily_saved_export, True) table = instance.get_table(MAIN_TABLE) self.assertEqual(table.label, "Cases") self.assertTrue(table.selected) index, column = table.get_column([PathNode(name="DOB")], "ExportItem", None) self.assertEqual(column.label, "DOB Saved") self.assertEqual(column.selected, True)