From 0373cc04e85db4f08ccf104c6226b96d5e105233 Mon Sep 17 00:00:00 2001 From: ThomasBidot <77505438+ThomasBidot@users.noreply.github.com> Date: Sun, 26 Sep 2021 14:37:06 +0200 Subject: [PATCH] Solve public permission files on AWS (#40) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Added school info * Fixed typo in filters * Sorties (#30) * Custom participation_inline css * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Sortie thomas (#32) * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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 Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Update runtime.txt Changement version python * Ordering students by updated_date * Notifications for Sec-Gen (#35) * Custom participation_inline css * Ajout filtre sur register * Ajout filtre participation * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Sortie thomas (#32) * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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 Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Ajout export CSV sorties * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> * Erreurs dans visits/admin résolus * Notifications for Sec-Gen Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Add context_sheet for visits (#37) * Custom participation_inline css * Ajout filtre sur register * Ajout filtre participation * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Sortie thomas (#32) * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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 Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Ajout export CSV sorties * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> * Erreurs dans visits/admin résolus * Notifications for Sec-Gen * Add conext_sheet for visits * Add context_sheet for visits V2 * Add context_sheet for visits V3 Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Add context sheet for visits V4 (#38) * Custom participation_inline css * Ajout filtre sur register * Ajout filtre participation * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Sortie thomas (#32) * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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 Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Ajout export CSV sorties * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> * Erreurs dans visits/admin résolus * Notifications for Sec-Gen * Add conext_sheet for visits * Add context_sheet for visits V2 * Add context_sheet for visits V3 * Add context_sheet for visits V4 Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Version correction of psycopg2 and tornado * Solve public permission files on AWS (#39) * Custom participation_inline css * Ajout filtre sur register * Ajout filtre participation * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Sortie thomas (#32) * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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 Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> * Ajout export CSV sorties * 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: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur 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: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> * Erreurs dans visits/admin résolus * Notifications for Sec-Gen * Add conext_sheet for visits * Add context_sheet for visits V2 * Add context_sheet for visits V3 * Add context_sheet for visits V4 * Solve public permission files on AWS Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> Co-authored-by: chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by: florimondmanca <florimond.manca@gmail.com> Co-authored-by: Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by: Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by: Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by: Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by: Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by: Witeden <58004019+Witeden@users.noreply.github.com> --- aws/conf.py | 4 +++ projects/admin.py | 35 +++++++++++++++++++ tests/test_visits/test_visit.py | 5 +++ tests/test_visits/test_visit_api.py | 2 +- visits/admin.py | 8 +++-- visits/migrations/0002_visit_context_sheet.py | 18 ++++++++++ visits/models.py | 6 ++++ visits/serializers.py | 2 +- 8 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 visits/migrations/0002_visit_context_sheet.py diff --git a/aws/conf.py b/aws/conf.py index e7bf2e4..0553c51 100644 --- a/aws/conf.py +++ b/aws/conf.py @@ -51,3 +51,7 @@ MEDIA_URL = 'https://' + AWS_S3_CUSTOM_DOMAIN + 'media/' # Direct the MEDIA_ROOT to the media/ directory inside the bucket MEDIA_ROOT = 'media' + +# ACL for public read +AWS_DEFAULT_ACL = "public-read" +ACL = 'public-read' diff --git a/projects/admin.py b/projects/admin.py index e43c198..cbac65e 100644 --- a/projects/admin.py +++ b/projects/admin.py @@ -7,6 +7,11 @@ from dynamicforms.models import Form from .models import Edition, Participation, Project, EditionForm from django.contrib.admin import SimpleListFilter from profiles.models import Student +from django.http import HttpResponse +import csv +from users.models import User +import codecs + @admin.register(Project) @@ -106,6 +111,36 @@ class EditionFormAdmin(admin.ModelAdmin): class ParticipationAdmin(admin.ModelAdmin): """Participation admin panel.""" + def export_as_csv(self, request, queryset): + meta = self.model._meta + field_names = [field.name for field in meta.fields] + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment; filename={}.csv'.format( + meta) + response.write(codecs.BOM_UTF8) # force response to be UTF-8 + writer = csv.writer(response, delimiter=';') + + writer.writerow(['first_name', 'last_name', 'school', 'grade', + 'phone_number', 'scholarship'] + field_names) + + list_email = queryset.values_list("user__email", flat=True) + nb_user = 0 + for obj in queryset: + + 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', 'grade', 'scholarship') + + row = writer.writerow([name[0]['first_name'], name[0]['last_name'], school[0]['school'], school[0]['grade'], name[0]['phone_number'], school[0]['scholarship']] + [getattr(obj, field) + for field in field_names]) + nb_user += 1 + return response + + export_as_csv.short_description = "Exporter sélection (en .csv)" + + actions = ["export_as_csv"] + list_display = ('user', 'edition', 'submitted', 'state') list_filter = (SchoolFilter, 'edition', 'submitted', 'state',) diff --git a/tests/test_visits/test_visit.py b/tests/test_visits/test_visit.py index 8ed10cd..f46d806 100644 --- a/tests/test_visits/test_visit.py +++ b/tests/test_visits/test_visit.py @@ -54,6 +54,11 @@ class VisitTest(ModelTestCase): 'blank': True, 'null': True, }, + 'context_sheet': { + 'verbose_name': 'fiche contexte', + 'blank': True, + 'null': True, + }, 'permission': { 'verbose_name': 'autorisation de sortie', 'blank': True, diff --git a/tests/test_visits/test_visit_api.py b/tests/test_visits/test_visit_api.py index 5dba15e..e1a02a8 100644 --- a/tests/test_visits/test_visit_api.py +++ b/tests/test_visits/test_visit_api.py @@ -63,5 +63,5 @@ class VisitSerializerTestCase(SerializerTestCaseMixin, TestCase): 'place', 'date', 'start_time', 'end_time', 'meeting', 'passed', 'deadline', 'registrations_open', 'participants', 'organizers', - 'image', 'fact_sheet', 'permission', + 'image', 'fact_sheet', 'context_sheet', 'permission', ) diff --git a/visits/admin.py b/visits/admin.py index 6ca578e..682f570 100644 --- a/visits/admin.py +++ b/visits/admin.py @@ -110,6 +110,8 @@ class ParticipationInline(admin.TabularInline): school = Student.objects.get(user = participation.user).school return school school.short_description = "Établissement" + + def name(self, participation: Participation): """Returns the participation's user's name""" return participation.user.first_name + " " + participation.user.last_name @@ -166,7 +168,6 @@ class ParticipationAdmin(admin.ModelAdmin): actions = ["export_as_csv"] - def school(self, participation: Participation): """Return a link to the participation's user's school.""" school = Student.objects.get(user=participation.user).school @@ -182,7 +183,8 @@ class ParticipationAdmin(admin.ModelAdmin): response.write(codecs.BOM_UTF8) # force response to be UTF-8 writer = csv.writer(response, delimiter=';') - writer.writerow(['first_name', 'last_name', 'school', + + writer.writerow(['first_name', 'last_name', 'school', 'grade', 'phone_number', 'scholarship'] + field_names) list_email = queryset.values_list("user__email", flat=True) @@ -196,6 +198,7 @@ class ParticipationAdmin(admin.ModelAdmin): 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]) + nb_user += 1 return response @@ -235,6 +238,7 @@ class VisitAdmin(admin.ModelAdmin): return obj.participants.count() num_participants.short_description = 'Participants' + @ admin.register(Place) class PlaceAdmin(admin.ModelAdmin): """Admin panel for places.""" diff --git a/visits/migrations/0002_visit_context_sheet.py b/visits/migrations/0002_visit_context_sheet.py new file mode 100644 index 0000000..bd96e25 --- /dev/null +++ b/visits/migrations/0002_visit_context_sheet.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2021-05-14 16:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('visits', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='visit', + name='context_sheet', + field=models.FileField(blank=True, help_text='Informe le lycéen de détails sur le contexte. Tout format supporté, PDF recommandé.', null=True, upload_to='visits/context_sheets/', verbose_name='fiche contexte'), + ), + ] diff --git a/visits/models.py b/visits/models.py index 3194430..7c5a8f8 100644 --- a/visits/models.py +++ b/visits/models.py @@ -169,11 +169,17 @@ class Visit(models.Model): upload_to='visits/fact_sheets/', help_text=('Informe le lycéen de détails sur la sortie. ' 'Tous formats supportés, PDF recommandé.')) + context_sheet = models.FileField( + 'fiche contexte', blank=True, null=True, + upload_to='visits/context_sheets/', + help_text=('Informe le lycéen de détails sur le contexte. ' + 'Tout format supporté, PDF recommandé.')) permission = models.FileField( 'autorisation de sortie', blank=True, null=True, upload_to='visits/visit_permissions/', help_text=('À mettre à disposition pour que le lycéen la remplisse. ' 'Tout format supporté, PDF recommandé.')) + participants = models.ManyToManyField('users.User', through='Participation') organizers = models.ManyToManyField('profiles.Tutor', diff --git a/visits/serializers.py b/visits/serializers.py index 201aeec..4bd93a6 100644 --- a/visits/serializers.py +++ b/visits/serializers.py @@ -94,7 +94,7 @@ class VisitSerializer(VisitListSerializer): 'place', 'date', 'start_time', 'end_time', 'meeting', 'deadline', 'passed', 'registrations_open', 'participants', 'organizers', - 'image', 'fact_sheet', 'permission', + 'image', 'fact_sheet', 'context_sheet', 'permission', 'url',) -- GitLab