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.
This commit is contained in:
parent
3c73c209a7
commit
308b0f978f
|
@ -4,3 +4,4 @@
|
|||
__pycache__
|
||||
db.sqlite3
|
||||
media
|
||||
uploads/
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<form action="{% url 'import_books' %}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<input type="text" name="bookname">
|
||||
<input type="file" name="bookpdf">
|
||||
<input type="submit" value="Import PDF">
|
||||
</form>
|
||||
|
||||
{% if just_imported %}
|
||||
thanks for the import!
|
||||
{% endif %}
|
|
@ -0,0 +1,9 @@
|
|||
{% if legislative_texts %}
|
||||
<ul>
|
||||
{% for text in legislative_texts %}
|
||||
<li><a href="{% url 'viewleg' text.id %}">{{ text.legislation_title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No texts available</p>
|
||||
{% endif %}
|
|
@ -0,0 +1,9 @@
|
|||
<h1>{{ legislation.legislation_title }}</h1>
|
||||
|
||||
<i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i>
|
||||
|
||||
<p>Sponsored by {{ legislation.sponsors }} of {{ legislation.school }}</p>
|
||||
|
||||
<blockquote>
|
||||
{{ legislation.text }}
|
||||
</blockquote>
|
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"),
|
||||
path("import/", views.import_books, name="import_books"),
|
||||
]
|
|
@ -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)
|
||||
|
|
|
@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
|
|||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'explorer.apps.ExplorerConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
|
|
@ -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),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue