From b9593848d4643fa239a8fab61c36bcdc05efd59a Mon Sep 17 00:00:00 2001
From: Felix Blanke <felixblanke@uni-bonn.de>
Date: Wed, 2 Apr 2025 22:32:29 +0200
Subject: [PATCH] Add docstrings to JSONScheduleImportForm

---
 AKModel/forms.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/AKModel/forms.py b/AKModel/forms.py
index eb60a040..93448b28 100644
--- a/AKModel/forms.py
+++ b/AKModel/forms.py
@@ -309,6 +309,13 @@ class JSONScheduleImportForm(AdminIntermediateForm):
         )
 
     def _check_json_data(self, data: str):
+        """Validate `data` against our JSON schema.
+
+        :param data: The JSON string to validate using `self.json_schema_validator`.
+        :type data: str
+        :raises ValidationError: if the validation fails, with a description of the cause.
+        :return: The parsed JSON dict, if validation is successful.
+        """
         try:
             schedule = json.loads(data)
         except json.JSONDecodeError as ex:
@@ -328,6 +335,16 @@ class JSONScheduleImportForm(AdminIntermediateForm):
         return schedule
 
     def clean(self):
+        """Extract and validate entered JSON data.
+
+        We allow entering of the schedule from two sources:
+        1. from an uploaded file
+        2. from a text field.
+
+        This function checks that data is entered from exactly one source.
+        If so, the entered JSON string is validated against our schema.
+        Any errors are reported at the corresponding form field.
+        """
         cleaned_data = super().clean()
         if cleaned_data.get("json_file") and cleaned_data.get("json_data"):
             err = ValidationError(
-- 
GitLab