Skip to content

Commit

Permalink
chore!: Upgrade wagtail to 5.x (#2830)
Browse files Browse the repository at this point in the history
* Upgrade to wagtail 3.x and pillow 9.x

* Migration

* iMigration

* recreated upgrade migrations

* PageRevision content_json TextField changed to content JSONField

* linting

* lint

* rebased

* recreated v3 upgrade migration

* lint & fixed blog migration

* wagtail 4 poetry

* wagtail 4.0.4 upgrade

* remove commented code

* fix object_id typing and skip pylint checks

* disable pylint

* fix tests

* disabled pylint

* fixing migrations

* fix migrations for new instance

* use TitleFieldPanel for title field

* course topic modeladmin changed to snippets

* upgraded to v5.2.1

* rename migration, update comment

* upgrade wagtail-metadata to fix new page slugs

* upgrade wagtail-factories to fix wagtail module paths

* fix some of the tests

* fix image carousel test

* fix migrations

* fix: migrations (rough)

* upgrade migration deps

* title field panel to field panel when slug is not required and lint

* small fix in data migration and cleanup

* remove migration generated by Django msg

* cleanup

* updated module import to specify the blocks

* updated migration

* update docs

* lint

* replace wagtail snippets with modelviewset for coursetopic

---------

Co-authored-by: Nathan Levesque <[email protected]>
Co-authored-by: Arslan <[email protected]>
  • Loading branch information
3 people authored Jan 2, 2024
1 parent ad8ee86 commit 209069f
Show file tree
Hide file tree
Showing 56 changed files with 1,305 additions and 775 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ jobs:
- name: Install dependencies
run: poetry install --no-interaction

- name: Lint
run: poetry run pylint ./**/*.py
# TODO: use ruff or upgrade pylint, pylint-django, and asteroid to support String based model references.
# - name: Lint
# run: poetry run pylint ./**/*.py

- name: Code Formatting (Black)
run: poetry run black --check .
Expand Down
3 changes: 1 addition & 2 deletions cms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import pytz
from django.contrib.contenttypes.models import ContentType
from wagtail.core.models import Page, Site

from wagtail.models import Page, Site
from cms import models as cms_models
from cms.constants import CERTIFICATE_INDEX_SLUG

Expand Down
2 changes: 1 addition & 1 deletion cms/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django import forms
from django.apps import apps
from django.core.exceptions import ValidationError
from wagtail.core import blocks
from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock


Expand Down
48 changes: 33 additions & 15 deletions cms/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ObjectDoesNotExist
from factory.django import DjangoModelFactory
from faker.providers import internet
from wagtail.core.rich_text import RichText
from wagtail.rich_text import RichText

from cms.blocks import (
FacultyBlock,
Expand Down Expand Up @@ -192,7 +192,7 @@ class LearningTechniquesItemFactory(wagtail_factories.StructBlockFactory):

heading = factory.fuzzy.FuzzyText(prefix="heading ")
sub_heading = factory.fuzzy.FuzzyText(prefix="Sub-heading ")
image = factory.SubFactory(wagtail_factories.ImageFactory)
image = factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)

class Meta:
model = LearningTechniqueBlock
Expand All @@ -202,7 +202,7 @@ class LearningTechniquesPageFactory(wagtail_factories.PageFactory):
"""LearningTechniquesPage factory class"""

technique_items = wagtail_factories.StreamFieldFactory(
{"techniques": LearningTechniquesItemFactory}
{"techniques": factory.SubFactory(LearningTechniquesItemFactory)}
)

class Meta:
Expand Down Expand Up @@ -269,12 +269,21 @@ class Meta:
model = WhoShouldEnrollPage


class CoursePageChooserBlockFactory(wagtail_factories.PageChooserBlockFactory):
"""CoursePage chooser factory"""

class Meta:
model = CoursePage


class CoursesInProgramPageFactory(wagtail_factories.PageFactory):
"""CoursesInProgramPage factory class"""

heading = factory.fuzzy.FuzzyText(prefix="Heading ")
body = factory.fuzzy.FuzzyText(prefix="Body ")
contents = wagtail_factories.StreamFieldFactory({"item": CoursePageFactory})
contents = wagtail_factories.StreamFieldFactory(
{"item": factory.SubFactory(CoursePageChooserBlockFactory)}
)

class Meta:
model = CoursesInProgramPage
Expand Down Expand Up @@ -306,7 +315,7 @@ class UserTestimonialBlockFactory(wagtail_factories.StructBlockFactory):

name = factory.fuzzy.FuzzyText(prefix="name ")
title = factory.fuzzy.FuzzyText(prefix="title ")
image = factory.SubFactory(wagtail_factories.ImageFactory)
image = factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)
quote = factory.fuzzy.FuzzyText(prefix="quote ")

class Meta:
Expand All @@ -320,7 +329,7 @@ class UserTestimonialsPageFactory(wagtail_factories.PageFactory):
heading = factory.fuzzy.FuzzyText(prefix="heading ")
subhead = factory.fuzzy.FuzzyText(prefix="subhead ")
items = wagtail_factories.StreamFieldFactory(
{"testimonial": UserTestimonialBlockFactory}
{"testimonial": factory.SubFactory(UserTestimonialBlockFactory)}
)

class Meta:
Expand All @@ -332,7 +341,7 @@ class NewsAndEventsBlockFactory(wagtail_factories.StructBlockFactory):

content_type = factory.fuzzy.FuzzyText(prefix="content_type ")
title = factory.fuzzy.FuzzyText(prefix="title ")
image = factory.SubFactory(wagtail_factories.ImageFactory)
image = factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)
content = factory.fuzzy.FuzzyText(prefix="content ")
call_to_action = factory.fuzzy.FuzzyText(prefix="call_to_action ")
action_url = factory.Faker("uri")
Expand All @@ -346,7 +355,7 @@ class NewsAndEventsPageFactory(wagtail_factories.PageFactory):

heading = factory.fuzzy.FuzzyText(prefix="heading ")
items = wagtail_factories.StreamFieldFactory(
{"news_and_events": NewsAndEventsBlockFactory}
{"news_and_events": factory.SubFactory(NewsAndEventsBlockFactory)}
)

class Meta:
Expand All @@ -357,8 +366,10 @@ class FacultyBlockFactory(wagtail_factories.StructBlockFactory):
"""FacultyBlock factory class"""

name = factory.Faker("name")
image = factory.SubFactory(wagtail_factories.ImageFactory)
text = factory.LazyFunction(lambda: RichText("<p>{}</p>".format(FAKE.paragraph())))
image = factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)
description = factory.LazyFunction(
lambda: RichText("<p>{}</p>".format(FAKE.paragraph()))
)

class Meta:
model = FacultyBlock
Expand All @@ -369,7 +380,9 @@ class FacultyMembersPageFactory(wagtail_factories.PageFactory):

heading = factory.fuzzy.FuzzyText(prefix="heading ")
subhead = factory.fuzzy.FuzzyText(prefix="subhead ")
members = wagtail_factories.StreamFieldFactory({"member": FacultyBlockFactory})
members = wagtail_factories.StreamFieldFactory(
{"member": factory.SubFactory(FacultyBlockFactory)}
)

class Meta:
model = FacultyMembersPage
Expand All @@ -389,7 +402,7 @@ class ImageCarouselPageFactory(wagtail_factories.PageFactory):

title = factory.fuzzy.FuzzyText(prefix="title")
images = wagtail_factories.StreamFieldFactory(
{"image": wagtail_factories.ImageChooserBlockFactory}
{"image": factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)}
)

class Meta:
Expand Down Expand Up @@ -431,8 +444,13 @@ class SignatoryPageFactory(wagtail_factories.PageFactory):
title_1 = factory.fuzzy.FuzzyText(prefix="Title_1")
title_2 = factory.fuzzy.FuzzyText(prefix="Title_2")
organization = factory.fuzzy.FuzzyText(prefix="Organization")
signature_image = factory.SubFactory(wagtail_factories.ImageFactory)
signature_image = factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)

class Meta:
model = SignatoryPage


class SignatoryChooserBlockFactory(wagtail_factories.PageChooserBlockFactory):
class Meta:
model = SignatoryPage

Expand All @@ -442,9 +460,9 @@ class CertificatePageFactory(wagtail_factories.PageFactory):

product_name = factory.fuzzy.FuzzyText(prefix="product_name")
CEUs = factory.Faker("pystr_format", string_format="#.#")
partner_logo = factory.SubFactory(wagtail_factories.ImageFactory)
partner_logo = factory.SubFactory(wagtail_factories.ImageChooserBlockFactory)
signatories = wagtail_factories.StreamFieldFactory(
{"signatory": SignatoryPageFactory}
{"signatory": factory.SubFactory(SignatoryChooserBlockFactory)}
)

class Meta:
Expand Down
24 changes: 12 additions & 12 deletions cms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks


Expand Down Expand Up @@ -34,22 +34,22 @@ class Migration(migrations.Migration):
),
(
"description",
wagtail.core.fields.RichTextField(
wagtail.fields.RichTextField(
blank=True,
help_text="The description shown on the program page",
),
),
(
"content",
wagtail.core.fields.StreamField(
wagtail.fields.StreamField(
[
(
"heading",
wagtail.core.blocks.CharBlock(classname="full title"),
wagtail.blocks.CharBlock(classname="full title"),
),
("paragraph", wagtail.core.blocks.RichTextBlock()),
("paragraph", wagtail.blocks.RichTextBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
("raw_html", wagtail.core.blocks.RawHTMLBlock()),
("raw_html", wagtail.blocks.RawHTMLBlock()),
],
blank=True,
help_text="The content of this tab on the program page",
Expand Down Expand Up @@ -95,22 +95,22 @@ class Migration(migrations.Migration):
),
(
"description",
wagtail.core.fields.RichTextField(
wagtail.fields.RichTextField(
blank=True,
help_text="The description shown on the program page",
),
),
(
"content",
wagtail.core.fields.StreamField(
wagtail.fields.StreamField(
[
(
"heading",
wagtail.core.blocks.CharBlock(classname="full title"),
wagtail.blocks.CharBlock(classname="full title"),
),
("paragraph", wagtail.core.blocks.RichTextBlock()),
("paragraph", wagtail.blocks.RichTextBlock()),
("image", wagtail.images.blocks.ImageChooserBlock()),
("raw_html", wagtail.core.blocks.RawHTMLBlock()),
("raw_html", wagtail.blocks.RawHTMLBlock()),
],
blank=True,
help_text="The content of this tab on the program page",
Expand Down
4 changes: 2 additions & 2 deletions cms/migrations/0004_add_video_title.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 2.1.7 on 2019-04-19 05:44

from django.db import migrations
import wagtail.core.fields
import wagtail.fields


class Migration(migrations.Migration):
Expand All @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="coursepage",
name="video_title",
field=wagtail.core.fields.RichTextField(
field=wagtail.fields.RichTextField(
blank=True, help_text="The title to be displayed for the course video"
),
)
Expand Down
6 changes: 3 additions & 3 deletions cms/migrations/0005_move_fields_to_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.fields
import wagtail.fields


class Migration(migrations.Migration):
Expand Down Expand Up @@ -48,7 +48,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="programpage",
name="video_title",
field=wagtail.core.fields.RichTextField(
field=wagtail.fields.RichTextField(
blank=True,
help_text="The title to be displayed for the program/course video",
),
Expand Down Expand Up @@ -77,7 +77,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="coursepage",
name="video_title",
field=wagtail.core.fields.RichTextField(
field=wagtail.fields.RichTextField(
blank=True,
help_text="The title to be displayed for the program/course video",
),
Expand Down
8 changes: 4 additions & 4 deletions cms/migrations/0008_learningoutcomespage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.blocks
import wagtail.fields


class Migration(migrations.Migration):
Expand Down Expand Up @@ -45,8 +45,8 @@ class Migration(migrations.Migration):
),
(
"outcome_items",
wagtail.core.fields.StreamField(
[("outcome", wagtail.core.blocks.TextBlock(icon="plus"))],
wagtail.fields.StreamField(
[("outcome", wagtail.blocks.TextBlock(icon="plus"))],
help_text="Detail about What you'll learn as learning outcome.",
),
),
Expand Down
16 changes: 6 additions & 10 deletions cms/migrations/0009_learningtechniquespage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks


Expand Down Expand Up @@ -31,23 +31,19 @@ class Migration(migrations.Migration):
),
(
"technique_items",
wagtail.core.fields.StreamField(
wagtail.fields.StreamField(
[
(
"techniques",
wagtail.core.blocks.StructBlock(
wagtail.blocks.StructBlock(
[
(
"heading",
wagtail.core.blocks.CharBlock(
max_length=100
),
wagtail.blocks.CharBlock(max_length=100),
),
(
"sub_heading",
wagtail.core.blocks.CharBlock(
max_length=250
),
wagtail.blocks.CharBlock(max_length=250),
),
(
"image",
Expand Down
4 changes: 2 additions & 2 deletions cms/migrations/0010_add_faqspage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
import wagtail.core.fields
import wagtail.fields


class Migration(migrations.Migration):
Expand Down Expand Up @@ -31,7 +31,7 @@ class Migration(migrations.Migration):
models.IntegerField(blank=True, editable=False, null=True),
),
("question", models.TextField()),
("answer", wagtail.core.fields.RichTextField()),
("answer", wagtail.fields.RichTextField()),
],
options={"ordering": ["sort_order"], "abstract": False},
),
Expand Down
4 changes: 2 additions & 2 deletions cms/migrations/0011_for_teams_subpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import migrations, models
import django.db.models.deletion
import wagtail.core.fields
import wagtail.fields


class Migration(migrations.Migration):
Expand Down Expand Up @@ -30,7 +30,7 @@ class Migration(migrations.Migration):
),
(
"content",
wagtail.core.fields.RichTextField(
wagtail.fields.RichTextField(
help_text="The content shown in the section"
),
),
Expand Down
Loading

0 comments on commit 209069f

Please sign in to comment.