Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add micro cohorts to cohort model #1494

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
),
),
]
24 changes: 24 additions & 0 deletions breathecode/admissions/migrations/0066_cohort_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.2 on 2024-11-14 12:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("admissions", "0065_cohort_cohorts_order_cohort_micro_cohorts"),
]

operations = [
migrations.AddField(
model_name="cohort",
name="color",
field=models.CharField(
blank=True,
default=None,
help_text="Add the color with hexadecimal format, i.e.: #FFFFFF",
max_length=50,
null=True,
),
),
]
22 changes: 22 additions & 0 deletions breathecode/admissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ 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",
)
color = models.CharField(
max_length=50,
null=True,
blank=True,
default=None,
help_text="Add the color with hexadecimal format, i.e.: #FFFFFF",
)

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

Expand Down
16 changes: 16 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,15 +442,22 @@ 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()
color = serpy.Field()
current_module = serpy.Field()
syllabus_version = SyllabusVersionSmallSerializer(required=False)
academy = GetAcademySerializer()
stage = serpy.Field()
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
Loading