Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 3, 2024
1 parent 74c143e commit ea18746
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cms/migrations/0041_populate_min_weeks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Generated by Django 4.2.16 on 2024-12-03 18:25

from django.db import migrations
import re

from django.db import migrations


def populate_max_min_weeks_fields(apps, schema_editor):
CoursePage = apps.get_model("cms", "CoursePage")
for course_page in CoursePage.objects.all():
Expand All @@ -16,23 +18,31 @@ def populate_max_min_weeks_fields(apps, schema_editor):
ProgramPage = apps.get_model("cms", "ProgramPage")
for program_page in ProgramPage.objects.all():
if program_page.length and program_page.max_weeks is None:
duration_string = re.findall(r"\d+[\s-]*[\d+\s]*week", program_page.length.lower())
duration_string = re.findall(
r"\d+[\s-]*[\d+\s]*week", program_page.length.lower()
)
if duration_string:
duration_nums = re.findall(r"\d+", duration_string[0])
else:
duration_string = re.findall(r"\d+[\s-]*[\d+\s]*month", program_page.length.lower())
duration_string = re.findall(
r"\d+[\s-]*[\d+\s]*month", program_page.length.lower()
)
duration_nums_in_month = re.findall(r"\d+", duration_string[0])
duration_nums = [num * 4 for num in duration_nums_in_month]
program_page.min_weeks = duration_nums[0]
program_page.max_weeks = duration_nums[1] if len(duration_nums) > 1 else duration_nums[0]
program_page.max_weeks = (
duration_nums[1] if len(duration_nums) > 1 else duration_nums[0]
)
program_page.save()


class Migration(migrations.Migration):
dependencies = [
('cms', '0040_coursepage_max_weeks_coursepage_min_weeks_and_more'),
("cms", "0040_coursepage_max_weeks_coursepage_min_weeks_and_more"),
]

operations = [
migrations.RunPython(populate_max_min_weeks_fields, reverse_code=migrations.RunPython.noop),
migrations.RunPython(
populate_max_min_weeks_fields, reverse_code=migrations.RunPython.noop
),
]

0 comments on commit ea18746

Please sign in to comment.