-
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.
Populate max min weekly hours (#2488)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
98ba6d3
commit c4222fa
Showing
1 changed file
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 4.2.16 on 2024-12-05 19:39 | ||
import re | ||
|
||
from django.db import migrations | ||
|
||
|
||
def populate_weekly_hours_fields(apps, schema_editor): | ||
CoursePage = apps.get_model("cms", "CoursePage") | ||
for page in CoursePage.objects.all(): | ||
if page.effort: | ||
effort_str = page.effort.lower() | ||
effort_nums = re.findall(r"\d+", effort_str) | ||
if len(effort_nums) > 0: | ||
page.min_weekly_hours = effort_nums[0] | ||
page.max_weekly_hours = ( | ||
effort_nums[1] if len(effort_nums) > 1 else effort_nums[0] | ||
) | ||
page.save() | ||
|
||
ProgramPage = apps.get_model("cms", "ProgramPage") | ||
for page in ProgramPage.objects.all(): | ||
if page.effort: | ||
effort_str = page.effort.lower() | ||
effort_nums = re.findall(r"\d+", effort_str) | ||
if len(effort_nums) > 0: | ||
page.min_weekly_hours = effort_nums[0] | ||
page.max_weekly_hours = ( | ||
effort_nums[1] if len(effort_nums) > 1 else effort_nums[0] | ||
) | ||
page.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0041_populate_min_weeks"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
populate_weekly_hours_fields, reverse_code=migrations.RunPython.noop | ||
), | ||
] |