From 31369f9c406ff0b06a9aadda4eec5a7fc4944792 Mon Sep 17 00:00:00 2001 From: William Palin Date: Mon, 25 Sep 2023 22:02:23 -0400 Subject: [PATCH] refactor(cl.search): More changes for PR --- .../migrations/0020_courthouse_and_more.py | 36 ++++++++----------- .../migrations/0020_courthouse_and_more.sql | 30 ++++++---------- cl/search/models.py | 36 ++++++++----------- 3 files changed, 40 insertions(+), 62 deletions(-) diff --git a/cl/search/migrations/0020_courthouse_and_more.py b/cl/search/migrations/0020_courthouse_and_more.py index 4463c9dc1c..594462c9a9 100644 --- a/cl/search/migrations/0020_courthouse_and_more.py +++ b/cl/search/migrations/0020_courthouse_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.4 on 2023-09-25 22:40 +# Generated by Django 4.2.4 on 2023-09-26 02:01 from django.db import migrations, models import django.db.models.deletion @@ -29,23 +29,20 @@ class Migration(migrations.Migration): "court_seat", models.BooleanField( default=False, - help_text="Is this the seat of the Court.", + help_text="Is this the seat of the Court?", null=True, ), ), ( "building_name", models.TextField( - blank=True, - help_text="Ex. John Adams Courthouse", - verbose_name="Courthouse building name.", + blank=True, help_text="Ex. John Adams Courthouse." ), ), ( "address1", models.TextField( blank=True, - db_index=True, help_text="The normalized address1 of the courthouse.", ), ), @@ -53,7 +50,6 @@ class Migration(migrations.Migration): "address2", models.TextField( blank=True, - db_index=True, help_text="The normalized address2 of the courthouse.", ), ), @@ -61,23 +57,20 @@ class Migration(migrations.Migration): "city", models.TextField( blank=True, - db_index=True, - help_text="The normalized city of the organization.", + help_text="The normalized city of the courthouse.", ), ), ( "county", models.TextField( blank=True, - help_text="The county, if any, where the court resides.", + help_text="The county, if any, where the courthouse resides.", ), ), ( "state", localflavor.us.models.USPostalCodeField( blank=True, - null=True, - db_index=True, help_text="The two-letter USPS postal abbreviation for the organization w/ obsolete state options.", max_length=2, ), @@ -85,19 +78,20 @@ class Migration(migrations.Migration): ( "zip_code", localflavor.us.models.USZipCodeField( - null=True, blank=True, - db_index=True, help_text="The zip code for the organization, XXXXX or XXXXX-XXXX work.", max_length=10, ), ), ( "country_code", - models.CharField( + models.TextField( + choices=[ + ("GB", "United Kingdom"), + ("US", "United States"), + ], default="US", - help_text="The two letter country code", - max_length=2, + help_text="The two letter country code.", ), ), ], @@ -115,11 +109,11 @@ class Migration(migrations.Migration): ), migrations.AddField( model_name="court", - name="appellate_courts", + name="appeals_to", field=models.ManyToManyField( blank=True, help_text="Appellate courts for this court", - related_name="appellate_courts_to", + related_name="appeals_from", to="search.court", ), ), @@ -131,7 +125,7 @@ class Migration(migrations.Migration): help_text="Parent court for subdivisions", null=True, on_delete=django.db.models.deletion.SET_NULL, - related_name="subcourts", + related_name="child_courts", to="search.court", ), ), @@ -248,7 +242,7 @@ class Migration(migrations.Migration): model_name="courthouse", name="court", field=models.ForeignKey( - help_text="The court object associated with this Courthouse.", + help_text="The court object associated with this courthouse.", on_delete=django.db.models.deletion.CASCADE, related_name="courts", to="search.court", diff --git a/cl/search/migrations/0020_courthouse_and_more.sql b/cl/search/migrations/0020_courthouse_and_more.sql index cf6448f445..3a4937ae3b 100644 --- a/cl/search/migrations/0020_courthouse_and_more.sql +++ b/cl/search/migrations/0020_courthouse_and_more.sql @@ -2,7 +2,7 @@ BEGIN; -- -- Create model Courthouse -- -CREATE TABLE "search_courthouse" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "court_seat" boolean NULL, "building_name" text NOT NULL, "address1" text NOT NULL, "address2" text NOT NULL, "city" text NOT NULL, "county" text NOT NULL, "state" varchar(2) NULL, "zip_code" varchar(10) NULL, "country_code" varchar(2) NOT NULL); +CREATE TABLE "search_courthouse" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "court_seat" boolean NULL, "building_name" text NOT NULL, "address1" text NOT NULL, "address2" text NOT NULL, "city" text NOT NULL, "county" text NOT NULL, "state" varchar(2) NOT NULL, "zip_code" varchar(10) NOT NULL, "country_code" text NOT NULL); -- -- Remove trigger update_or_delete_snapshot_delete from model court -- @@ -12,9 +12,9 @@ DROP TRIGGER IF EXISTS pgtrigger_update_or_delete_snapshot_delete_84ec4 ON "sear -- DROP TRIGGER IF EXISTS pgtrigger_update_or_delete_snapshot_update_c94ab ON "search_court"; -- --- Add field appellate_courts to court +-- Add field appeals_to to court -- -CREATE TABLE "search_court_appellate_courts" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "from_court_id" varchar(15) NOT NULL, "to_court_id" varchar(15) NOT NULL); +CREATE TABLE "search_court_appeals_to" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "from_court_id" varchar(15) NOT NULL, "to_court_id" varchar(15) NOT NULL); -- -- Add field parent_court to court -- @@ -139,23 +139,13 @@ ALTER TABLE "search_courtevent" ADD COLUMN "parent_court_id" varchar(15) NULL; -- Add field court to courthouse -- ALTER TABLE "search_courthouse" ADD COLUMN "court_id" varchar(15) NOT NULL CONSTRAINT "search_courthouse_court_id_6528f572_fk_search_court_id" REFERENCES "search_court"("id") DEFERRABLE INITIALLY DEFERRED; SET CONSTRAINTS "search_courthouse_court_id_6528f572_fk_search_court_id" IMMEDIATE; -CREATE INDEX "search_courthouse_address1_713c70f8" ON "search_courthouse" ("address1"); -CREATE INDEX "search_courthouse_address1_713c70f8_like" ON "search_courthouse" ("address1" text_pattern_ops); -CREATE INDEX "search_courthouse_address2_6344113f" ON "search_courthouse" ("address2"); -CREATE INDEX "search_courthouse_address2_6344113f_like" ON "search_courthouse" ("address2" text_pattern_ops); -CREATE INDEX "search_courthouse_city_4a7c0fb2" ON "search_courthouse" ("city"); -CREATE INDEX "search_courthouse_city_4a7c0fb2_like" ON "search_courthouse" ("city" text_pattern_ops); -CREATE INDEX "search_courthouse_state_8a5794a6" ON "search_courthouse" ("state"); -CREATE INDEX "search_courthouse_state_8a5794a6_like" ON "search_courthouse" ("state" varchar_pattern_ops); -CREATE INDEX "search_courthouse_zip_code_160c45c9" ON "search_courthouse" ("zip_code"); -CREATE INDEX "search_courthouse_zip_code_160c45c9_like" ON "search_courthouse" ("zip_code" varchar_pattern_ops); -ALTER TABLE "search_court_appellate_courts" ADD CONSTRAINT "search_court_appellate_c_from_court_id_to_court_i_c508e354_uniq" UNIQUE ("from_court_id", "to_court_id"); -ALTER TABLE "search_court_appellate_courts" ADD CONSTRAINT "search_court_appella_from_court_id_203006c3_fk_search_co" FOREIGN KEY ("from_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED; -ALTER TABLE "search_court_appellate_courts" ADD CONSTRAINT "search_court_appella_to_court_id_fca7514b_fk_search_co" FOREIGN KEY ("to_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED; -CREATE INDEX "search_court_appellate_courts_from_court_id_203006c3" ON "search_court_appellate_courts" ("from_court_id"); -CREATE INDEX "search_court_appellate_courts_from_court_id_203006c3_like" ON "search_court_appellate_courts" ("from_court_id" varchar_pattern_ops); -CREATE INDEX "search_court_appellate_courts_to_court_id_fca7514b" ON "search_court_appellate_courts" ("to_court_id"); -CREATE INDEX "search_court_appellate_courts_to_court_id_fca7514b_like" ON "search_court_appellate_courts" ("to_court_id" varchar_pattern_ops); +ALTER TABLE "search_court_appeals_to" ADD CONSTRAINT "search_court_appeals_to_from_court_id_to_court_id_006ed7af_uniq" UNIQUE ("from_court_id", "to_court_id"); +ALTER TABLE "search_court_appeals_to" ADD CONSTRAINT "search_court_appeals_from_court_id_fb09cc1a_fk_search_co" FOREIGN KEY ("from_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED; +ALTER TABLE "search_court_appeals_to" ADD CONSTRAINT "search_court_appeals_to_to_court_id_49ac3d9c_fk_search_court_id" FOREIGN KEY ("to_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED; +CREATE INDEX "search_court_appeals_to_from_court_id_fb09cc1a" ON "search_court_appeals_to" ("from_court_id"); +CREATE INDEX "search_court_appeals_to_from_court_id_fb09cc1a_like" ON "search_court_appeals_to" ("from_court_id" varchar_pattern_ops); +CREATE INDEX "search_court_appeals_to_to_court_id_49ac3d9c" ON "search_court_appeals_to" ("to_court_id"); +CREATE INDEX "search_court_appeals_to_to_court_id_49ac3d9c_like" ON "search_court_appeals_to" ("to_court_id" varchar_pattern_ops); CREATE INDEX "search_court_parent_court_id_51ba1d28" ON "search_court" ("parent_court_id"); CREATE INDEX "search_court_parent_court_id_51ba1d28_like" ON "search_court" ("parent_court_id" varchar_pattern_ops); CREATE INDEX "search_courtevent_parent_court_id_342036cc" ON "search_courtevent" ("parent_court_id"); diff --git a/cl/search/models.py b/cl/search/models.py index da6b76ccdc..544bcead44 100644 --- a/cl/search/models.py +++ b/cl/search/models.py @@ -2034,18 +2034,18 @@ class Court(models.Model): ) parent_court = models.ForeignKey( "self", + help_text="Parent court for subdivisions", on_delete=models.SET_NULL, blank=True, null=True, - related_name="subcourts", - help_text="Parent court for subdivisions", + related_name="child_courts", ) - appellate_courts = models.ManyToManyField( + appeals_to = models.ManyToManyField( "self", + help_text="Appellate courts for this court", blank=True, symmetrical=False, - related_name="appellate_courts_to", - help_text="Appellate courts for this court", + related_name="appeals_from", ) # Pacer fields pacer_court_id = models.PositiveSmallIntegerField( @@ -2174,59 +2174,53 @@ class Meta: class Courthouse(models.Model): """A class to represent the physical location of a court.""" + COUNTRY_CHOICES = (("GB", "United Kingdom"), ("US", "United States")) + court = models.ForeignKey( Court, - help_text="The court object associated with this Courthouse.", + help_text="The court object associated with this courthouse.", related_name="courts", on_delete=models.CASCADE, ) court_seat = models.BooleanField( - help_text="Is this the seat of the Court.", + help_text="Is this the seat of the Court?", default=False, null=True, ) building_name = models.TextField( - verbose_name="Courthouse building name.", - help_text="Ex. John Adams Courthouse", + help_text="Ex. John Adams Courthouse.", blank=True, ) address1 = models.TextField( help_text="The normalized address1 of the courthouse.", - db_index=True, blank=True, ) address2 = models.TextField( help_text="The normalized address2 of the courthouse.", - db_index=True, blank=True, ) city = models.TextField( - help_text="The normalized city of the organization.", - db_index=True, + help_text="The normalized city of the courthouse.", blank=True, ) county = models.TextField( - help_text="The county, if any, where the court resides.", + help_text="The county, if any, where the courthouse resides.", blank=True, ) state = USPostalCodeField( help_text="The two-letter USPS postal abbreviation for the " "organization w/ obsolete state options.", - db_index=True, choices=USPS_CHOICES + OBSOLETE_STATES, - null=True, blank=True, ) zip_code = USZipCodeField( help_text="The zip code for the organization, XXXXX or XXXXX-XXXX " "work.", - db_index=True, blank=True, - null=True, ) - country_code = models.CharField( - help_text="The two letter country code", - max_length=2, + country_code = models.TextField( + help_text="The two letter country code.", + choices=COUNTRY_CHOICES, default="US", )