Skip to content

Commit

Permalink
Adjustments to db models
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Jun 20, 2023
1 parent 29ca5b7 commit f3028fb
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 37 deletions.
17 changes: 11 additions & 6 deletions content_migration/management/import_archive_articles_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError
from tqdm import tqdm
from content_migration.management.errors import (
CouldNotFindMatchingContactError,
Expand Down Expand Up @@ -41,6 +42,7 @@ def create_archive_article_authors(

for drupal_author_id in authors_list:
try:
# TODO: determine if this is the cause of importer slowness
contact = get_existing_magazine_author_from_db(
drupal_author_id,
)
Expand All @@ -50,18 +52,21 @@ def create_archive_article_authors(
):
continue

article_author_exists = ArchiveArticleAuthor.objects.filter(
article=archive_article,
author=contact,
).exists()

if not article_author_exists:
# TODO: determine if this is the cause of importer slowness
# For performance reasons,
# check if the ArchiveArticleAuthor instance already exists
# using the unique together constraint (implicit check)
try:
article_author = ArchiveArticleAuthor(
article=archive_article,
author=contact,
)

article_author.save()
# handle unique together constraint exception
except IntegrityError as e:
logger.error(e)
continue


def handle_import_archive_articles(file_name: str) -> None:
Expand Down
137 changes: 137 additions & 0 deletions library/migrations/0017_alter_libraryitem_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Generated by Django 4.2.1 on 2023-06-20 09:59

import blocks.blocks
import django.core.validators
from django.db import migrations
import documents.blocks
import re
import wagtail.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtail_color_panel.blocks


class Migration(migrations.Migration):
dependencies = [
("library", "0001_squashed_0016_alter_libraryitem_body"),
]

operations = [
migrations.AlterField(
model_name="libraryitem",
name="body",
field=wagtail.fields.StreamField(
[
(
"heading",
wagtail.blocks.StructBlock(
[
(
"heading_level",
wagtail.blocks.ChoiceBlock(
choices=[
("h2", "Level 2 (child of level 1)"),
("h3", "Level 3 (child of level 2)"),
("h4", "Level 4 (child of level 3)"),
("h5", "Level 5 (child of level 4)"),
("h6", "Level 6 (child of level 5)"),
],
help_text="These different heading levels help to communicate the organization and hierarchy of the content on a page.",
),
),
(
"heading_text",
wagtail.blocks.CharBlock(
help_text="The text to appear in the heading."
),
),
(
"target_slug",
wagtail.blocks.CharBlock(
help_text="Used to link to a specific location within this page. A slug should only contain letters, numbers, underscore (_), or hyphen (-).",
required=False,
validators=(
django.core.validators.RegexValidator(
re.compile("^[-a-zA-Z0-9_]+\\Z"),
"Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.",
"invalid",
),
),
),
),
(
"color",
wagtail_color_panel.blocks.NativeColorBlock(
required=False
),
),
]
),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=["bold", "italic", "ol", "ul", "link", "hr"]
),
),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"width",
wagtail.blocks.IntegerBlock(
help_text="Enter the desired image width value in pixels up to 800 max.",
max_value=800,
min_value=0,
),
),
(
"align",
wagtail.blocks.ChoiceBlock(
choices=[("left", "Left"), ("right", "Right")],
help_test="Optionally align image left or right",
icon="file-richtext",
required=False,
),
),
(
"link",
wagtail.blocks.URLBlock(
help_text="Optional web address to use as image link.",
required=False,
),
),
],
classname="full title",
),
),
("document", documents.blocks.DocumentEmbedBlock()),
("media", blocks.blocks.MediaBlock(icon="media")),
("embed", wagtail.embeds.blocks.EmbedBlock()),
("url", blocks.blocks.WfURLBlock()),
("pullquote", blocks.blocks.PullQuoteBlock()),
(
"spacer",
wagtail.blocks.StructBlock(
[
(
"height",
wagtail.blocks.DecimalBlock(
decimal_places=1,
help_text="The height of this spacer in 'em' values where 1 em is one uppercase M.",
min_value=0,
),
)
]
),
),
],
blank=True,
null=True,
use_json_field=True,
),
),
]
33 changes: 7 additions & 26 deletions library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
FormattedImageChooserStructBlock,
HeadingBlock,
MediaBlock,
PullQuoteBlock,
SpacerBlock,
WfURLBlock,
)
Expand All @@ -42,16 +43,11 @@ class LibraryItem(Page):
description = RichTextField(null=True, blank=True)
body = StreamField(
[
(
"heading",
HeadingBlock(),
),
("heading", HeadingBlock()),
(
"rich_text",
wagtail_blocks.RichTextBlock(
features=[
"h2",
"h3",
"bold",
"italic",
"ol",
Expand All @@ -67,32 +63,17 @@ class LibraryItem(Page):
classname="full title",
),
),
(
"document",
DocumentEmbedBlock(),
),
("document", DocumentEmbedBlock()),
(
"media",
MediaBlock(
icon="media",
),
),
(
"embed",
EmbedBlock(),
),
(
"url",
WfURLBlock(),
),
(
"quote",
wagtail_blocks.BlockQuoteBlock(),
),
(
"spacer",
SpacerBlock(),
),
("embed", EmbedBlock()),
("url", WfURLBlock()),
("pullquote", PullQuoteBlock()),
("spacer", SpacerBlock()),
],
null=True,
blank=True,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Generated by Django 4.2.1 on 2023-06-20 09:59

import blocks.blocks
import django.core.validators
from django.db import migrations
import documents.blocks
import re
import wagtail.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtail_color_panel.blocks


class Migration(migrations.Migration):
dependencies = [
("wagtailcore", "0083_workflowcontenttype"),
("magazine", "0001_squashed_0024_magazineissue_magazine_ma_drupal__50c0bf_idx"),
]

operations = [
migrations.AlterModelOptions(
name="archivearticleauthor",
options={},
),
migrations.AlterField(
model_name="magazinearticle",
name="body",
field=wagtail.fields.StreamField(
[
(
"heading",
wagtail.blocks.StructBlock(
[
(
"heading_level",
wagtail.blocks.ChoiceBlock(
choices=[
("h2", "Level 2 (child of level 1)"),
("h3", "Level 3 (child of level 2)"),
("h4", "Level 4 (child of level 3)"),
("h5", "Level 5 (child of level 4)"),
("h6", "Level 6 (child of level 5)"),
],
help_text="These different heading levels help to communicate the organization and hierarchy of the content on a page.",
),
),
(
"heading_text",
wagtail.blocks.CharBlock(
help_text="The text to appear in the heading."
),
),
(
"target_slug",
wagtail.blocks.CharBlock(
help_text="Used to link to a specific location within this page. A slug should only contain letters, numbers, underscore (_), or hyphen (-).",
required=False,
validators=(
django.core.validators.RegexValidator(
re.compile("^[-a-zA-Z0-9_]+\\Z"),
"Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.",
"invalid",
),
),
),
),
(
"color",
wagtail_color_panel.blocks.NativeColorBlock(
required=False
),
),
]
),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"hr",
"link",
"document-link",
"superscript",
"superscript",
"strikethrough",
]
),
),
("pullquote", blocks.blocks.PullQuoteBlock()),
("document", documents.blocks.DocumentEmbedBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"width",
wagtail.blocks.IntegerBlock(
help_text="Enter the desired image width value in pixels up to 800 max.",
max_value=800,
min_value=0,
),
),
(
"align",
wagtail.blocks.ChoiceBlock(
choices=[("left", "Left"), ("right", "Right")],
help_test="Optionally align image left or right",
icon="file-richtext",
required=False,
),
),
(
"link",
wagtail.blocks.URLBlock(
help_text="Optional web address to use as image link.",
required=False,
),
),
],
classname="full title",
),
),
(
"spacer",
wagtail.blocks.StructBlock(
[
(
"height",
wagtail.blocks.DecimalBlock(
decimal_places=1,
help_text="The height of this spacer in 'em' values where 1 em is one uppercase M.",
min_value=0,
),
)
]
),
),
],
use_json_field=True,
),
),
migrations.AlterUniqueTogether(
name="archivearticleauthor",
unique_together={("article", "author")},
),
]
Loading

0 comments on commit f3028fb

Please sign in to comment.