mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 12:23:11 +00:00
PoC téléchargement des données perso en CSV (RGPD)
This commit is contained in:
parent
3e03fc0c49
commit
125357eb1f
4 changed files with 47 additions and 0 deletions
|
@ -49,6 +49,7 @@ import re
|
||||||
import uuid
|
import uuid
|
||||||
import datetime
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
|
import csv
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -59,6 +60,7 @@ from django.dispatch import receiver
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
|
from django.http import HttpResponse
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -349,6 +351,41 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
self.unarchive()
|
self.unarchive()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def create_data_file(self):
|
||||||
|
"""Génère le fichier contenant toutes les infos que l'on a sur l'user:
|
||||||
|
- Infos perso
|
||||||
|
- Machines
|
||||||
|
- Cotisations
|
||||||
|
- Paramètres mail
|
||||||
|
- Historique sur les objects.
|
||||||
|
renvoit le chemin du fichier pour lancer le téléchargement.
|
||||||
|
"""
|
||||||
|
interfaces = self.users_interfaces([self])
|
||||||
|
|
||||||
|
response = HttpResponse(content_type='text/csv')
|
||||||
|
response['Content-Disposition'] = 'attachment; filename="{}_data.csv"'.format(self.get_full_name())
|
||||||
|
|
||||||
|
writer = csv.writer(response)
|
||||||
|
writer.writerow(["Ce fichier contient toutes les données que Re2o possède pour l\'utilisateur {}".format(self.get_full_name())])
|
||||||
|
writer.writerow(["Nom de la variable","Valeur","Commentaire"])
|
||||||
|
writer.writerow(["Informations personnelles"])
|
||||||
|
writer.writerow(["Prénom",str(self.name)])
|
||||||
|
writer.writerow(["Nom",str(self.surname)])
|
||||||
|
writer.writerow(["Téléphone",str(self.telephone)])
|
||||||
|
writer.writerow(["Commentaire",str(self.comment)])
|
||||||
|
writer.writerow(["École",str(self.school)])
|
||||||
|
writer.writerow(["Chambre",str(self.room)])
|
||||||
|
writer.writerow(["Date d'inscription",str(self.registered)])
|
||||||
|
writer.writerow(["Dernière connexion",str(self.last_login)])
|
||||||
|
writer.writerow(["Solde",str(self.solde)])
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_staff(self):
|
def is_staff(self):
|
||||||
""" Fonction de base django, renvoie si l'user est admin"""
|
""" Fonction de base django, renvoie si l'user est admin"""
|
||||||
|
|
|
@ -150,6 +150,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</a>
|
</a>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% history_button users text=True %}
|
{% history_button users text=True %}
|
||||||
|
<a class="btn btn-warning btn-sm" role="button" href="{% url 'users:download-data' user.id %}">
|
||||||
|
<i class="fa fa-archive"></i> CSV
|
||||||
|
</a>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
|
|
@ -34,6 +34,7 @@ urlpatterns = [
|
||||||
url(r'^new_user/$', views.new_user, name='new-user'),
|
url(r'^new_user/$', views.new_user, name='new-user'),
|
||||||
url(r'^new_club/$', views.new_club, name='new-club'),
|
url(r'^new_club/$', views.new_club, name='new-club'),
|
||||||
url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info, name='edit-info'),
|
url(r'^edit_info/(?P<userid>[0-9]+)$', views.edit_info, name='edit-info'),
|
||||||
|
url(r'^download_data/(?P<userid>[0-9]+)$', views.download_data, name='download-data'),
|
||||||
url(r'^edit_club_admin_members/(?P<clubid>[0-9]+)$',
|
url(r'^edit_club_admin_members/(?P<clubid>[0-9]+)$',
|
||||||
views.edit_club_admin_members,
|
views.edit_club_admin_members,
|
||||||
name='edit-club-admin-members'),
|
name='edit-club-admin-members'),
|
||||||
|
|
|
@ -225,6 +225,12 @@ def edit_info(request, user, userid):
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_edit(User)
|
||||||
|
def download_data(request, user, userid):
|
||||||
|
""" Call the create_data_file method from user and push the file to download """
|
||||||
|
return user.create_data_file()
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(User, 'state')
|
@can_edit(User, 'state')
|
||||||
|
|
Loading…
Reference in a new issue