summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/admin.py10
-rw-r--r--ishtar_common/admin.py22
2 files changed, 31 insertions, 1 deletions
diff --git a/archaeological_finds/admin.py b/archaeological_finds/admin.py
index 17ac6d49b..717422573 100644
--- a/archaeological_finds/admin.py
+++ b/archaeological_finds/admin.py
@@ -222,6 +222,16 @@ class TreatmentTypeAdmin(GeneralTypeAdmin):
'change_current_location', 'restore_reference_location'
]
model = models.TreatmentType
+ CSV_FIELD_ORDER = [
+ "virtual",
+ "destructive",
+ "create_new_find",
+ "upstream_is_many",
+ "downstream_is_many",
+ "change_reference_location",
+ "change_current_location",
+ "restore_reference_location",
+ ]
def get_list_display(self, request):
list_display = super(TreatmentTypeAdmin, self).get_list_display(request)
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)[:]