Skip to content

Commit

Permalink
Populate max min weekly hours (#2488)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
annagav and pre-commit-ci[bot] authored Dec 6, 2024
1 parent 98ba6d3 commit c4222fa
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cms/migrations/0042_populate_weekly_hours.py
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
),
]

0 comments on commit c4222fa

Please sign in to comment.