def testFull(self): """Tests the creation of a form group from several forms, including added, deleted, and changed fields.""" fd2_dup = create_xsd_and_populate("data/versioning/base.2.xsd") fd3_add = create_xsd_and_populate("data/versioning/base.3.addition.xsd") fd4_del = create_xsd_and_populate("data/versioning/base.4.deletion.xsd") fd5_mod = create_xsd_and_populate("data/versioning/base.5.data_type_change.xsd") original_list = [self.original_formdef, fd2_dup, fd3_add, fd4_del, fd5_mod] dom = Domain.objects.all()[0] group = FormDataGroup.from_forms(original_list, dom) self.assertEqual(5, len(group.forms.all())) for form in group.forms.all(): self.assertTrue(form in original_list) columns = self.original_formdef.get_data_column_names() # this is added by form 3 columns.append("root_added_field") # a second one of these is added by form 5 columns.append("meta_username_2") self.assertEqual(len(columns), len(group.columns.all())) for group_column in group.columns.all(): self.assertTrue(group_column.name in columns, "%s was found in the list of columns: %s" % \ (group_column.name, columns)) for form in original_list: self._check_columns(form, group) # also make sure the view was created. query = "SELECT * from %s" % group.view_name cursor = connection.cursor() cursor.execute(query) view_cols_expected = ["form_id"] view_cols_expected.extend(columns) view_column_names = get_column_names(cursor) for view_column in view_column_names: self.assertTrue(view_column in view_cols_expected, "%s was found in the list of view columns" % \ view_column) # test deletion. orig_col_count = group.columns.count() group.remove_form(fd3_add) group = FormDataGroup.objects.get(id=group.id) self.assertEqual(group.columns.count(), orig_col_count - 1) self.assertFalse("root_added_field" in group.columns.values_list("name", flat=True)) # test adding it back group.add_form(fd3_add) group = FormDataGroup.objects.get(id=group.id) self.assertEqual(group.columns.count(), orig_col_count) columns.append("root_added_field") self.assertTrue("root_added_field" in group.columns.values_list("name", flat=True))
def form_data_group(req, group_id): group = get_object_or_404(FormDataGroup, id=group_id) items, sort_column, sort_descending, filters =\ get_table_display_properties(req,default_sort_column = None, default_sort_descending = False) cursor = group.get_data(sort_column, sort_descending) columns = get_column_names(cursor) if sort_column: sort_index = columns.index(sort_column) else: sort_index = -1 data = paginate(req, cursor.fetchall()) extra_params = "&".join(['%s=%s' % (key, value)\ for key, value in req.GET.items()\ if key != "page"]) return render_to_response(req, "xformmanager/form_data_group.html", {"group": group, "columns": columns, "data": data, "sort_column": sort_column, "sort_descending": sort_descending, "sort_index": sort_index, "extra_params": extra_params, "editing": False })