Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
oser-backend
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hamza Touizrat
oser-backend
Commits
95f6ba86
Commit
95f6ba86
authored
7 years ago
by
florimondmanca
Browse files
Options
Downloads
Patches
Plain Diff
add csv download on edition form admin
parent
af1f7a46
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
dynamicforms/admin.py
+1
-1
1 addition, 1 deletion
dynamicforms/admin.py
dynamicforms/exports.py
+3
-3
3 additions, 3 deletions
dynamicforms/exports.py
dynamicforms/views.py
+4
-3
4 additions, 3 deletions
dynamicforms/views.py
projects/admin.py
+13
-0
13 additions, 0 deletions
projects/admin.py
with
21 additions
and
7 deletions
dynamicforms/admin.py
+
1
−
1
View file @
95f6ba86
...
@@ -42,7 +42,7 @@ class FormAdmin(admin.ModelAdmin):
...
@@ -42,7 +42,7 @@ class FormAdmin(admin.ModelAdmin):
def
download_csv
(
self
,
request
,
queryset
):
def
download_csv
(
self
,
request
,
queryset
):
"""
Download entries of selected forms under a ZIP file.
"""
"""
Download entries of selected forms under a ZIP file.
"""
return
download_multiple_forms_entries
(
request
,
queryset
)
return
download_multiple_forms_entries
(
request
,
forms
=
queryset
.
all
()
)
download_csv
.
short_description
=
(
download_csv
.
short_description
=
(
'
Télécharger les résponses des formulaires sélectionnés
'
)
'
Télécharger les résponses des formulaires sélectionnés
'
)
...
...
This diff is collapsed.
Click to expand it.
dynamicforms/exports.py
+
3
−
3
View file @
95f6ba86
...
@@ -53,8 +53,8 @@ def _write_csv(form: Form, stream):
...
@@ -53,8 +53,8 @@ def _write_csv(form: Form, stream):
return
stream
return
stream
def
write_zip
(
forms
_queryset
,
stream
=
None
,
folder
=
'
forms
'
):
def
write_zip
(
forms
,
stream
=
None
,
folder
=
'
forms
'
):
"""
Write form entries into a zip of CSV files.
"""
"""
Write form
s
'
entries into a zip of CSV files.
"""
if
stream
is
None
:
if
stream
is
None
:
stream
=
BytesIO
()
stream
=
BytesIO
()
# See https://stackoverflow.com/a/32075279
# See https://stackoverflow.com/a/32075279
...
@@ -63,7 +63,7 @@ def write_zip(forms_queryset, stream=None, folder='forms'):
...
@@ -63,7 +63,7 @@ def write_zip(forms_queryset, stream=None, folder='forms'):
'
consider using BytesIO instead
'
'
consider using BytesIO instead
'
)
)
with
zipfile
.
ZipFile
(
stream
,
'
w
'
)
as
zip
:
with
zipfile
.
ZipFile
(
stream
,
'
w
'
)
as
zip
:
for
form
in
forms
_queryset
:
for
form
in
forms
:
csv_file
=
StringIO
()
csv_file
=
StringIO
()
_write_csv
(
form
,
csv_file
)
_write_csv
(
form
,
csv_file
)
csv_filename
=
os
.
path
.
join
(
folder
,
f
'
{
form
.
slug
}
.csv
'
)
csv_filename
=
os
.
path
.
join
(
folder
,
f
'
{
form
.
slug
}
.csv
'
)
...
...
This diff is collapsed.
Click to expand it.
dynamicforms/views.py
+
4
−
3
View file @
95f6ba86
...
@@ -28,12 +28,13 @@ class FormEntryViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
...
@@ -28,12 +28,13 @@ class FormEntryViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
queryset
=
FormEntry
.
objects
.
all
()
queryset
=
FormEntry
.
objects
.
all
()
def
download_multiple_forms_entries
(
request
,
queryset
):
def
download_multiple_forms_entries
(
request
,
forms
):
"""
Download form entries in a ZIP file containing CSV files.
"""
Download form entries in a ZIP file containing CSV files.
Note: this is not a proper Django view as it expects a queryset.
Note: this is not a proper Django view as it expects an iterable of
Form objects (typically a queryset).
"""
"""
stream
=
write_zip
(
queryset
,
folder
=
'
reponses
'
)
stream
=
write_zip
(
forms
=
forms
,
folder
=
'
reponses
'
)
stream
.
seek
(
0
)
stream
.
seek
(
0
)
contents
=
stream
.
read
()
contents
=
stream
.
read
()
filename
=
'
responses.zip
'
filename
=
'
responses.zip
'
...
...
This diff is collapsed.
Click to expand it.
projects/admin.py
+
13
−
0
View file @
95f6ba86
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
from
django.contrib
import
admin
from
django.contrib
import
admin
from
dynamicforms.views
import
download_multiple_forms_entries
from
dynamicforms.models
import
Form
from
.models
import
Edition
,
Participation
,
Project
,
EditionForm
from
.models
import
Edition
,
Participation
,
Project
,
EditionForm
...
@@ -78,6 +80,17 @@ class EditionFormAdmin(admin.ModelAdmin):
...
@@ -78,6 +80,17 @@ class EditionFormAdmin(admin.ModelAdmin):
list_display
=
(
'
form
'
,
'
deadline
'
,
'
recipient
'
,)
list_display
=
(
'
form
'
,
'
deadline
'
,
'
recipient
'
,)
list_filter
=
(
'
edition
'
,
'
deadline
'
,)
list_filter
=
(
'
edition
'
,
'
deadline
'
,)
actions
=
[
'
download_csv
'
]
def
download_csv
(
self
,
request
,
queryset
):
"""
Download entries of selected edition forms under a ZIP file.
"""
form_ids
=
queryset
.
values_list
(
'
form__id
'
,
flat
=
True
)
forms
=
Form
.
objects
.
filter
(
id__in
=
form_ids
)
return
download_multiple_forms_entries
(
request
,
forms
=
forms
)
download_csv
.
short_description
=
(
'
Télécharger les résponses des formulaires sélectionnés
'
)
@admin.register
(
Participation
)
@admin.register
(
Participation
)
class
ParticipationAdmin
(
admin
.
ModelAdmin
):
class
ParticipationAdmin
(
admin
.
ModelAdmin
):
...
...
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