11"""CMS app serializers"""
22
3+ from __future__ import annotations
4+
35import bleach
46from django .templatetags .static import static
7+ from drf_spectacular .utils import extend_schema_field
58from rest_framework import serializers
69
710from cms import models
@@ -19,6 +22,7 @@ class BaseCoursePageSerializer(serializers.ModelSerializer):
1922 effort = serializers .SerializerMethodField ()
2023 length = serializers .SerializerMethodField ()
2124
25+ @extend_schema_field (str )
2226 def get_feature_image_src (self , instance ):
2327 """Serializes the source of the feature_image"""
2428 feature_img_src = None
@@ -27,19 +31,22 @@ def get_feature_image_src(self, instance):
2731
2832 return feature_img_src or static (DEFAULT_COURSE_IMG_PATH )
2933
34+ @extend_schema_field (serializers .URLField )
3035 def get_page_url (self , instance ):
3136 return instance .get_url ()
3237
38+ @extend_schema_field (str )
3339 def get_description (self , instance ):
3440 return bleach .clean (instance .description , tags = [], strip = True )
3541
36- def get_effort (self , instance ):
42+ def get_effort (self , instance ) -> str | None :
3743 return (
3844 bleach .clean (instance .effort , tags = [], strip = True )
3945 if instance .effort
4046 else None
4147 )
4248
49+ @extend_schema_field (str )
4350 def get_length (self , instance ):
4451 return (
4552 bleach .clean (instance .length , tags = [], strip = True )
@@ -66,6 +73,7 @@ class CoursePageSerializer(BaseCoursePageSerializer):
6673 instructors = serializers .SerializerMethodField ()
6774 current_price = serializers .SerializerMethodField ()
6875
76+ @extend_schema_field (serializers .URLField )
6977 def get_financial_assistance_form_url (self , instance ):
7078 """
7179 Returns URL of the Financial Assistance Form.
@@ -116,14 +124,16 @@ def get_financial_assistance_form_url(self, instance):
116124 else ""
117125 )
118126
119- def get_current_price (self , instance ):
127+ @extend_schema_field (int )
128+ def get_current_price (self , instance ) -> int | None :
120129 relevant_product = (
121130 instance .product .active_products .filter ().order_by ("-price" ).first ()
122131 if instance .product .active_products
123132 else None
124133 )
125134 return relevant_product .price if relevant_product else None
126135
136+ @extend_schema_field (list )
127137 def get_instructors (self , instance ):
128138 members = [
129139 member .linked_instructor_page
@@ -160,6 +170,7 @@ class ProgramPageSerializer(serializers.ModelSerializer):
160170 price = serializers .SerializerMethodField ()
161171 financial_assistance_form_url = serializers .SerializerMethodField ()
162172
173+ @extend_schema_field (str )
163174 def get_feature_image_src (self , instance ):
164175 """Serializes the source of the feature_image"""
165176 feature_img_src = None
@@ -168,12 +179,15 @@ def get_feature_image_src(self, instance):
168179
169180 return feature_img_src or static (DEFAULT_COURSE_IMG_PATH )
170181
182+ @extend_schema_field (serializers .URLField )
171183 def get_page_url (self , instance ):
172184 return instance .get_url ()
173185
186+ @extend_schema_field (str )
174187 def get_price (self , instance ):
175188 return instance .price [0 ].value ["text" ] if len (instance .price ) > 0 else None
176189
190+ @extend_schema_field (serializers .URLField )
177191 def get_financial_assistance_form_url (self , instance ):
178192 """
179193 Returns URL of the Financial Assistance Form.
@@ -235,6 +249,7 @@ class InstructorPageSerializer(serializers.ModelSerializer):
235249
236250 feature_image_src = serializers .SerializerMethodField ()
237251
252+ @extend_schema_field (str )
238253 def get_feature_image_src (self , instance ):
239254 """Serializes the source of the feature_image"""
240255 feature_img_src = None
0 commit comments