Skip to content
Snippets Groups Projects
Commit a674f1d1 authored by Dorian Lesbre's avatar Dorian Lesbre
Browse files

Fix imports

parent d63c782e
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ from shared.admin import ExportCsvMixin
admin.site.unregister(Group)
@admin.register(EmailUser)
class EmailUserAdmin(admin.ModelAdmin, ExportCsvMixin):
class EmailUserAdmin(ExportCsvMixin, admin.ModelAdmin):
"""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"]
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, ExportCsvMixin):
class InterludesActivityAdmin(ExportCsvMixin, admin.ModelAdmin):
"""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, ExportCsvMixin):
class InterludesParticipantAdmin(ExportCsvMixin, admin.ModelAdmin):
"""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, ExportCsvMixin):
class ActivityListAdmin(ExportCsvMixin, admin.ModelAdmin):
"""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"]
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
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment