From 1d55726a1f0870180d64a43a7e98f4eb609ebd4f Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Wed, 22 Jan 2025 15:43:41 +0100
Subject: [PATCH] =?UTF-8?q?refactor(graphs):=20=F0=9F=8F=B7=EF=B8=8F=20add?=
 =?UTF-8?q?=20types=20to=20model=20field/form?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 scipost_django/graphs/forms.py          |  4 +++-
 scipost_django/graphs/graphs/plotter.py | 12 ++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/scipost_django/graphs/forms.py b/scipost_django/graphs/forms.py
index 2fccdc33c..fa182abaf 100644
--- a/scipost_django/graphs/forms.py
+++ b/scipost_django/graphs/forms.py
@@ -147,6 +147,8 @@ class PlotOptionsForm(forms.Form):
         # Iterate over all forms and construct the form layout
         # either by extending the layout with the preferred layout from the object class
         # or by creating a row with all fields that are not already in the layout
+        form: forms.Form
+        object_class: ModelFieldPlotter | PlotKind | None
         for form, object_class in {
             self.model_field_select_form: self.model_field_select_form.plotter.__class__,
             self.plot_kind_select_form: self.plot_kind_select_form.kind_class,
@@ -172,7 +174,7 @@ class PlotOptionsForm(forms.Form):
                 )
                 if get_row_field_layout:
                     try:
-                        object_class_prefix = object_class.Options.prefix or ""
+                        object_class_prefix = str(object_class.Options.prefix) or ""
                     except AttributeError:
                         object_class_prefix = ""
 
diff --git a/scipost_django/graphs/graphs/plotter.py b/scipost_django/graphs/graphs/plotter.py
index c1daec660..81322b3d9 100644
--- a/scipost_django/graphs/graphs/plotter.py
+++ b/scipost_django/graphs/graphs/plotter.py
@@ -53,7 +53,7 @@ class ModelFieldPlotter(ABC):
     def __str__(self):
         return self.get_name()
 
-    def get_queryset(self):
+    def get_queryset(self) -> models.QuerySet[Any]:
         qs = self.model.objects.all()
         return qs
 
@@ -150,7 +150,7 @@ class FellowshipPlotter(ModelFieldPlotter):
     date_key = "start_date"
     country_key = "latest_affiliation_country"
 
-    def get_queryset(self):
+    def get_queryset(self) -> models.QuerySet[Fellowship]:
         qs = super().get_queryset()
 
         return qs.annotate(
@@ -175,7 +175,7 @@ class RefereePlotter(ModelFieldPlotter):
     date_key = "latest_report_date"
     country_key = "referee_country"
 
-    def get_queryset(self):
+    def get_queryset(self) -> models.QuerySet[Profile]:
         qs = super().get_queryset()
         return qs.annotate(
             latest_report_date=models.Subquery(
@@ -205,7 +205,7 @@ class AuthorPlotter(ModelFieldPlotter):
     date_key = "first_authorship_date"
     country_key = "author_country"
 
-    def get_queryset(self):
+    def get_queryset(self) -> models.QuerySet[Profile]:
         qs = super().get_queryset()
         return qs.annotate(
             first_authorship_date=models.Subquery(
@@ -235,7 +235,7 @@ class SponsorPlotter(ModelFieldPlotter):
     date_key = "latest_subsidy"
     country_key = "country"
 
-    def get_queryset(self):
+    def get_queryset(self) -> models.QuerySet[Organization]:
         qs = super().get_queryset()
         return qs.annotate(
             latest_subsidy=models.Subquery(
@@ -251,7 +251,7 @@ class ReportPlotter(ModelFieldPlotter):
     date_key = "created"
     country_key = "latest_affiliation_country"
 
-    def get_queryset(self):
+    def get_queryset(self) -> models.QuerySet[Report]:
         qs = super().get_queryset()
 
         return qs.annotate(
-- 
GitLab