Skip to content
Snippets Groups Projects
Commit f40191bc authored by Carlos Vega's avatar Carlos Vega
Browse files

added provenance to export view

parent 6bffc65f
No related branches found
No related tags found
1 merge request!266Resolve "Record who exports information and restrict who can export info."
......@@ -7,7 +7,7 @@ from django.http import HttpResponse
from .notifications import get_today_midnight_date
from web.decorators import PermissionDecorator
from . import e500_error, wrap_response
from ..models import Subject, StudySubject, Appointment, ConfigurationItem
from ..models import Subject, StudySubject, Appointment, ConfigurationItem, Worker, Provenance, Visit
from web.models.constants import VISIT_SHOW_VISIT_NUMBER_FROM_ZERO
from distutils.util import strtobool
from web.templatetags.filters import display_visit_number
......@@ -32,6 +32,14 @@ def export_to_csv(request, data_type="subjects"):
for row in data:
writer.writerow([s.encode("utf-8") for s in row])
worker = Worker.get_by_user(request.user)
p = Provenance(
modification_author=worker,
modification_description=f'Export {data_type} to csv',
modified_field='',
request_path=request.path)
p.save()
return response
......@@ -49,6 +57,14 @@ def export_to_excel(request, data_type="subjects"):
response = excel.make_response_from_array(data, 'xls', file_name=filename)
response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
worker = Worker.get_by_user(request.user)
p = Provenance(
modification_author=worker,
modification_description=f'Export {data_type} to excel',
modified_field='',
request_path=request.path)
p.save()
return response
......@@ -208,7 +224,14 @@ def get_appointments_as_array(selected_fields=None):
@PermissionDecorator('export_subjects', 'subject')
def export(request):
provenances = Provenance.objects.filter(
modified_table__isnull=True,
previous_value__isnull=True,
new_value__isnull=True,
modified_field='',
request_path__startswith='/export/').order_by('-modification_date')
return wrap_response(request, 'export/index.html', {
'subject_fields': get_default_subject_fields(),
'appointment_fields': get_appointment_fields()[0]
'appointment_fields': get_appointment_fields()[0],
'provenances': provenances
})
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