-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add courseware language support
- Loading branch information
1 parent
6482515
commit 70a3859
Showing
16 changed files
with
305 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Generated by Django 4.2.17 on 2025-01-03 08:36 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
def populate_course_language(apps, schema_editor): | ||
"""Prepopulate the course language for the course pages""" | ||
|
||
CoursePage = apps.get_model("cms.CoursePage") | ||
ExternalCoursePage = apps.get_model("cms.ExternalCoursePage") | ||
ProgramPage = apps.get_model("cms.ProgramPage") | ||
ExternalProgramPage = apps.get_model("cms.ExternalProgramPage") | ||
|
||
CourseLanguage = apps.get_model("courses.CourseLanguage") | ||
# English is the default language for all the courses | ||
course_language_english, _ = CourseLanguage.objects.get_or_create( | ||
name="English", priority=1 | ||
) | ||
|
||
CoursePage.objects.update(language=course_language_english) | ||
ExternalCoursePage.objects.update(language=course_language_english) | ||
ProgramPage.objects.update(language=course_language_english) | ||
ExternalProgramPage.objects.update(language=course_language_english) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("courses", "0042_add_course_language"), | ||
("cms", "0077_alter_certificatepage_ceus"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="coursepage", | ||
name="language", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="The course/program language for this page", | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="externalcoursepage", | ||
name="language", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="The course/program language for this page", | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="externalprogrampage", | ||
name="language", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="The course/program language for this page", | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="programpage", | ||
name="language", | ||
field=models.ForeignKey( | ||
blank=True, | ||
help_text="The course/program language for this page", | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
), | ||
migrations.RunPython( | ||
populate_course_language, reverse_code=migrations.RunPython.noop | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Generated by Django 4.2.17 on 2025-01-03 08:39 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0078_add_courseware_page_language"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="coursepage", | ||
name="language", | ||
field=models.ForeignKey( | ||
help_text="The course/program language for this page", | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="externalcoursepage", | ||
name="language", | ||
field=models.ForeignKey( | ||
help_text="The course/program language for this page", | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="externalprogrampage", | ||
name="language", | ||
field=models.ForeignKey( | ||
default="", | ||
help_text="The course/program language for this page", | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AlterField( | ||
model_name="programpage", | ||
name="language", | ||
field=models.ForeignKey( | ||
default="", | ||
help_text="The course/program language for this page", | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="courses.courselanguage", | ||
), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Generated by Django 4.2.17 on 2025-01-07 13:31 | ||
|
||
import django.core.validators | ||
import django.db.models.functions.text | ||
from django.db import migrations, models | ||
|
||
|
||
def add_default_supported_languages(apps, schema_editor): | ||
"""Add the languages that xPRO platform will support as default""" | ||
CourseLanguage = apps.get_model("courses.CourseLanguage") | ||
CourseLanguage.objects.bulk_create( | ||
[ | ||
CourseLanguage(name="English", priority=1), | ||
CourseLanguage(name="Spanish"), | ||
CourseLanguage(name="Portuguese"), | ||
CourseLanguage(name="Mandarin"), | ||
CourseLanguage(name="Italian"), | ||
CourseLanguage(name="French"), | ||
] | ||
) | ||
|
||
|
||
def remove_all_languages(apps, schema_editor): | ||
"""Remove all languages""" | ||
CourseLanguage = apps.get_model("courses.CourseLanguage") | ||
CourseLanguage.objects.all().delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("courses", "0041_platform_sync_daily"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="CourseLanguage", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_on", models.DateTimeField(auto_now_add=True)), | ||
("updated_on", models.DateTimeField(auto_now=True)), | ||
("name", models.CharField(max_length=255, unique=True)), | ||
( | ||
"priority", | ||
models.PositiveSmallIntegerField( | ||
blank=True, | ||
default=100, | ||
help_text="The priority of this language in the course/program sorting.", | ||
null=True, | ||
validators=[django.core.validators.MinValueValidator(1)], | ||
), | ||
), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name="courselanguage", | ||
constraint=models.UniqueConstraint( | ||
django.db.models.functions.text.Lower("name"), | ||
name="unique_language_name", | ||
), | ||
), | ||
migrations.RunPython( | ||
code=add_default_supported_languages, | ||
reverse_code=remove_all_languages, | ||
), | ||
] |
Oops, something went wrong.