Preserve column ordering
This commit is contained in:
parent
bf88d232fb
commit
3abadf0516
@ -823,6 +823,22 @@ class SavedViewSerializer(OwnedObjectSerializer):
|
||||
"set_permissions",
|
||||
]
|
||||
|
||||
def to_internal_value(self, data):
|
||||
value = super().to_internal_value(data)
|
||||
# MultipleChoiceField doesn't preserve order, so we revert the dict to the original array
|
||||
if "dashboard_view_table_columns" in data:
|
||||
value["dashboard_view_table_columns"] = data["dashboard_view_table_columns"]
|
||||
return value
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
# MultipleChoiceField doesn't preserve order, so we re-order the array to match the original order
|
||||
if "dashboard_view_table_columns" in representation:
|
||||
representation["dashboard_view_table_columns"] = [
|
||||
str(x) for x in instance.dashboard_view_table_columns
|
||||
]
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
if "filter_rules" in validated_data:
|
||||
rules_data = validated_data.pop("filter_rules")
|
||||
|
@ -1534,6 +1534,62 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
v1 = SavedView.objects.get(id=v1.id)
|
||||
self.assertEqual(v1.filter_rules.count(), 0)
|
||||
|
||||
def test_saved_view_dashboard_view_options(self):
|
||||
User.objects.create_user("user1")
|
||||
|
||||
view = {
|
||||
"name": "test",
|
||||
"show_on_dashboard": True,
|
||||
"show_in_sidebar": True,
|
||||
"sort_field": "created2",
|
||||
"filter_rules": [{"rule_type": 4, "value": "test"}],
|
||||
"dashboard_view_limit": 20,
|
||||
"dashboard_view_mode": SavedView.DashboardViewDisplayMode.SMALL_CARDS,
|
||||
"dashboard_view_table_columns": [
|
||||
SavedView.DashboardViewTableColumns.TITLE,
|
||||
SavedView.DashboardViewTableColumns.CREATED,
|
||||
],
|
||||
}
|
||||
|
||||
response = self.client.post("/api/saved_views/", view, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
v1 = SavedView.objects.get(name="test")
|
||||
self.assertEqual(v1.dashboard_view_limit, 20)
|
||||
self.assertEqual(
|
||||
v1.dashboard_view_mode,
|
||||
SavedView.DashboardViewDisplayMode.SMALL_CARDS,
|
||||
)
|
||||
self.assertEqual(
|
||||
v1.dashboard_view_table_columns,
|
||||
[
|
||||
SavedView.DashboardViewTableColumns.TITLE,
|
||||
SavedView.DashboardViewTableColumns.CREATED,
|
||||
],
|
||||
)
|
||||
|
||||
response = self.client.patch(
|
||||
f"/api/saved_views/{v1.id}/",
|
||||
{
|
||||
"dashboard_view_table_columns": [
|
||||
SavedView.DashboardViewTableColumns.TAGS,
|
||||
SavedView.DashboardViewTableColumns.TITLE,
|
||||
SavedView.DashboardViewTableColumns.CREATED,
|
||||
],
|
||||
},
|
||||
format="json",
|
||||
)
|
||||
|
||||
v1.refresh_from_db()
|
||||
self.assertEqual(
|
||||
v1.dashboard_view_table_columns,
|
||||
[
|
||||
SavedView.DashboardViewTableColumns.TAGS,
|
||||
SavedView.DashboardViewTableColumns.TITLE,
|
||||
SavedView.DashboardViewTableColumns.CREATED,
|
||||
],
|
||||
)
|
||||
|
||||
def test_get_logs(self):
|
||||
log_data = "test\ntest2\n"
|
||||
with open(os.path.join(settings.LOGGING_DIR, "mail.log"), "w") as f:
|
||||
|
Loading…
x
Reference in New Issue
Block a user