diff --git a/src/backend/joanie/core/serializers/admin.py b/src/backend/joanie/core/serializers/admin.py index 3bf12c245..f9291064b 100755 --- a/src/backend/joanie/core/serializers/admin.py +++ b/src/backend/joanie/core/serializers/admin.py @@ -1,3 +1,4 @@ +# ruff: noqa: SLF001 # pylint: disable=too-many-lines """Admin serializers for Joanie Core app.""" @@ -8,7 +9,6 @@ from rest_framework.generics import get_object_or_404 from joanie.core import models -from joanie.core.enums import ALL_LANGUAGES from joanie.core.serializers.fields import ( ImageDetailField, ISO8601DurationField, @@ -21,6 +21,12 @@ class AdminContractDefinitionSerializer(serializers.ModelSerializer): """Serializer for ContractDefinition model.""" title = serializers.CharField() + name = serializers.ChoiceField( + required=False, + choices=models.ContractDefinition._meta.get_field("name").choices, + default=models.ContractDefinition._meta.get_field("name").default, + label=models.ContractDefinition._meta.get_field("name").verbose_name, + ) class Meta: model = models.ContractDefinition @@ -53,7 +59,22 @@ class AdminCourseRunLightSerializer(serializers.ModelSerializer): """Serializer for CourseRun model.""" title = serializers.CharField() - languages = serializers.MultipleChoiceField(choices=ALL_LANGUAGES) + languages = serializers.MultipleChoiceField( + choices=models.CourseRun._meta.get_field("languages").choices + ) + is_gradable = serializers.BooleanField( + required=False, + # default=False, + # label=_("Is gradable") + default=models.CourseRun._meta.get_field("is_gradable").default, + label=models.CourseRun._meta.get_field("is_gradable").verbose_name, + ) + is_listed = serializers.BooleanField( + required=False, + default=models.CourseRun._meta.get_field("is_listed").default, + label=models.CourseRun._meta.get_field("is_listed").verbose_name, + help_text=models.CourseRun._meta.get_field("is_listed").help_text, + ) class Meta: model = models.CourseRun @@ -125,6 +146,11 @@ class AdminOrganizationAccessSerializer(serializers.ModelSerializer): """Serializer for OrganizationAccess model.""" user = AdminUserSerializer(read_only=True) + role = serializers.ChoiceField( + required=False, + choices=models.OrganizationAccess._meta.get_field("role").choices, + default=models.OrganizationAccess._meta.get_field("role").default, + ) class Meta: model = models.OrganizationAccess @@ -169,6 +195,17 @@ def validate(self, attrs): class AdminOrganizationAddressSerializer(serializers.ModelSerializer): """Serializer for the Address model for an organization""" + is_main = serializers.BooleanField( + required=False, + default=models.Address._meta.get_field("is_main").default, + label=models.Address._meta.get_field("is_main").verbose_name, + ) + is_reusable = serializers.BooleanField( + required=False, + default=models.Address._meta.get_field("is_reusable").default, + label=models.Address._meta.get_field("is_reusable").verbose_name, + ) + class Meta: model = models.Address fields = [ @@ -246,6 +283,12 @@ class AdminOrganizationSerializer(serializers.ModelSerializer): signature = ImageDetailField(required=False) accesses = AdminOrganizationAccessSerializer(many=True, read_only=True) addresses = AdminOrganizationAddressSerializer(many=True, read_only=True) + country = serializers.ChoiceField( + required=False, + choices=models.Organization._meta.get_field("country").choices, + default=models.Organization._meta.get_field("country").default, + help_text=models.Organization._meta.get_field("country").help_text, + ) class Meta: model = models.Organization @@ -355,6 +398,22 @@ class AdminOrderGroupSerializer(serializers.ModelSerializer): Admin Serializer for OrderGroup model """ + nb_seats = serializers.IntegerField( + required=False, + label=models.OrderGroup._meta.get_field("nb_seats").verbose_name, + help_text=models.OrderGroup._meta.get_field("nb_seats").help_text, + default=models.OrderGroup._meta.get_field("nb_seats").default, + min_value=models.OrderGroup._meta.get_field("nb_seats") + .validators[0] + .limit_value, + max_value=models.OrderGroup._meta.get_field("nb_seats") + .validators[1] + .limit_value, + ) + is_active = serializers.BooleanField( + required=False, + default=models.OrderGroup._meta.get_field("is_active").default, + ) nb_available_seats = serializers.SerializerMethodField(read_only=True) class Meta: @@ -522,6 +581,13 @@ class AdminCourseAccessSerializer(serializers.ModelSerializer): """Serializer for CourseAccess model.""" user = AdminUserSerializer(read_only=True) + role = serializers.ChoiceField( + required=False, + # choices=models.CourseAccess.ROLE_CHOICES, + # default=enums.INSTRUCTOR, + choices=models.CourseAccess._meta.get_field("role").choices, + default=models.CourseAccess._meta.get_field("role").default, + ) class Meta: model = models.CourseAccess @@ -665,31 +731,14 @@ def update(self, instance, validated_data): return super().update(instance, validated_data) -class AdminCourseRunSerializer(serializers.ModelSerializer): +class AdminCourseRunSerializer(AdminCourseRunLightSerializer): """Serializer for CourseRun model.""" - title = serializers.CharField() course = AdminCourseLightSerializer(read_only=True) - languages = serializers.MultipleChoiceField(choices=ALL_LANGUAGES) class Meta: - model = models.CourseRun - fields = [ - "id", - "course", - "resource_link", - "title", - "is_gradable", - "is_listed", - "languages", - "start", - "end", - "enrollment_start", - "enrollment_end", - "uri", - "state", - ] - read_only_fields = ["id", "uri", "state"] + model = AdminCourseRunLightSerializer.Meta.model + fields = AdminCourseRunLightSerializer.Meta.fields + ["course"] def validate(self, attrs): """ @@ -827,6 +876,30 @@ class AdminProductTargetCourseRelationSerializer(serializers.ModelSerializer): Serializer for ProductTargetCourseRelation model """ + is_graded = serializers.BooleanField( + required=False, + default=models.ProductTargetCourseRelation._meta.get_field("is_graded").default, + label=models.ProductTargetCourseRelation._meta.get_field( + "is_graded" + ).verbose_name, + help_text=models.ProductTargetCourseRelation._meta.get_field( + "is_graded" + ).help_text, + ) + position = serializers.IntegerField( + required=False, + default=models.ProductTargetCourseRelation._meta.get_field("position").default, + label=models.ProductTargetCourseRelation._meta.get_field( + "position" + ).verbose_name, + min_value=models.ProductTargetCourseRelation._meta.get_field("position") + .validators[0] + .limit_value, + max_value=models.ProductTargetCourseRelation._meta.get_field("position") + .validators[1] + .limit_value, + ) + class Meta: model = models.ProductTargetCourseRelation fields = ["id", "course", "product", "is_graded", "position", "course_runs"] diff --git a/src/backend/joanie/core/serializers/client.py b/src/backend/joanie/core/serializers/client.py index d6a5d981d..3a54e06bc 100644 --- a/src/backend/joanie/core/serializers/client.py +++ b/src/backend/joanie/core/serializers/client.py @@ -1,6 +1,7 @@ +# ruff: noqa: SLF001 +# pylint: disable=too-many-lines """Client serializers for Joanie Core app.""" -# pylint: disable=too-many-lines from django.conf import settings from django.utils.translation import get_language from django.utils.translation import gettext_lazy as _ @@ -67,6 +68,10 @@ class AddressSerializer(serializers.ModelSerializer): """ id = serializers.CharField(read_only=True, required=False) + is_main = serializers.BooleanField( + required=False, + label=models.Address._meta.get_field("is_main").verbose_name, + ) class Meta: model = models.Address @@ -113,6 +118,12 @@ class CourseAccessSerializer(AbilitiesModelSerializer): source="user", ) + role = serializers.ChoiceField( + required=False, + choices=models.CourseAccess._meta.get_field("role").choices, + default=models.CourseAccess._meta.get_field("role").default, + ) + class Meta: model = models.CourseAccess fields = ["id", "role", "user_id"] @@ -222,6 +233,12 @@ class OrganizationAccessSerializer(AbilitiesModelSerializer): source="user", ) + role = serializers.ChoiceField( + required=False, + choices=models.OrganizationAccess._meta.get_field("role").choices, + default=models.OrganizationAccess._meta.get_field("role").default, + ) + class Meta: model = models.OrganizationAccess fields = ["id", "role", "user_id"] diff --git a/src/backend/joanie/payment/serializers.py b/src/backend/joanie/payment/serializers.py index f9babd08b..863ed534f 100644 --- a/src/backend/joanie/payment/serializers.py +++ b/src/backend/joanie/payment/serializers.py @@ -1,3 +1,4 @@ +# ruff: noqa: SLF001 """Serializers for api.""" from rest_framework import serializers @@ -11,6 +12,10 @@ class CreditCardSerializer(serializers.ModelSerializer): """ id = serializers.CharField(read_only=True, required=False) + is_main = serializers.BooleanField( + required=False, + label=models.CreditCard._meta.get_field("is_main").verbose_name, + ) class Meta: model = models.CreditCard diff --git a/src/backend/joanie/tests/swagger/admin-swagger.json b/src/backend/joanie/tests/swagger/admin-swagger.json index d5fc51245..9f653341a 100644 --- a/src/backend/joanie/tests/swagger/admin-swagger.json +++ b/src/backend/joanie/tests/swagger/admin-swagger.json @@ -2773,7 +2773,6 @@ "name": "state", "schema": { "type": "string", - "default": "draft", "enum": [ "canceled", "draft", @@ -4479,7 +4478,7 @@ } ], "default": "contract_definition", - "title": "Template name" + "title": "template name" } }, "required": [ @@ -4517,7 +4516,7 @@ } ], "default": "contract_definition", - "title": "Template name" + "title": "template name" } }, "required": [ @@ -4835,14 +4834,6 @@ "readOnly": true, "description": "primary key for the record as UUID" }, - "course": { - "allOf": [ - { - "$ref": "#/components/schemas/AdminCourseLight" - } - ], - "readOnly": true - }, "resource_link": { "type": "string", "maxLength": 200 @@ -4919,6 +4910,14 @@ "text" ], "readOnly": true + }, + "course": { + "allOf": [ + { + "$ref": "#/components/schemas/AdminCourseLight" + } + ], + "readOnly": true } }, "required": [ @@ -5932,12 +5931,12 @@ "is_main": { "type": "boolean", "default": false, - "title": "Main" + "title": "main" }, "is_reusable": { "type": "boolean", "default": false, - "title": "Reusable" + "title": "reusable" } }, "required": [ @@ -5991,12 +5990,12 @@ "is_main": { "type": "boolean", "default": false, - "title": "Main" + "title": "main" }, "is_reusable": { "type": "boolean", "default": false, - "title": "Reusable" + "title": "reusable" } }, "required": [ @@ -6388,7 +6387,7 @@ "is_graded": { "type": "boolean", "default": true, - "title": "Take into account for certification", + "title": "take into account for certification", "description": "Take into account the course grade for certification." }, "position": { @@ -6396,7 +6395,7 @@ "maximum": 32767, "minimum": 0, "default": 0, - "title": "Position in product" + "title": "position in product" }, "course_runs": { "type": "array", @@ -6430,7 +6429,7 @@ "is_graded": { "type": "boolean", "default": true, - "title": "Take into account for certification", + "title": "take into account for certification", "description": "Take into account the course grade for certification." }, "position": { @@ -6438,7 +6437,7 @@ "maximum": 32767, "minimum": 0, "default": 0, - "title": "Position in product" + "title": "position in product" }, "course_runs": { "type": "array", @@ -7337,7 +7336,7 @@ } ], "default": "contract_definition", - "title": "Template name" + "title": "template name" } } }, @@ -7514,12 +7513,12 @@ "is_main": { "type": "boolean", "default": false, - "title": "Main" + "title": "main" }, "is_reusable": { "type": "boolean", "default": false, - "title": "Reusable" + "title": "reusable" } } }, @@ -7662,7 +7661,7 @@ "is_graded": { "type": "boolean", "default": true, - "title": "Take into account for certification", + "title": "take into account for certification", "description": "Take into account the course grade for certification." }, "position": { @@ -7670,7 +7669,7 @@ "maximum": 32767, "minimum": 0, "default": 0, - "title": "Position in product" + "title": "position in product" }, "course_runs": { "type": "array", diff --git a/src/backend/joanie/tests/swagger/swagger.json b/src/backend/joanie/tests/swagger/swagger.json index c5c0388c2..490de532e 100644 --- a/src/backend/joanie/tests/swagger/swagger.json +++ b/src/backend/joanie/tests/swagger/swagger.json @@ -2537,7 +2537,6 @@ "type": "array", "items": { "type": "string", - "default": "draft", "enum": [ "canceled", "draft", @@ -2558,7 +2557,6 @@ "type": "array", "items": { "type": "string", - "default": "draft", "enum": [ "canceled", "draft", @@ -4132,8 +4130,7 @@ }, "is_main": { "type": "boolean", - "default": false, - "title": "Main" + "title": "main" }, "postcode": { "type": "string", @@ -4184,8 +4181,7 @@ }, "is_main": { "type": "boolean", - "default": false, - "title": "Main" + "title": "main" }, "postcode": { "type": "string", @@ -5043,8 +5039,7 @@ }, "is_main": { "type": "boolean", - "default": false, - "title": "Main" + "title": "main" } }, "required": [ @@ -5066,8 +5061,7 @@ }, "is_main": { "type": "boolean", - "default": false, - "title": "Main" + "title": "main" } } }, @@ -6329,8 +6323,7 @@ }, "is_main": { "type": "boolean", - "default": false, - "title": "Main" + "title": "main" }, "postcode": { "type": "string", @@ -6374,8 +6367,7 @@ }, "is_main": { "type": "boolean", - "default": false, - "title": "Main" + "title": "main" } } },