From 8e117eb7e1c65ba87145a8c43824b7b41cdf81fc Mon Sep 17 00:00:00 2001 From: Anas Hameed <68567262+Anas-hameed@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:03:52 +0500 Subject: [PATCH] Feat: Add a additional language in the courserun API model. (#93) Co-authored-by: anas.hameed --- course_discovery/apps/api/serializers.py | 2 +- .../apps/api/tests/test_serializers.py | 1 + .../apps/course_metadata/data_loaders/api.py | 1 + .../migrations/0274_auto_20240911_0805.py | 23 +++++++++++++++++++ .../apps/course_metadata/models.py | 7 ++++++ .../apps/course_metadata/search_indexes.py | 1 + 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 course_discovery/apps/course_metadata/migrations/0274_auto_20240911_0805.py diff --git a/course_discovery/apps/api/serializers.py b/course_discovery/apps/api/serializers.py index 9c4901ae7e..92b6dd0551 100644 --- a/course_discovery/apps/api/serializers.py +++ b/course_discovery/apps/api/serializers.py @@ -930,7 +930,7 @@ class Meta(MinimalCourseRunSerializer.Meta): 'course_uuid', 'estimated_hours', 'invite_only', 'subjects', 'is_marketing_price_set', 'marketing_price_value', 'is_marketing_price_hidden', 'featured', 'card_image_url', 'average_rating', 'total_raters', 'yt_video_url', 'course_duration_override', 'course_difficulty', - 'course_job_role', 'course_format', 'course_industry_certified_training', 'course_owner', + 'course_job_role', 'course_format', 'course_industry_certified_training', 'course_owner', 'course_language' ) read_only_fields = ('enrollment_count', 'recent_enrollment_count',) diff --git a/course_discovery/apps/api/tests/test_serializers.py b/course_discovery/apps/api/tests/test_serializers.py index 13dc7f83ca..712f2cc909 100644 --- a/course_discovery/apps/api/tests/test_serializers.py +++ b/course_discovery/apps/api/tests/test_serializers.py @@ -660,6 +660,7 @@ def get_expected_data(cls, course_run, request): 'is_marketing_price_hidden': course_run.is_marketing_price_hidden, 'card_image_url': course_run.card_image_url, 'subjects': [], + 'course_language': course_run.course_language }) return expected diff --git a/course_discovery/apps/course_metadata/data_loaders/api.py b/course_discovery/apps/course_metadata/data_loaders/api.py index 518ed1c893..d8b0d83580 100644 --- a/course_discovery/apps/course_metadata/data_loaders/api.py +++ b/course_discovery/apps/course_metadata/data_loaders/api.py @@ -1083,6 +1083,7 @@ def _process_response(self, response): course_run.course_job_role = body['course_job_role'] course_run.course_format = body['course_format'] course_run.course_industry_certified_training = body['course_industry_certified_training'] + course_run.course_language = body.get('course_language', '') course_run.course_owner = body['course_owner'] course_run.status = self._process_course_status(body['status']) diff --git a/course_discovery/apps/course_metadata/migrations/0274_auto_20240911_0805.py b/course_discovery/apps/course_metadata/migrations/0274_auto_20240911_0805.py new file mode 100644 index 0000000000..ea91cbcdfe --- /dev/null +++ b/course_discovery/apps/course_metadata/migrations/0274_auto_20240911_0805.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.16 on 2024-09-11 08:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('course_metadata', '0273_auto_20240910_1605'), + ] + + operations = [ + migrations.AddField( + model_name='courserun', + name='course_language', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Language of the course run'), + ), + migrations.AddField( + model_name='historicalcourserun', + name='course_language', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Language of the course run'), + ), + ] diff --git a/course_discovery/apps/course_metadata/models.py b/course_discovery/apps/course_metadata/models.py index aa0ae01e53..f65d9fc3ad 100644 --- a/course_discovery/apps/course_metadata/models.py +++ b/course_discovery/apps/course_metadata/models.py @@ -1346,6 +1346,13 @@ class CourseRun(DraftModelMixin, CachedMixin, TimeStampedModel): max_length=255, null=True, blank=True, verbose_name=_("Course Owner") ) + course_language = models.CharField( + max_length=255, + null=True, + blank=True, + verbose_name=_("Language of the course run"), + ) + STATUS_CHANGE_EXEMPT_FIELDS = [ 'start', 'end', diff --git a/course_discovery/apps/course_metadata/search_indexes.py b/course_discovery/apps/course_metadata/search_indexes.py index afab3101ba..fe78446917 100644 --- a/course_discovery/apps/course_metadata/search_indexes.py +++ b/course_discovery/apps/course_metadata/search_indexes.py @@ -258,6 +258,7 @@ class CourseRunIndex(BaseCourseIndex, indexes.Indexable): course_job_role = indexes.CharField(model_attr='course_job_role', null=True) course_format = indexes.CharField(model_attr='course_format', null=True) course_industry_certified_training = indexes.CharField(model_attr='course_industry_certified_training', null=True) + course_language = indexes.CharField(model_attr='course_language', null=True) course_owner = indexes.CharField(model_attr='course_owner', null=True)