add a School model
This commit is contained in:
parent
761b00eb49
commit
de4575a2f0
|
@ -11,7 +11,8 @@ class LegislationBookAdmin(admin.ModelAdmin):
|
||||||
to_register = [
|
to_register = [
|
||||||
[models.LegislativeText, LegislativeTextAdmin],
|
[models.LegislativeText, LegislativeTextAdmin],
|
||||||
[models.LegislationBook, LegislationBookAdmin],
|
[models.LegislationBook, LegislationBookAdmin],
|
||||||
[models.LegislationClassification]
|
[models.LegislationClassification],
|
||||||
|
[models.School],
|
||||||
]
|
]
|
||||||
for i in to_register:
|
for i in to_register:
|
||||||
admin.site.register(*i)
|
admin.site.register(*i)
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 4.2.12 on 2024-06-30 03:57
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('explorer', '0007_legislativetext_category_legislativetext_country'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='School',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=256)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='legislativetext',
|
||||||
|
name='school',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='explorer.school'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -7,6 +7,25 @@ import fitz
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
def ForeignInstantiateIfNone(model, name):
|
||||||
|
"""
|
||||||
|
Search the model for instances by name.
|
||||||
|
If there's none, then create one.
|
||||||
|
"""
|
||||||
|
filtered = model.objects.filter(name__exact=name)
|
||||||
|
try:
|
||||||
|
return filtered[0]
|
||||||
|
except IndexError:
|
||||||
|
obj = model(name=name)
|
||||||
|
obj.save()
|
||||||
|
return obj
|
||||||
|
|
||||||
|
class School(models.Model):
|
||||||
|
name = models.CharField(max_length=256)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class LegislationBook(models.Model):
|
class LegislationBook(models.Model):
|
||||||
class ConferenceType(models.TextChoices):
|
class ConferenceType(models.TextChoices):
|
||||||
MIDDLE = "M", _("Middle School")
|
MIDDLE = "M", _("Middle School")
|
||||||
|
@ -47,6 +66,7 @@ class LegislationBook(models.Model):
|
||||||
return
|
return
|
||||||
|
|
||||||
for text in parsed.output:
|
for text in parsed.output:
|
||||||
|
text["school"] = ForeignInstantiateIfNone(School, text["school"])
|
||||||
text = LegislativeText(**text, from_book=self)
|
text = LegislativeText(**text, from_book=self)
|
||||||
text.save()
|
text.save()
|
||||||
|
|
||||||
|
@ -78,7 +98,7 @@ class LegislativeText(models.Model):
|
||||||
committee = models.IntegerField()
|
committee = models.IntegerField()
|
||||||
category = models.CharField(max_length=256)
|
category = models.CharField(max_length=256)
|
||||||
docket_order = models.IntegerField()
|
docket_order = models.IntegerField()
|
||||||
school = models.CharField(max_length=256)
|
school = models.ForeignKey(School, on_delete=models.SET_NULL, null=True)
|
||||||
sponsors = models.CharField(max_length=256)
|
sponsors = models.CharField(max_length=256)
|
||||||
from_book = models.ForeignKey(LegislationBook, on_delete=models.CASCADE)
|
from_book = models.ForeignKey(LegislationBook, on_delete=models.CASCADE)
|
||||||
legislation_title = models.CharField(max_length=512)
|
legislation_title = models.CharField(max_length=512)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
<p><i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i></p>
|
<p><i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i></p>
|
||||||
|
|
||||||
<p>Sponsored by {{ legislation.sponsors }} of {{ legislation.school }}</p>
|
<p>Sponsored by {{ legislation.sponsors }} of <a href="/explorer/schools/{{ legislation.school.id}}">{{ legislation.school }}</a></p>
|
||||||
|
|
||||||
<p>Presented as part of the <a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a> conference</p>
|
<p>Presented as part of the <a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a> conference</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends "explorer/base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/tn.css" />
|
||||||
|
<div class="boxed">
|
||||||
|
<h1>All bills by {{ school_name }}</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for text in legislation %}
|
||||||
|
<li><a href="/explorer/legislation/{{ text.id }}">{{ text.legislation_title }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
|
@ -9,5 +9,6 @@ urlpatterns = [
|
||||||
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"),
|
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"),
|
||||||
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
||||||
path("topics/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
|
path("topics/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
|
||||||
path("topics/", views.get_all_classifications, name="classificationview"),
|
path("topics/", views.get_all_classifications, name="classificationsview"),
|
||||||
|
path("schools/<int:school_id>/", views.get_all_by_school, name="schoolview"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from .models import LegislativeText, LegislationBook, LegislationClassification
|
from .models import LegislativeText, LegislationBook, LegislationClassification, School
|
||||||
|
|
||||||
from random import sample
|
from random import sample
|
||||||
|
|
||||||
|
@ -80,3 +80,12 @@ def get_all_classified_by_id(request, classification_id):
|
||||||
"legislation": matches,
|
"legislation": matches,
|
||||||
"result_name": "All legislation in topic {}".format(classification.name)
|
"result_name": "All legislation in topic {}".format(classification.name)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def get_all_by_school(request, school_id):
|
||||||
|
school = get_object_or_404(School, pk=school_id)
|
||||||
|
|
||||||
|
return render(request, "explorer/school.html", {
|
||||||
|
"school_name": school.name,
|
||||||
|
"legislation": school.legislativetext_set.all()
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue