From 308b0f978f9cf3513f59cfe28c64096b44cb8402 Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Wed, 19 Jun 2024 05:41:13 -0500 Subject: [PATCH] created LegislativeText and LegislationBook models, wired them - Created the LegislativeText and LegislationBook models, and wired them to primitive web interfaces. - Created an import-like mechanism for users to import books into the database with. Need to integrate previous bill-book parsing code. --- .gitignore | 1 + franklincce/explorer/admin.py | 5 +- .../explorer/migrations/0001_initial.py | 39 ++++++++++++++ .../0002_legislativetext_legislation_title.py | 19 +++++++ franklincce/explorer/models.py | 54 ++++++++++++++++++- .../explorer/templates/explorer/import.html | 10 ++++ .../explorer/templates/explorer/index.html | 9 ++++ .../templates/explorer/legislation.html | 9 ++++ franklincce/explorer/urls.py | 9 ++++ franklincce/explorer/views.py | 31 ++++++++++- franklincce/franklincce/settings.py | 1 + franklincce/franklincce/urls.py | 3 +- 12 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 franklincce/explorer/migrations/0001_initial.py create mode 100644 franklincce/explorer/migrations/0002_legislativetext_legislation_title.py create mode 100644 franklincce/explorer/templates/explorer/import.html create mode 100644 franklincce/explorer/templates/explorer/index.html create mode 100644 franklincce/explorer/templates/explorer/legislation.html create mode 100644 franklincce/explorer/urls.py diff --git a/.gitignore b/.gitignore index dd54617..28c5001 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__ db.sqlite3 media +uploads/ diff --git a/franklincce/explorer/admin.py b/franklincce/explorer/admin.py index 8c38f3f..2462c9e 100644 --- a/franklincce/explorer/admin.py +++ b/franklincce/explorer/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. +from .models import LegislativeText, LegislationBook + +admin.site.register(LegislativeText) +admin.site.register(LegislationBook) diff --git a/franklincce/explorer/migrations/0001_initial.py b/franklincce/explorer/migrations/0001_initial.py new file mode 100644 index 0000000..40722dc --- /dev/null +++ b/franklincce/explorer/migrations/0001_initial.py @@ -0,0 +1,39 @@ +# Generated by Django 4.2.12 on 2024-06-19 06:53 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='LegislationBook', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('conference_type', models.CharField(choices=[('M', 'Middle School'), ('H', 'High School')], default='H', max_length=1)), + ('pdf', models.FileField(upload_to='uploads/')), + ('name', models.CharField(max_length=256)), + ('import_strategy', models.CharField(max_length=128)), + ], + ), + migrations.CreateModel( + name='LegislativeText', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('assembly', models.CharField(choices=[('RGA', 'Red General Assembly'), ('BGA', 'Blue General Assembly'), ('WGA', 'White General Assembly'), ('RHB', 'Red House'), ('BHB', 'Blue House'), ('WHB', 'White House'), ('RSB', 'Red Senate'), ('BSB', 'Blue Senate'), ('WSB', 'White Senate'), ('SEN', 'Senate'), ('HOU', 'House'), ('GEN', 'General Assembly')], default='GEN', max_length=3)), + ('text', models.TextField()), + ('year', models.IntegerField()), + ('committee', models.IntegerField()), + ('docket_order', models.IntegerField()), + ('school', models.CharField(max_length=256)), + ('sponsors', models.CharField(max_length=256)), + ('from_book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='explorer.legislationbook')), + ], + ), + ] diff --git a/franklincce/explorer/migrations/0002_legislativetext_legislation_title.py b/franklincce/explorer/migrations/0002_legislativetext_legislation_title.py new file mode 100644 index 0000000..27ad0bc --- /dev/null +++ b/franklincce/explorer/migrations/0002_legislativetext_legislation_title.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.12 on 2024-06-19 07:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('explorer', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='legislativetext', + name='legislation_title', + field=models.CharField(default='Sample title', max_length=512), + preserve_default=False, + ), + ] diff --git a/franklincce/explorer/models.py b/franklincce/explorer/models.py index 71a8362..e8e30c5 100644 --- a/franklincce/explorer/models.py +++ b/franklincce/explorer/models.py @@ -1,3 +1,55 @@ from django.db import models +from django.utils.translation import gettext_lazy as _ -# Create your models here. +class LegislationBook(models.Model): + class ConferenceType(models.TextChoices): + MIDDLE = "M", _("Middle School") + HIGH = "H", _("High School") + + conference_type = models.CharField( + max_length=1, + choices=ConferenceType.choices, + default=ConferenceType.HIGH, + ) + pdf = models.FileField(upload_to="uploads/") + name = models.CharField(max_length=256) + import_strategy = models.CharField(max_length=128) + + def __str__(self): + return "{}".format(self.name) + +class LegislativeText(models.Model): + class Assemblies(models.TextChoices): + RGA = "RGA", _("Red General Assembly") + BGA = "BGA", _("Blue General Assembly") + WGA = "WGA", _("White General Assembly") + RHB = "RHB", _("Red House") + BHB = "BHB", _("Blue House") + WHB = "WHB", _("White House") + RSB = "RSB", _("Red Senate") + BSB = "BSB", _("Blue Senate") + WSB = "WSB", _("White Senate") + SEN = "SEN", _("Senate") + HOU = "HOU", _("House") + GEN = "GEN", _("General Assembly") + + assembly = models.CharField( + max_length=3, + choices=Assemblies.choices, + default=Assemblies.GEN + ) + text = models.TextField() + year = models.IntegerField() + committee = models.IntegerField() + docket_order = models.IntegerField() + school = models.CharField(max_length=256) + sponsors = models.CharField(max_length=256) + from_book = models.ForeignKey(LegislationBook, on_delete=models.CASCADE) + legislation_title = models.CharField(max_length=512) + + def __str__(self): + return "{}/{}-{}".format( + self.assembly, + self.committee, + self.docket_order, + ) diff --git a/franklincce/explorer/templates/explorer/import.html b/franklincce/explorer/templates/explorer/import.html new file mode 100644 index 0000000..8d32763 --- /dev/null +++ b/franklincce/explorer/templates/explorer/import.html @@ -0,0 +1,10 @@ +
+{% csrf_token %} + + + +
+ +{% if just_imported %} +thanks for the import! +{% endif %} diff --git a/franklincce/explorer/templates/explorer/index.html b/franklincce/explorer/templates/explorer/index.html new file mode 100644 index 0000000..8c8a495 --- /dev/null +++ b/franklincce/explorer/templates/explorer/index.html @@ -0,0 +1,9 @@ +{% if legislative_texts %} + +{% else %} +

No texts available

+{% endif %} diff --git a/franklincce/explorer/templates/explorer/legislation.html b/franklincce/explorer/templates/explorer/legislation.html new file mode 100644 index 0000000..a5bb810 --- /dev/null +++ b/franklincce/explorer/templates/explorer/legislation.html @@ -0,0 +1,9 @@ +

{{ legislation.legislation_title }}

+ +{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }} + +

Sponsored by {{ legislation.sponsors }} of {{ legislation.school }}

+ +
+ {{ legislation.text }} +
diff --git a/franklincce/explorer/urls.py b/franklincce/explorer/urls.py new file mode 100644 index 0000000..3487de4 --- /dev/null +++ b/franklincce/explorer/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.index, name="index"), + path("legislation//", views.view_legislation, name="viewleg"), + path("import/", views.import_books, name="import_books"), +] diff --git a/franklincce/explorer/views.py b/franklincce/explorer/views.py index 91ea44a..07694b1 100644 --- a/franklincce/explorer/views.py +++ b/franklincce/explorer/views.py @@ -1,3 +1,30 @@ -from django.shortcuts import render +from django.shortcuts import get_object_or_404, render +from django.http import HttpResponse -# Create your views here. +from .models import LegislativeText, LegislationBook + +def index(request): + legislative_texts = LegislativeText.objects.all()[:5] + context = { + "legislative_texts": legislative_texts, + } + return render(request, "explorer/index.html", context) + +def import_books(request): + if request.method == "GET": + return render(request, "explorer/import.html", {}) + elif request.method == "POST": + book = LegislationBook( + pdf=request.FILES["bookpdf"], + name=request.POST.get("bookname"), + conference_type="H", + ) + book.save() + return render(request, "explorer/import.html", {just_imported: True}) + +def view_legislation(request, legislation_id): + legislation = get_object_or_404(LegislativeText, pk=legislation_id) + context = { + "legislation": legislation, + } + return render(request, "explorer/legislation.html", context) diff --git a/franklincce/franklincce/settings.py b/franklincce/franklincce/settings.py index 8df6ea8..2e09de0 100644 --- a/franklincce/franklincce/settings.py +++ b/franklincce/franklincce/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'explorer.apps.ExplorerConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/franklincce/franklincce/urls.py b/franklincce/franklincce/urls.py index aad0a94..8b4072b 100644 --- a/franklincce/franklincce/urls.py +++ b/franklincce/franklincce/urls.py @@ -15,8 +15,9 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import include, path urlpatterns = [ + path('explorer/', include("explorer.urls")), path('admin/', admin.site.urls), ]