summaryrefslogtreecommitdiff
path: root/ishtar_common/admin.py
diff options
context:
space:
mode:
authorCefin <kevon@tuta.io>2022-03-24 16:16:16 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-07-08 09:58:50 +0200
commit993da19467e202e35dc253ee7326d62b8734b7ca (patch)
tree85972943257d5bfffea6bf3f9482fa2eb1f693ef /ishtar_common/admin.py
parent425e9ffda520ae717ea84319449a748cae866dd2 (diff)
downloadIshtar-993da19467e202e35dc253ee7326d62b8734b7ca.tar.bz2
Ishtar-993da19467e202e35dc253ee7326d62b8734b7ca.zip
Admin - Export - CSV: Standardise csv exports of typologies (refs #5251)
Diffstat (limited to 'ishtar_common/admin.py')
-rw-r--r--ishtar_common/admin.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index d1a598356..f5729d9de 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -168,6 +168,18 @@ def export_as_csv_action(
excludeset = set(exclude)
field_names = field_names - excludeset
+ if hasattr(modeladmin, "CSV_FIELD_ORDER"):
+ field_order = modeladmin.CSV_FIELD_ORDER
+ def sort_csv(value):
+ if value not in field_order:
+ return 1000
+ else:
+ return field_order.index(value)
+
+ field_names = sorted(
+ field_names, key=sort_csv
+ )
+
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = "attachment; filename=%s.csv" % str(
opts
@@ -198,7 +210,6 @@ def export_as_csv_action(
export_as_csv.short_description = description
return export_as_csv
-
def export_as_geojson_action(
geometry_field,
description=_("Export selected as GeoJSON file"),
@@ -1056,6 +1067,15 @@ class GeneralTypeAdmin(ChangeParentAdmin, ImportActionAdmin, ImportJSONActionAdm
prepopulated_fields = {"txt_idx": ("label",)}
LIST_DISPLAY = ["label", "txt_idx", "available", "comment"]
extra_list_display = []
+ CSV_FIELD_ORDER = [
+ "id",
+ "label",
+ "txt_idx",
+ "parent",
+ "order",
+ "available",
+ "comment",
+ ]
def get_list_display(self, request):
list_display = list(self.LIST_DISPLAY)[:]