Skip to content

Commit

Permalink
Merge pull request #2019 from laws-africa/metadata
Browse files Browse the repository at this point in the history
Move metadata field to coredocument model
  • Loading branch information
actlikewill authored Sep 12, 2024
2 parents 11cdebd + f80a9a2 commit 884257b
Show file tree
Hide file tree
Showing 7 changed files with 755 additions and 685 deletions.
8 changes: 2 additions & 6 deletions liiweb/views/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ def get_variant_queryset(self, qs):
elif self.variant == "repealed":
qs = qs.filter(repealed=True)
elif self.variant == "current":
qs = qs.filter(
repealed=False, metadata_json__principal=True, parent_work=None
)
qs = qs.filter(repealed=False, principal=True, parent_work=None)
elif self.variant == "subleg":
qs = qs.exclude(parent_work=None).filter(
repealed=False, metadata_json__principal=True
)
qs = qs.exclude(parent_work=None).filter(repealed=False, principal=True)
elif self.variant == "uncommenced":
qs = qs.filter(metadata_json__commenced=False)
elif self.variant == "recent":
Expand Down
1,352 changes: 676 additions & 676 deletions peachjam/fixtures/documents/sample_documents.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.15 on 2024-09-11 09:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0155_entityprofile_title"),
]

operations = [
migrations.RenameField(
model_name="legislation",
old_name="metadata_json",
new_name="old_metadata_json",
),
migrations.AddField(
model_name="coredocument",
name="metadata_json",
field=models.JSONField(blank=True, null=True, verbose_name="metadata JSON"),
),
migrations.AddField(
model_name="legislation",
name="principal",
field=models.BooleanField(default=False, verbose_name="principal"),
),
]
26 changes: 26 additions & 0 deletions peachjam/migrations/0157_backfill_metadata_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.15 on 2024-09-11 09:20

from django.db import migrations


def backfill_metadata_json(apps, schema_editor):
Legislation = apps.get_model("peachjam", "Legislation")

for leg in Legislation.objects.iterator(100):
leg.metadata_json = leg.old_metadata_json
leg.principal = leg.old_metadata_json["principal"]
leg.save()


class Migration(migrations.Migration):

dependencies = [
(
"peachjam",
"0156_rename_metadata_json_legislation_old_metadata_json_and_more",
),
]

operations = [
migrations.RunPython(backfill_metadata_json, migrations.RunPython.noop)
]
18 changes: 18 additions & 0 deletions peachjam/migrations/0158_alter_legislation_old_metadata_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-09-11 10:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("peachjam", "0157_backfill_metadata_json"),
]

operations = [
migrations.AlterField(
model_name="legislation",
name="old_metadata_json",
field=models.JSONField(blank=True, null=True, verbose_name="metadata JSON"),
),
]
3 changes: 2 additions & 1 deletion peachjam/models/core_document_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def __str__(self):
class CoreDocumentManager(PolymorphicManager):
def get_queryset(self):
# defer expensive fields
return super().get_queryset().defer("content_html", "toc_json")
return super().get_queryset().defer("content_html", "toc_json", "metadata_json")

def get_qs_no_defer(self):
return super().get_queryset()
Expand Down Expand Up @@ -461,6 +461,7 @@ class CoreDocument(PolymorphicModel):
db_index=True,
help_text=_("Is this document published and visible on the website?"),
)
metadata_json = models.JSONField(_("metadata JSON"), null=True, blank=True)

# options for the FRBR URI doctypes
frbr_uri_doctypes = FRBR_URI_DOCTYPES
Expand Down
5 changes: 3 additions & 2 deletions peachjam/models/generic_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def get_queryset(self):
return (
super()
.get_queryset()
.defer("metadata_json", "timeline_json", "commencements_json")
.defer("old_metadata_json", "timeline_json", "commencements_json")
)


class Legislation(CoreDocument):
objects = LegislationManager.from_queryset(CoreDocumentQuerySet)()

metadata_json = models.JSONField(_("metadata JSON"), null=False, blank=False)
old_metadata_json = models.JSONField(_("metadata JSON"), null=True, blank=True)
timeline_json = models.JSONField(
_("timeline JSON"), null=False, blank=False, default=list
)
Expand All @@ -82,6 +82,7 @@ class Legislation(CoreDocument):
parent_work = models.ForeignKey(
Work, null=True, on_delete=models.PROTECT, verbose_name=_("parent work")
)
principal = models.BooleanField(_("principal"), default=False, null=False)

frbr_uri_doctypes = ["act"]

Expand Down

0 comments on commit 884257b

Please sign in to comment.