From 6632918fb18a06e9e2d9a20049f76e55b340ce87 Mon Sep 17 00:00:00 2001 From: matteotolloso Date: Thu, 9 Nov 2023 20:16:05 +0100 Subject: [PATCH] bugfix --- smartreport_app/kb_interface.py | 3 +-- smartreport_app/models.py | 11 ++++++++--- smartreport_app/views.py | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/smartreport_app/kb_interface.py b/smartreport_app/kb_interface.py index 6bda091..a6b3479 100644 --- a/smartreport_app/kb_interface.py +++ b/smartreport_app/kb_interface.py @@ -1,6 +1,5 @@ -def kb_interface(params): - kpi_name = params['kpi_name'], +def kb_interface(kpi_name, params): plot_type = params['chart_type'] # other parameters like the time period diff --git a/smartreport_app/models.py b/smartreport_app/models.py index 46e8e2e..8250f61 100644 --- a/smartreport_app/models.py +++ b/smartreport_app/models.py @@ -2,9 +2,6 @@ from django.utils.translation import gettext_lazy as _ -# class ArchivedReport(models.Model): -# created = models.DateTimeField(auto_now_add=True) -# file = models.FileField(upload_to="reports/") class UserType(models.TextChoices): DOCTOR = 'doctor', _('Doctor') @@ -124,3 +121,11 @@ class DashboardLayout(models.Model): def __str__(self): return self.name + +class ArchivedReport(models.Model): + created = models.DateTimeField(auto_now_add=True) + + template = models.ForeignKey( + ReportTemplate, related_name="archived_reports", on_delete=models.CASCADE) + + file = models.FileField(upload_to="reports/") \ No newline at end of file diff --git a/smartreport_app/views.py b/smartreport_app/views.py index 530645b..a263ec5 100644 --- a/smartreport_app/views.py +++ b/smartreport_app/views.py @@ -73,9 +73,10 @@ def kpi_data(request, format=None): params = request.query_params # check if the parameters "kpi_name" and "user_type" are provided - if not 'kpi_name' in params or not 'user_type' in params or not 'chart_type' in params: + if not 'kpi_id' in params or not 'user_type' in params or not 'chart_type' in params: return Response({"message": "The required parameters 'kpi_name' and 'user_type' are missing"}, status=status.HTTP_400_BAD_REQUEST) + kpi_name = Kpi.objects.get(pk=params['kpi_id']).name if False: # enable in production # check if the required kpi exists @@ -95,6 +96,6 @@ def kpi_data(request, format=None): # ask the kb for the response, the format is different depending on the kind of plot - data = kb_interface(params) + data = kb_interface(kpi_name, params) return Response({'data' : data})