Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
djangoldp-packages
djangoldp
Commits
8ed4099a
Commit
8ed4099a
authored
10 months ago
by
Sylvain Le Bon
Browse files
Options
Downloads
Patches
Plain Diff
feature: csv export in admin
parent
f3deec52
No related branches found
No related tags found
1 merge request
!283
feature: csv export in admin
Pipeline
#17998
passed
10 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp/admin.py
+16
-3
16 additions, 3 deletions
djangoldp/admin.py
with
16 additions
and
3 deletions
djangoldp/admin.py
+
16
−
3
View file @
8ed4099a
from
csv
import
DictWriter
from
django.contrib
import
admin
from
guardian.admin
import
GuardedModelAdmin
from
django.contrib.auth.admin
import
UserAdmin
from
django.http
import
HttpResponse
from
guardian.admin
import
GuardedModelAdmin
from
djangoldp.models
import
Activity
,
ScheduledActivity
,
Follower
from
djangoldp.activities.services
import
ActivityQueueService
...
...
@@ -10,10 +12,21 @@ class DjangoLDPAdmin(GuardedModelAdmin):
An admin model representing a federated object. Inherits from GuardedModelAdmin to provide Django-Guardian
object-level permissions
'''
pass
actions
=
[
'
export_csv
'
]
@admin.action
(
description
=
"
Export CSV
"
)
def
export_csv
(
self
,
request
,
queryset
):
response
=
HttpResponse
(
content_type
=
"
text/csv
"
)
response
[
'
Content-Disposition
'
]
=
f
'
attachment; filename=
"
{
self
.
model
.
__name__
}
.csv
"'
headers
=
{
field
.
name
:
field
.
verbose_name
for
field
in
self
.
model
.
_meta
.
fields
if
field
.
name
in
self
.
list_display
}
writer
=
DictWriter
(
response
,
fieldnames
=
headers
.
keys
())
writer
.
writerow
(
headers
)
writer
.
writerows
(
queryset
.
values
(
*
headers
.
keys
()))
return
response
class
DjangoLDPUserAdmin
(
UserAdmin
,
GuardedModel
Admin
):
class
DjangoLDPUserAdmin
(
UserAdmin
,
DjangoLDP
Admin
):
'''
An extension of UserAdmin providing the functionality of DjangoLDPAdmin
'''
list_display
=
(
'
urlid
'
,
'
email
'
,
'
first_name
'
,
'
last_name
'
,
'
date_joined
'
,
'
last_login
'
,
'
is_staff
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment