Skip to content

Commit

Permalink
add micro cohorts to cohort model
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomm19 committed Nov 7, 2024
1 parent 4dd04a3 commit 9a1bbaa
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
15 changes: 15 additions & 0 deletions breathecode/admissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions breathecode/admissions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions breathecode/admissions/tests/urls/tests_academy_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
),
],
Expand Down Expand Up @@ -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,
}
),
],
Expand Down Expand Up @@ -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,
}
),
],
Expand Down Expand Up @@ -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,
}
),
],
Expand Down Expand Up @@ -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,
}
),
],
Expand Down
4 changes: 4 additions & 0 deletions breathecode/admissions/tests/urls/tests_academy_cohort_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9a1bbaa

Please sign in to comment.