Skip to content

Commit 4a18e56

Browse files
authored
Include internal category in filter and limit exported fields (#1301)
1 parent 80b74e5 commit 4a18e56

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

apps/dot_ext/admin.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ def clean_agree(self):
9191
class MyApplicationAdmin(admin.ModelAdmin, ExportCsvMixin):
9292
form = CustomAdminApplicationForm
9393

94-
def get_fieldsets(self, request, obj=None):
95-
fieldsets = super().get_fieldsets(request, obj)
96-
return fieldsets
97-
9894
def get_list_display(self, request):
9995
return (
10096
"name",
@@ -115,6 +111,7 @@ def get_list_display(self, request):
115111
"require_demographic_scopes",
116112
"active",
117113
"skip_authorization",
114+
"internal_application_labels",
118115
)
119116

120117
radio_fields = {
@@ -133,6 +130,29 @@ def get_search_fields(self, request):
133130
"=authorization_grant_type",
134131
)
135132

133+
def get_export_fields(self, request):
134+
return (
135+
"id",
136+
"user",
137+
"name",
138+
"created",
139+
"website_uri",
140+
"redirect_uris",
141+
"logo_uri",
142+
"tos_uri",
143+
"policy_uri",
144+
"contacts",
145+
"support_email",
146+
"support_phone_number",
147+
"description",
148+
"active",
149+
"first_active",
150+
"last_active",
151+
"require_demographic_scopes",
152+
"data_access_type",
153+
"internal_application_labels",
154+
)
155+
136156
raw_id_fields = ("user",)
137157

138158
actions = ["export_as_csv"]

apps/dot_ext/csv.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ class ExportCsvMixin:
1111
"""
1212
def export_as_csv(self, request, queryset):
1313

14-
meta = self.model._meta
15-
field_names = [field.name for field in meta.fields]
14+
def get_value(obj, key):
15+
if key == "internal_application_labels":
16+
return getattr(obj, key).all()
17+
return getattr(obj, key)
18+
19+
export_fields = self.get_export_fields(None)
1620

1721
response = HttpResponse(content_type='text/csv')
18-
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
22+
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(self.model._meta)
1923
writer = csv.writer(response)
2024

21-
writer.writerow(field_names)
25+
writer.writerow(export_fields)
2226
for obj in queryset:
23-
writer.writerow([getattr(obj, field) for field in field_names])
27+
writer.writerow([get_value(obj, field) for field in export_fields])
2428

2529
return response
2630

apps/dot_ext/fixtures/internal_application_labels.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"model": "dot_ext.internalapplicationlabels",
4949
"pk": 7,
5050
"fields": {
51-
"label": "Medication managementz",
52-
"slug": "medication-managementz",
51+
"label": "Medication management",
52+
"slug": "medication-management",
5353
"description": "Desc: place holder"
5454
}
5555
},

0 commit comments

Comments
 (0)