Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
site-kwei
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aeltheos
site-kwei
Commits
a674f1d1
Commit
a674f1d1
authored
4 years ago
by
Dorian Lesbre
Browse files
Options
Downloads
Patches
Plain Diff
Fix imports
parent
d63c782e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
accounts/admin.py
+3
-2
3 additions, 2 deletions
accounts/admin.py
home/admin.py
+3
-8
3 additions, 8 deletions
home/admin.py
shared/admin.py
+13
-1
13 additions, 1 deletion
shared/admin.py
shared/forms.py
+1
-1
1 addition, 1 deletion
shared/forms.py
with
20 additions
and
12 deletions
accounts/admin.py
+
3
−
2
View file @
a674f1d1
...
...
@@ -8,7 +8,7 @@ from shared.admin import ExportCsvMixin
admin
.
site
.
unregister
(
Group
)
@admin.register
(
EmailUser
)
class
EmailUserAdmin
(
admin
.
ModelAdmin
,
ExportCsvMix
in
):
class
EmailUserAdmin
(
ExportCsvMixin
,
admin
.
ModelAdm
in
):
"""
option d
'
affichage des activités dans la vue django admin
"""
list_display
=
(
"
email
"
,
"
last_name
"
,
"
first_name
"
,
"
is_superuser
"
,
"
is_active
"
,
"
email_confirmed
"
,)
list_filter
=
(
"
is_superuser
"
,
"
is_active
"
,
"
email_confirmed
"
,)
...
...
@@ -19,4 +19,5 @@ class EmailUserAdmin(admin.ModelAdmin, ExportCsvMixin):
ordering
=
(
"
last_name
"
,
"
first_name
"
)
readonly_fields
=
(
"
date_joined
"
,
"
last_login
"
,)
list_per_page
=
200
actions
=
[
"
export_as_csv
"
]
csv_export_exclude
=
[
"
password
"
]
This diff is collapsed.
Click to expand it.
home/admin.py
+
3
−
8
View file @
a674f1d1
import
csv
from
django.contrib
import
admin
from
django.http
import
HttpResponse
from
home.models
import
InterludesActivity
,
InterludesParticipant
,
ActivityList
from
shared.admin
import
ExportCsvMixin
...
...
@@ -12,29 +10,26 @@ admin.site.site_title = "Admin Interludes"
@admin.register
(
InterludesActivity
)
class
InterludesActivityAdmin
(
admin
.
ModelAdmin
,
ExportCsvMix
in
):
class
InterludesActivityAdmin
(
ExportCsvMixin
,
admin
.
ModelAdm
in
):
"""
option d
'
affichage des activités dans la vue django admin
"""
list_display
=
(
"
title
"
,
"
host_name
"
,
"
display
"
,
"
must_subscribe
"
,
"
on_planning
"
)
list_filter
=
(
"
display
"
,
"
must_subscribe
"
,
"
on_planning
"
)
ordering
=
(
"
title
"
,
"
host_name
"
,)
list_editable
=
(
"
display
"
,)
list_per_page
=
100
actions
=
[
"
export_as_csv
"
]
@admin.register
(
InterludesParticipant
)
class
InterludesParticipantAdmin
(
admin
.
ModelAdmin
,
ExportCsvMix
in
):
class
InterludesParticipantAdmin
(
ExportCsvMixin
,
admin
.
ModelAdm
in
):
"""
option d
'
affichage des participant dans la vue django admin
"""
list_display
=
(
"
user
"
,
"
school
"
,
"
is_registered
"
)
list_filter
=
(
"
school
"
,
"
is_registered
"
)
ordering
=
(
"
user
"
,)
list_per_page
=
200
actions
=
[
"
export_as_csv
"
]
@admin.register
(
ActivityList
)
class
ActivityListAdmin
(
admin
.
ModelAdmin
,
ExportCsvMix
in
):
class
ActivityListAdmin
(
ExportCsvMixin
,
admin
.
ModelAdm
in
):
"""
option d
'
affichage des choix d
'
activités dans la vue django admin
"""
list_display
=
(
"
participant
"
,
"
priority
"
,
"
activity
"
,)
list_filter
=
(
"
activity
"
,
"
participant
"
,)
ordering
=
(
"
participant
"
,
"
priority
"
,)
list_per_page
=
200
actions
=
[
"
export_as_csv
"
]
This diff is collapsed.
Click to expand it.
shared/admin.py
+
13
−
1
View file @
a674f1d1
import
csv
from
django.http
import
HttpResponse
class
ExportCsvMixin
:
"""
class abstraite pour permettre l
'
export CSV rapide d
'
un modele
"""
"""
class abstraite pour permettre l
'
export CSV rapide d
'
un modele
utiliser csv_export_exclude pour exclure des colonnes du fichier généré
"""
def
export_as_csv
(
self
,
request
,
queryset
):
"""
renvoie un fichier CSV contenant l
'
information du queryset
"""
meta
=
self
.
model
.
_meta
field_names
=
[
field
.
name
for
field
in
meta
.
fields
]
if
self
.
csv_export_exclude
:
field_names
=
[
field
for
field
in
field_names
if
not
field
in
self
.
csv_export_exclude
]
response
=
HttpResponse
(
content_type
=
'
text/csv
'
)
response
[
'
Content-Disposition
'
]
=
'
attachment; filename={}.csv
'
.
format
(
meta
)
writer
=
csv
.
writer
(
response
)
...
...
@@ -17,3 +26,6 @@ class ExportCsvMixin:
return
response
export_as_csv
.
short_description
=
"
Exporter au format CSV
"
actions
=
[
"
export_as_csv
"
]
csv_export_exclude
=
None
This diff is collapsed.
Click to expand it.
shared/forms.py
+
1
−
1
View file @
a674f1d1
from
django.utils.safestring
import
mark_safe
class
FormRenderMixin
:
"""
A mixin that can be included in any form to make it render to html as we want
...
...
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