Skip to content
Snippets Groups Projects
Commit 05b2fac9 authored by s2536528's avatar s2536528
Browse files

Changed group permission for Cas

parent e768fbc0
Branches
No related tags found
No related merge requests found
Pipeline #72239 failed
......@@ -17,3 +17,4 @@ def json_parse(json_str_obj):
except TypeError:
obj = json_str_obj
return obj
......@@ -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)})
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment