From 05b2fac9f47288157f367294560609c37d6b478a Mon Sep 17 00:00:00 2001
From: iggy <i.kepka@student.utwente.nl>
Date: Fri, 21 Jul 2023 10:50:40 +0200
Subject: [PATCH] Changed group permission for Cas

---
 MySU/helper_functions.py                           |  1 +
 apps/MySU/models/association_specific_data.py      | 14 +++++++-------
 apps/MySU/serializers/association_specific_data.py | 10 ++++++++--
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/MySU/helper_functions.py b/MySU/helper_functions.py
index a73cb60..822f39a 100644
--- a/MySU/helper_functions.py
+++ b/MySU/helper_functions.py
@@ -17,3 +17,4 @@ def json_parse(json_str_obj):
     except TypeError:
         obj = json_str_obj
     return obj
+
diff --git a/apps/MySU/models/association_specific_data.py b/apps/MySU/models/association_specific_data.py
index c1b933b..1a9d1c8 100644
--- a/apps/MySU/models/association_specific_data.py
+++ b/apps/MySU/models/association_specific_data.py
@@ -52,22 +52,22 @@ class AssociationSpecificData(models.Model):
             if self.association != self.data_field.association:
                 raise ValidationError({"data_field": "Association of data_field doesn't match the association."})
 
-            # TODO: remove after django update to v3
-            if len(self.data_field.type) > 1:
-                raise ValidationError({"data_field": "Validation does not work currently for more than one type"})
+            # # TODO: remove after django update to v3
+            # if len(self.data_field.type) > 1:
+            #     raise ValidationError({"data_field": "Validation does not work currently for more than one type"})
 
-            if self.data_field.type[0] == "Boolean":
+            if self.data_field.type == "Boolean":
                 if self.value not in ["true", "false"]:
                     raise ValidationError({"value": "Value for boolean data field should be 'true' or 'false'."})
                 if self.data_field.mandatory and self.value != "true":
                     raise ValidationError({"value": "Value has to be true (value='true'), when data field is mandatory."})
-            elif self.data_field.type[0] == "Number":
+            elif self.data_field.type == "Number":
                 if not self.value.isdigit():
                     raise ValidationError({"value": "Value should be a integer"})
-            elif self.data_field.type[0] == "String":
+            elif self.data_field.type == "String":
                 # any valid value for a text field is valid for a data field with type string
                 pass
-            elif self.data_field.type[0] == "Choice":
+            elif self.data_field.type == "Choice":
                 if self.value not in self.data_field.choices.split(","):
                     raise ValidationError({"value": "Value {} is not in the list of valid choices"
                                           .format(self.value)})
diff --git a/apps/MySU/serializers/association_specific_data.py b/apps/MySU/serializers/association_specific_data.py
index 6ed53f0..87add27 100644
--- a/apps/MySU/serializers/association_specific_data.py
+++ b/apps/MySU/serializers/association_specific_data.py
@@ -5,6 +5,10 @@ from apps.MySU.models import AssociationSpecificData
 from apps.MySU.serializers.base import BaseSerializer
 from MySU.helper_functions import get_for_patch
 
+from django.forms import ModelForm
+from apps.MySU.models.association_specific_data import AssociationSpecificData
+
+
 
 
 class AssociationSpecificDataSerializerSimple(serializers.HyperlinkedModelSerializer):
@@ -42,9 +46,11 @@ class AssociationSpecificDataSerializer(BaseSerializer):
 
         errors = {}
         if association != data_field.association:
-            errors["Association"] = f"{association.slug}, doesn't match the association, {data_field.association.slug}, of the data_field {data_field.slug}"
+            errors[
+                "Association"] = f"{association.slug}, doesn't match the association, {data_field.association.slug}, of the data_field {data_field.slug}"
         if association != membership.association:
-            errors["Association"] = f"{association.slug}, doesn't match the association, {data_field.association.slug}, of the membership {membership.slug}"
+            errors[
+                "Association"] = f"{association.slug}, doesn't match the association, {data_field.association.slug}, of the membership {membership.slug}"
         if data_field.type == "Boolean" and data_field.mandatory and not value:
             errors["mandatory"] = "Value has to be true, when data field is mandatory."
         if errors:
-- 
GitLab