mirror of
https://github.com/umap-project/umap.git
synced 2025-05-01 12:32:23 +02:00
chore: display user maps in admin and add in csv export (#2169)
maps are owned maps + maps as editor cf https://github.com/umap-project/umap/pull/2131#discussion_r1772775039
This commit is contained in:
commit
4b4546991a
1 changed files with 12 additions and 1 deletions
|
@ -22,10 +22,15 @@ class CSVExportMixin:
|
||||||
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
|
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_cell(user, field):
|
||||||
|
if hasattr(self, field):
|
||||||
|
return getattr(self, field)(user)
|
||||||
|
return getattr(user, field)
|
||||||
|
|
||||||
writer = csv.writer(response)
|
writer = csv.writer(response)
|
||||||
writer.writerow(self.csv_fields)
|
writer.writerow(self.csv_fields)
|
||||||
for user in queryset:
|
for user in queryset:
|
||||||
writer.writerow(getattr(user, field) for field in self.csv_fields)
|
writer.writerow(get_cell(user, field) for field in self.csv_fields)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +82,13 @@ class UserAdmin(CSVExportMixin, UserAdminBase):
|
||||||
"last_name",
|
"last_name",
|
||||||
"last_login",
|
"last_login",
|
||||||
"date_joined",
|
"date_joined",
|
||||||
|
"maps_count",
|
||||||
]
|
]
|
||||||
|
list_display = list(UserAdminBase.list_display) + ["maps_count"]
|
||||||
|
|
||||||
|
def maps_count(self, obj):
|
||||||
|
# owner maps + maps as editor
|
||||||
|
return obj.owned_maps.count() + obj.map_set.count()
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Map, MapAdmin)
|
admin.site.register(Map, MapAdmin)
|
||||||
|
|
Loading…
Reference in a new issue