Skip to content
Snippets Groups Projects
Unverified Commit f3728719 authored by ThomasBidot's avatar ThomasBidot Committed by GitHub
Browse files

Sortie thomas (export CSV sorties) (#33)


* Updated student admin filters (#28)

* Password reset feature (#8)

* Add Django Rest auth module

* Try to make the send reset password email work

* Modified template mail for reset

* Add Django Rest auth module

* Try to make the send reset password email work

* Modified template mail for reset

* test

* Added utf-8 support to exported csv and switched delimiter from , to ; in admin interface

* Disabled emails while in dev

* Added multi selection filter in admin

* Fixed mail settings

* Added year field to Tutor serializer

* Fixed year updated before registration form filled

* commit for automatic deploy

* Testing CI

* Added filtering in admin for registration validation

* Added filter to student admin

Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>

* Ajout filtre sur register

* Ajout filtre participation

* Ajout de 3 filtres par etablissements

* Ajout 3 filtres pour etablissement V2

* Ajout export CSV sorties

Co-authored-by: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>
parent 5e708651
Branches
No related tags found
6 merge requests!39Solve public permission files on AWS,!41Rectification Exportation excel sorties,!37Add context_sheet for visits,!38Add context sheet for visits V4,!30Sorties,!35Notifications for Sec-Gen
...@@ -5,6 +5,25 @@ from .models import Registration ...@@ -5,6 +5,25 @@ from .models import Registration
from profiles.models import Student from profiles.models import Student
class SchoolFilter(admin.SimpleListFilter):
title = 'établissement'
parameter_name = 'profiles__school'
def lookups(self, request, model_admin):
list_of_school = []
query = Student.objects.values_list(
"school", flat=True).distinct()
for school in query:
list_of_school.append((school, school))
return list_of_school
def queryset(self, request, queryset):
if self.value():
emails = Student.objects.filter(
school=self.value()).values_list("user__email", flat=True)
return queryset.filter(email__in=emails)
class SchoolFilter(admin.SimpleListFilter): class SchoolFilter(admin.SimpleListFilter):
title = 'établissement' title = 'établissement'
parameter_name = 'profiles__school' parameter_name = 'profiles__school'
......
...@@ -9,6 +9,8 @@ from django.http import HttpResponse ...@@ -9,6 +9,8 @@ from django.http import HttpResponse
import csv import csv
from .models import Participation, Place, Visit from .models import Participation, Place, Visit
from profiles.models import Student from profiles.models import Student
from users.models import User
import codecs
# Register your models here. # Register your models here.
...@@ -154,8 +156,6 @@ class ParticipationAdmin(admin.ModelAdmin): ...@@ -154,8 +156,6 @@ class ParticipationAdmin(admin.ModelAdmin):
list_display = ('submitted', 'visit', 'user_link', 'accepted', 'present') list_display = ('submitted', 'visit', 'user_link', 'accepted', 'present')
list_filter = (SchoolFilter, 'submitted', 'accepted', 'present') list_filter = (SchoolFilter, 'submitted', 'accepted', 'present')
actions = [accept_selected_participations, reject_selected_participations] actions = [accept_selected_participations, reject_selected_participations]
def user_link(self, participation: Participation): def user_link(self, participation: Participation):
...@@ -179,17 +179,30 @@ class ParticipationAdmin(admin.ModelAdmin): ...@@ -179,17 +179,30 @@ class ParticipationAdmin(admin.ModelAdmin):
def export_as_csv(self, request, queryset): def export_as_csv(self, request, queryset):
meta = self.model._meta meta = self.model._meta
field_names = [field.name for field in meta.fields] field_names = [field.name for field in meta.fields]
response = HttpResponse(content_type='text/csv') response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename={}.csv'.format( response['Content-Disposition'] = 'attachment; filename={}.csv'.format(
meta) meta)
writer = csv.writer(response) response.write(codecs.BOM_UTF8) # force response to be UTF-8
writer.writerow(field_names) writer = csv.writer(response, delimiter=';')
writer.writerow(['first_name', 'last_name', 'school',
'phone_number', 'scholarship'] + field_names)
list_email = queryset.values_list("user__email", flat=True)
nb_user = 0
for obj in queryset: for obj in queryset:
row = writer.writerow([getattr(obj, field)
name = User.objects.filter(
email=str(list_email[nb_user])).values('first_name', 'last_name', 'phone_number')
school = Student.objects.filter(
user__email=str(list_email[nb_user])).values('school', 'scholarship')
row = writer.writerow([name[0]['first_name'], name[0]['last_name'], school[0]['school'], name[0]['phone_number'], school[0]['scholarship']] + [getattr(obj, field)
for field in field_names]) for field in field_names])
nb_user += 1
return response return response
export_as_csv.short_description = "Exporter au format CSV"
export_as_csv.short_description = "Exporter sélection (en .csv)"
...@@ -226,6 +239,7 @@ class VisitAdmin(admin.ModelAdmin): ...@@ -226,6 +239,7 @@ class VisitAdmin(admin.ModelAdmin):
return obj.participants.count() return obj.participants.count()
num_participants.short_description = 'Participants' num_participants.short_description = 'Participants'
@admin.register(Place) @admin.register(Place)
class PlaceAdmin(admin.ModelAdmin): class PlaceAdmin(admin.ModelAdmin):
"""Admin panel for places.""" """Admin panel for places."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment