2727 OrganizationUser ,
2828)
2929from django_email_learning .services .jwt_service import generate_jwt
30+ from django .utils .translation import get_language_info
3031import enum
3132
3233
@@ -90,6 +91,7 @@ class CreateCourseRequest(BaseModel):
9091 )
9192 imap_connection_id : Optional [int ] = Field (None , examples = [1 ])
9293 image : Optional [str ] = Field (None , examples = ["/path/to/course_image.png" ])
94+ language : str = Field (min_length = 2 , max_length = 10 , examples = ["en" ])
9395
9496 def to_django_model (self , organization_id : int ) -> Course :
9597 organization = Organization .objects .get (id = organization_id )
@@ -113,6 +115,7 @@ def to_django_model(self, organization_id: int) -> Course:
113115 slug = self .slug ,
114116 description = self .description ,
115117 organization = organization ,
118+ language = self .language ,
116119 )
117120 if imap_connection :
118121 course .imap_connection = imap_connection
@@ -133,6 +136,7 @@ class UpdateCourseRequest(BaseModel):
133136 enabled : Optional [bool ] = Field (None , examples = [True ])
134137 reset_imap_connection : Optional [bool ] = Field (None , examples = [False ])
135138 image : Optional [str ] = Field (None , examples = ["/path/to/course_image.png" ])
139+ language : Optional [str ] = Field (None , min_length = 2 , max_length = 10 , examples = ["en" ])
136140
137141 def to_django_model (self , course_id : int ) -> Course :
138142 try :
@@ -160,7 +164,8 @@ def to_django_model(self, course_id: int) -> Course:
160164 course .replace_image (self .image )
161165 if not self .image :
162166 course .image = None
163-
167+ if self .language is not None :
168+ course .language = self .language
164169 return course
165170
166171
@@ -175,13 +180,16 @@ class CourseResponse(BaseModel):
175180 enrollments_count : dict [str , int ]
176181 image : Optional [str ] = None
177182 image_path : Optional [str ] = None
183+ language : str
184+ is_rtl : bool = False
178185
179186 model_config = ConfigDict (from_attributes = True )
180187
181188 @staticmethod
182189 def from_django_model (
183190 course : Course , abs_url_builder : Callable
184191 ) -> "CourseResponse" :
192+ language_info = get_language_info (course .language )
185193 return CourseResponse .model_validate (
186194 {
187195 "id" : course .id ,
@@ -196,6 +204,8 @@ def from_django_model(
196204 "enrollments_count" : course .enrollments_count ,
197205 "image" : abs_url_builder (course .image .url ) if course .image else None ,
198206 "image_path" : course .image .name if course .image else None ,
207+ "language" : course .language ,
208+ "is_rtl" : language_info ["bidi" ],
199209 }
200210 )
201211
0 commit comments