From 9a1bbaa087c27d433d8c425ef10e1a31c5706dfa Mon Sep 17 00:00:00 2001 From: gustavomm19 Date: Thu, 7 Nov 2024 23:39:16 +0000 Subject: [PATCH] add micro cohorts to cohort model --- ...hort_cohorts_order_cohort_micro_cohorts.py | 34 +++++++++++++++++++ breathecode/admissions/models.py | 15 ++++++++ breathecode/admissions/serializers.py | 15 ++++++++ .../tests/urls/tests_academy_cohort.py | 5 +++ .../tests/urls/tests_academy_cohort_id.py | 4 +++ 5 files changed, 73 insertions(+) create mode 100644 breathecode/admissions/migrations/0065_cohort_cohorts_order_cohort_micro_cohorts.py diff --git a/breathecode/admissions/migrations/0065_cohort_cohorts_order_cohort_micro_cohorts.py b/breathecode/admissions/migrations/0065_cohort_cohorts_order_cohort_micro_cohorts.py new file mode 100644 index 000000000..a9cdc72c6 --- /dev/null +++ b/breathecode/admissions/migrations/0065_cohort_cohorts_order_cohort_micro_cohorts.py @@ -0,0 +1,34 @@ +# Generated by Django 5.1.2 on 2024-11-07 22:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("admissions", "0064_academy_legal_name"), + ] + + operations = [ + migrations.AddField( + model_name="cohort", + name="cohorts_order", + field=models.CharField( + blank=True, + default=None, + help_text="An IDs comma separated list to indicate the order in which the micro cohorts will be displayed", + max_length=50, + null=True, + ), + ), + migrations.AddField( + model_name="cohort", + name="micro_cohorts", + field=models.ManyToManyField( + blank=True, + help_text="This cohorts will represent small courses inside a main course", + related_name="cohorts", + to="admissions.cohort", + ), + ), + ] diff --git a/breathecode/admissions/models.py b/breathecode/admissions/models.py index faa6b8cea..1a1420fb5 100644 --- a/breathecode/admissions/models.py +++ b/breathecode/admissions/models.py @@ -362,6 +362,21 @@ class Cohort(models.Model): language = models.CharField(max_length=2, default="en", db_index=True) + micro_cohorts = models.ManyToManyField( + "Cohort", + blank=True, + help_text="This cohorts will represent small courses inside a main course", + related_name="cohorts", + ) + + cohorts_order = models.CharField( + max_length=50, + null=True, + blank=True, + default=None, + help_text="An IDs comma separated list to indicate the order in which the micro cohorts will be displayed", + ) + created_at = models.DateTimeField(auto_now_add=True, editable=False) updated_at = models.DateTimeField(auto_now=True, editable=False) diff --git a/breathecode/admissions/serializers.py b/breathecode/admissions/serializers.py index e322a2b64..42bda6b19 100644 --- a/breathecode/admissions/serializers.py +++ b/breathecode/admissions/serializers.py @@ -27,6 +27,15 @@ logger = logging.getLogger(__name__) +class GetTinyCohortSerializer(serpy.Serializer): + """The serializer schema definition.""" + + # Use a Field subclass like IntField if you need more validation. + id = serpy.Field() + name = serpy.Field() + slug = serpy.Field() + + class CountrySerializer(serpy.Serializer): """The serializer schema definition.""" @@ -433,6 +442,8 @@ class GetMeCohortSerializer(serpy.Serializer): name = serpy.Field() kickoff_date = serpy.Field() ending_date = serpy.Field() + micro_cohorts = serpy.MethodField() + cohorts_order = serpy.Field() intro_video = serpy.Field() current_day = serpy.Field() current_module = serpy.Field() @@ -442,6 +453,10 @@ class GetMeCohortSerializer(serpy.Serializer): is_hidden_on_prework = serpy.Field() available_as_saas = serpy.Field() + def get_micro_cohorts(self, obj): + cohorts = obj.micro_cohorts.all() + return GetTinyCohortSerializer(cohorts, many=True).data + class GetPublicCohortUserSerializer(serpy.Serializer): user = UserPublicSerializer() diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort.py b/breathecode/admissions/tests/urls/tests_academy_cohort.py index 9e9e928f0..d30dceacc 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort.py @@ -901,6 +901,7 @@ def test_academy_cohort__post__passing_all_statuses__uppercase(self): "accepts_enrollment_suggestions": True, "kickoff_date": UTC_NOW, "available_as_saas": False, + "cohorts_order": None, } ), ], @@ -1002,6 +1003,7 @@ def test_academy_cohort__post__passing_all_statuses__lowercase(self): "accepts_enrollment_suggestions": True, "kickoff_date": UTC_NOW, "available_as_saas": False, + "cohorts_order": None, } ), ], @@ -1103,6 +1105,7 @@ def test_academy_cohort__post__passing_available_as_saas_with__true(self): "accepts_enrollment_suggestions": True, "kickoff_date": UTC_NOW, "available_as_saas": True, + "cohorts_order": None, } ), ], @@ -1204,6 +1207,7 @@ def test_academy_cohort__post__passing_available_as_saas_with__false(self): "accepts_enrollment_suggestions": True, "kickoff_date": UTC_NOW, "available_as_saas": False, + "cohorts_order": None, } ), ], @@ -1304,6 +1308,7 @@ def test_academy_cohort__post__not_passing_available_as_saas(self): "accepts_enrollment_suggestions": True, "kickoff_date": UTC_NOW, "available_as_saas": model.academy.available_as_saas, + "cohorts_order": None, } ), ], diff --git a/breathecode/admissions/tests/urls/tests_academy_cohort_id.py b/breathecode/admissions/tests/urls/tests_academy_cohort_id.py index 0181e2461..ac2ebed13 100644 --- a/breathecode/admissions/tests/urls/tests_academy_cohort_id.py +++ b/breathecode/admissions/tests/urls/tests_academy_cohort_id.py @@ -676,6 +676,7 @@ def test_cohort_id__put__with_id__with_data_in_body(self): "accepts_enrollment_suggestions": True, "current_day": data["current_day"], "current_module": None, + "cohorts_order": None, "ending_date": model["cohort"].ending_date, "id": model["cohort"].id, "kickoff_date": model["cohort"].kickoff_date, @@ -849,6 +850,7 @@ def test_cohort_id__put__with_id__with_data_in_body__cohort_with_timezone(self): "accepts_enrollment_suggestions": True, "current_day": data["current_day"], "current_module": None, + "cohorts_order": None, "ending_date": model["cohort"].ending_date, "id": model["cohort"].id, "kickoff_date": model["cohort"].kickoff_date, @@ -1028,6 +1030,7 @@ def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_ "accepts_enrollment_suggestions": True, "current_day": data["current_day"], "current_module": None, + "cohorts_order": None, "ending_date": model["cohort"].ending_date, "id": model["cohort"].id, "kickoff_date": model["cohort"].kickoff_date, @@ -1194,6 +1197,7 @@ def test_cohort_id__put__with_id__schedule_related_to_syllabus_of_other_academy_ "accepts_enrollment_suggestions": True, "current_day": data["current_day"], "current_module": None, + "cohorts_order": None, "ending_date": model["cohort"].ending_date, "id": model["cohort"].id, "kickoff_date": model["cohort"].kickoff_date,