Compare commits
3 Commits
main
...
pending_do
Author | SHA1 | Date |
---|---|---|
stupidcomputer | 61ba7f6a55 | |
stupidcomputer | dee8d67161 | |
stupidcomputer | 2c31e7f3a5 |
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
prod: # execute this target on the production server in the nix-shell
|
||||
cd franklincce; yes yes | python3 manage.py collectstatic
|
||||
cd franklincce; python3 manage.py collectstatic
|
||||
sh gen_kb.sh
|
||||
sed "s|change_me|$(shell dd if=/dev/urandom bs=1024 count=1|base64)|g" .env.prod.orig > .env.prod
|
||||
docker-compose -f docker-compose.prod.yml up -d --build
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,15 +0,0 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
{
|
||||
# nix expressions to configure the relevant things
|
||||
# manual nix-shell -c "make clean && make" (etc) is still needed, sadly
|
||||
|
||||
virtualisation.docker.enable = true;
|
||||
|
||||
services.nginx.virtualHosts."franklincce.beepboop.systems" = {
|
||||
forceSSL = true;
|
||||
enableACME = true;
|
||||
locations."/" = {
|
||||
proxyPass = "http://localhost:1337";
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
python3 manage.py makemigrations
|
||||
python3 manage.py migrate --run-syncdb
|
||||
python3 manage.py migrate
|
||||
|
||||
exec "$@"
|
||||
|
|
|
@ -11,11 +11,7 @@ class LegislationBookAdmin(admin.ModelAdmin):
|
|||
to_register = [
|
||||
[models.LegislativeText, LegislativeTextAdmin],
|
||||
[models.LegislationBook, LegislationBookAdmin],
|
||||
[models.LegislationClassification],
|
||||
[models.School],
|
||||
[models.Country],
|
||||
[models.Sponsor],
|
||||
[models.Category],
|
||||
[models.LegislationClassification]
|
||||
]
|
||||
for i in to_register:
|
||||
admin.site.register(*i)
|
|
@ -163,63 +163,45 @@ class CCEParserBase():
|
|||
for legislative_text in splitted:
|
||||
# there are some blocks that contain just one value
|
||||
# and are aligned to some x value on the pdf
|
||||
|
||||
# it's an easy way to extract stuff
|
||||
|
||||
try:
|
||||
country = get_block_by_x_value(legislative_text, 139).text.rstrip()
|
||||
country = country.replace("Sponsor: ", "").lstrip()
|
||||
except AttributeError:
|
||||
country = None # this is a yig bill
|
||||
|
||||
try:
|
||||
category = get_block_by_x_value(legislative_text, 151).text.rstrip().lstrip()
|
||||
except AttributeError:
|
||||
try:
|
||||
category = get_block_by_x_value(legislative_text, 153).text.rstrip().lstrip()
|
||||
except AttributeError:
|
||||
print([(i.text, i.x0) for i in legislative_text])
|
||||
|
||||
leg_code = get_block_by_x_value(legislative_text, 88).text.rstrip()
|
||||
|
||||
try:
|
||||
school = get_block_by_x_value(legislative_text, 177).text.rstrip().lstrip()
|
||||
school = get_block_by_x_value(legislative_text, 177).text.rstrip()
|
||||
except AttributeError:
|
||||
try:
|
||||
school = get_block_by_x_value(legislative_text, 186).text.rstrip().lstrip()
|
||||
school = get_block_by_x_value(legislative_text, 186).text.rstrip()
|
||||
except AttributeError:
|
||||
school = "you tell me, man"
|
||||
|
||||
try:
|
||||
sponsors = get_block_by_x_value(legislative_text, 163).text.rstrip().lstrip()
|
||||
sponsors = get_block_by_x_value(legislative_text, 163).text.rstrip()
|
||||
except AttributeError:
|
||||
try:
|
||||
sponsors = get_block_by_x_value(legislative_text, 166).text.rstrip().lstrip()
|
||||
sponsors = get_block_by_x_value(legislative_text, 166).text.rstrip()
|
||||
except AttributeError:
|
||||
sponsors = "you tell me, man"
|
||||
|
||||
try:
|
||||
subcommittee = get_block_by_x_value(legislative_text, 151).text.rstrip()
|
||||
except AttributeError:
|
||||
try:
|
||||
subcommittee = get_block_by_x_value(legislative_text, 153).text.rstrip()
|
||||
except AttributeError:
|
||||
subcommittee = "you tell me, man"
|
||||
the_rest = ''.join([i.text for i in legislative_text[12:]])
|
||||
print([i.text for i in legislative_text[12:]])
|
||||
handled = self.handle_the_rest(the_rest)
|
||||
title = handled["title"]
|
||||
bill_text = handled["bill_text"]
|
||||
|
||||
codesplit = leg_code.split('/')
|
||||
assembly = codesplit[0]
|
||||
dashsplit = codesplit[1].split('-')
|
||||
year = 2000 + int(dashsplit[0])
|
||||
committee = int(dashsplit[1])
|
||||
docket_order = int(dashsplit[2])
|
||||
|
||||
output.append({
|
||||
"assembly": assembly,
|
||||
"year": year,
|
||||
"committee": committee,
|
||||
"docket_order": docket_order,
|
||||
"category": category,
|
||||
"country": country,
|
||||
"code": leg_code,
|
||||
"school": school,
|
||||
"sponsors": sponsors,
|
||||
"legislation_title": title,
|
||||
"text": bill_text
|
||||
"subcommittee": subcommittee,
|
||||
"title": title,
|
||||
"bill_text": bill_text
|
||||
})
|
||||
|
||||
self.output = output
|
||||
|
@ -273,33 +255,22 @@ class HSYIG24(CCEParserBase):
|
|||
|
||||
# it's an easy way to extract stuff
|
||||
legislative_text = remove_block_by_x_value(legislative_text, 565) # remove page numbers
|
||||
category = get_block_by_x_value(legislative_text, 139).text.rstrip().lstrip()
|
||||
leg_code = get_block_by_x_value(legislative_text, 88).text.rstrip()
|
||||
school = get_block_by_x_value(legislative_text, 163).text.rstrip().lstrip()
|
||||
sponsors = get_block_by_x_value(legislative_text, 152).text.rstrip().lstrip()
|
||||
school = get_block_by_x_value(legislative_text, 163).text.rstrip()
|
||||
sponsors = get_block_by_x_value(legislative_text, 152).text.rstrip()
|
||||
subcommittee = get_block_by_x_value(legislative_text, 139).text.rstrip()
|
||||
the_rest = ''.join([i.text for i in legislative_text[6:]])
|
||||
handled = self.handle_the_rest(the_rest)
|
||||
title = handled["title"]
|
||||
bill_text = handled["bill_text"]
|
||||
|
||||
codesplit = leg_code.split('/')
|
||||
assembly = codesplit[0]
|
||||
dashsplit = codesplit[1].split('-')
|
||||
year = 2000 + int(dashsplit[0])
|
||||
committee = int(dashsplit[1])
|
||||
docket_order = int(dashsplit[2])
|
||||
|
||||
output.append({
|
||||
"assembly": assembly,
|
||||
"year": year,
|
||||
"committee": committee,
|
||||
"docket_order": docket_order,
|
||||
"category": category,
|
||||
"country": None, # this is a yig bill
|
||||
"code": leg_code,
|
||||
"school": school,
|
||||
"sponsors": sponsors,
|
||||
"legislation_title": title,
|
||||
"text": bill_text
|
||||
"subcommittee": subcommittee,
|
||||
"title": title,
|
||||
"bill_text": bill_text
|
||||
})
|
||||
|
||||
self.output = output
|
||||
|
@ -316,9 +287,8 @@ def main():
|
|||
return
|
||||
|
||||
for text in doc.output:
|
||||
print("{} {} {} ---------------------------- {}".format(
|
||||
text["country"], text["category"],
|
||||
text["legislation_title"], text["text"]
|
||||
print("{} ---------------------------- {}".format(
|
||||
text["title"], text["bill_text"]
|
||||
))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.14 on 2024-07-24 06:38
|
||||
# Generated by Django 4.2.12 on 2024-06-19 06:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -12,16 +12,6 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Country',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=256)),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'Countries',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='LegislationBook',
|
||||
fields=[
|
||||
|
@ -29,38 +19,7 @@ class Migration(migrations.Migration):
|
|||
('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(choices=[('HSYIGBookParser', 'High School YIG Book Parser 1'), ('HSMUNBookParser', 'High School MUN Book Parser 1')], default='HSYIGBookParser', max_length=128)),
|
||||
('has_performed_export', models.BooleanField(default=False)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Book',
|
||||
'verbose_name_plural': 'Books',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='LegislationClassification',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(help_text='Name of this classification.', max_length=256)),
|
||||
('text_to_match', models.CharField(help_text='a comma seperated list of keywords to include in the classification. spaces and dashes are discluded.', max_length=256)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Topic',
|
||||
'verbose_name_plural': 'Topics',
|
||||
},
|
||||
),
|
||||
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.CreateModel(
|
||||
name='Sponsor',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=256)),
|
||||
('import_strategy', models.CharField(max_length=128)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
|
@ -71,17 +30,10 @@ class Migration(migrations.Migration):
|
|||
('text', models.TextField()),
|
||||
('year', models.IntegerField()),
|
||||
('committee', models.IntegerField()),
|
||||
('category', models.CharField(max_length=256)),
|
||||
('docket_order', models.IntegerField()),
|
||||
('legislation_title', models.CharField(max_length=512)),
|
||||
('country', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='explorer.country')),
|
||||
('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')),
|
||||
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='explorer.school')),
|
||||
('sponsors', models.ManyToManyField(blank=True, to='explorer.sponsor')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Legislation',
|
||||
'verbose_name_plural': 'Legislation',
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
# Generated by Django 4.2.14 on 2024-07-24 17:58
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('explorer', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Category',
|
||||
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='category',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='explorer.category'),
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 4.2.12 on 2024-06-19 17:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('explorer', '0002_legislativetext_legislation_title'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='legislationbook',
|
||||
name='has_performed_export',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='legislationbook',
|
||||
name='import_strategy',
|
||||
field=models.CharField(choices=[('HSYIGBookParser', 'High School YIG Book Parser 1'), ('HSMUNBookParser', 'High School MUN Book Parser 1')], default='HSYIGBookParser', max_length=128),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 4.2.12 on 2024-06-28 20:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('explorer', '0003_legislationbook_has_performed_export_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='LegislationClassification',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(help_text='Name of this classification.', max_length=256)),
|
||||
('text_to_match', models.CharField(help_text='a comma seperated list of keywords to include in the classification. spaces and dashes are discluded.', max_length=256)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.2.12 on 2024-06-28 21:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('explorer', '0004_legislationclassification'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='legislationclassification',
|
||||
name='obvious_change',
|
||||
field=models.CharField(default='test', help_text='Name of this classification.', max_length=256),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 4.2.12 on 2024-06-28 21:08
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('explorer', '0005_legislationclassification_obvious_change'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='legislationclassification',
|
||||
name='obvious_change',
|
||||
),
|
||||
]
|
|
@ -1,6 +1,5 @@
|
|||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.urls import reverse
|
||||
|
||||
from .leglib import HSYIG24, HSMUN23
|
||||
import io
|
||||
|
@ -8,70 +7,7 @@ import fitz
|
|||
|
||||
from collections import namedtuple
|
||||
|
||||
def InstantiateIfNone(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
|
||||
|
||||
def get_absolute_url(self):
|
||||
our_name = __class__.__name__
|
||||
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
|
||||
|
||||
class Country(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Countries"
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
our_name = __class__.__name__
|
||||
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
|
||||
|
||||
class Sponsor(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
our_name = __class__.__name__
|
||||
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField(max_length=256)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Categories"
|
||||
|
||||
def __str__(self):
|
||||
return "{}".format(self.name)
|
||||
|
||||
def get_absolute_url(self):
|
||||
our_name = __class__.__name__
|
||||
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
|
||||
|
||||
class LegislationBook(models.Model):
|
||||
class Meta:
|
||||
verbose_name = "Book"
|
||||
verbose_name_plural = "Books"
|
||||
|
||||
class ConferenceType(models.TextChoices):
|
||||
MIDDLE = "M", _("Middle School")
|
||||
HIGH = "H", _("High School")
|
||||
|
@ -111,40 +47,30 @@ class LegislationBook(models.Model):
|
|||
return
|
||||
|
||||
for text in parsed.output:
|
||||
text["school"] = InstantiateIfNone(School, text["school"])
|
||||
if text["country"]:
|
||||
# there's sometimes "Dominican Republic" and "Dominican Republic 2"
|
||||
# handle that gracefully
|
||||
text["country"] = text["country"].replace(" 2", "")
|
||||
text["country"] = InstantiateIfNone(Country, text["country"])
|
||||
|
||||
if not text["category"] or text["category"] == "Select One--":
|
||||
text["category"] = "No category"
|
||||
text["category"] = InstantiateIfNone(Category, text["category"])
|
||||
|
||||
sponsors = text["sponsors"].split(', ')
|
||||
sponsors = [InstantiateIfNone(Sponsor, sponsor) for sponsor in sponsors]
|
||||
|
||||
del text["sponsors"]
|
||||
|
||||
text = LegislativeText(**text, from_book=self)
|
||||
print(text["code"])
|
||||
codesplit = text["code"].split('/')
|
||||
assembly = codesplit[0]
|
||||
dashsplit = codesplit[1].split('-')
|
||||
year = 2000 + int(dashsplit[0])
|
||||
committee = int(dashsplit[1])
|
||||
docket_order = int(dashsplit[2])
|
||||
text = LegislativeText(
|
||||
assembly=assembly,
|
||||
year=year,
|
||||
committee=committee,
|
||||
docket_order=docket_order,
|
||||
school=text["school"],
|
||||
sponsors=text["sponsors"],
|
||||
legislation_title=text["title"],
|
||||
text=text["bill_text"],
|
||||
from_book=self
|
||||
)
|
||||
text.save()
|
||||
|
||||
for sponsor in sponsors:
|
||||
text.sponsors.add(sponsor)
|
||||
|
||||
def __str__(self):
|
||||
return "{}".format(self.name)
|
||||
|
||||
def get_absolute_url(self):
|
||||
our_name = __class__.__name__
|
||||
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
|
||||
|
||||
class LegislativeText(models.Model):
|
||||
class Meta:
|
||||
verbose_name = "Legislation"
|
||||
verbose_name_plural = "Legislation"
|
||||
|
||||
class Assemblies(models.TextChoices):
|
||||
RGA = "RGA", _("Red General Assembly")
|
||||
BGA = "BGA", _("Blue General Assembly")
|
||||
|
@ -167,13 +93,16 @@ class LegislativeText(models.Model):
|
|||
text = models.TextField()
|
||||
year = models.IntegerField()
|
||||
committee = models.IntegerField()
|
||||
category = models.ForeignKey(Category, on_delete=models.CASCADE)
|
||||
docket_order = models.IntegerField()
|
||||
school = models.ForeignKey(School, on_delete=models.CASCADE)
|
||||
sponsors = models.ManyToManyField(Sponsor, blank=True)
|
||||
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)
|
||||
country = models.ForeignKey(Country, on_delete=models.CASCADE, null=True)
|
||||
country = models.CharField(
|
||||
max_length=512,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return "{}/{}-{}-{}".format(
|
||||
|
@ -207,10 +136,6 @@ class LegislativeText(models.Model):
|
|||
return False
|
||||
|
||||
class LegislationClassification(models.Model):
|
||||
class Meta:
|
||||
verbose_name = "Topic"
|
||||
verbose_name_plural = "Topics"
|
||||
|
||||
name = models.CharField(max_length=256, help_text="Name of this classification.")
|
||||
text_to_match = models.CharField(
|
||||
max_length=256,
|
||||
|
@ -219,16 +144,3 @@ class LegislationClassification(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return "{}".format(self.name)
|
||||
|
||||
def get_absolute_url(self):
|
||||
our_name = __class__.__name__
|
||||
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
|
||||
|
||||
models_in_index = [
|
||||
LegislationClassification,
|
||||
School,
|
||||
Country,
|
||||
Sponsor,
|
||||
Category,
|
||||
LegislationBook
|
||||
]
|
|
@ -14,11 +14,11 @@
|
|||
<nav id="navbar" class="boxed">
|
||||
<div id="leftnav">
|
||||
<a href="/explorer">explorer</a>
|
||||
<a href="/knowledge">knowledge</a>
|
||||
<a href="/kb">knowledge</a>
|
||||
</div>
|
||||
<div id="rightnav">
|
||||
<a href="/explorer/all">all</a>
|
||||
<a href="/explorer/groups">by group</a>
|
||||
<a href="/explorer/topics">by topic</a>
|
||||
<a href="/explorer/search">search</a>
|
||||
<a href="/explorer/stats">stats</a>
|
||||
</div>
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
{% extends "explorer/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/tn.css" />
|
||||
|
||||
<div class="boxed">
|
||||
<h1>View legislation</h1>
|
||||
|
||||
<ul>
|
||||
{% for name, url in listing.items %}
|
||||
<li><a href="{{ url }}">By {{ name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -1,38 +0,0 @@
|
|||
{% comment %}
|
||||
This is a component -- I'm only using this because:
|
||||
1. I'm too lazy to install django-components, and
|
||||
2. This is the only time a component is necessary, so it doesn't make
|
||||
any sense to take on an extra dependancy.
|
||||
{% endcomment %}
|
||||
<div class="legcomponent">
|
||||
<a href="/explorer/legislation/{{ legislation.id }}"><h2 class="legtitle">{{ legislation.legislation_title }}</h2></a>
|
||||
|
||||
<div class="legmetadata">
|
||||
<p>
|
||||
<i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i>
|
||||
|
||||
·
|
||||
|
||||
{% for sponsor in legislation.sponsors.all %}
|
||||
<a href="/explorer/sponsors/{{ sponsor.id }}">{{ sponsor.name }}</a>{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
|
||||
·
|
||||
|
||||
<a href="/explorer/schools/{{ legislation.school.id }}">{{ legislation.school }}</a>
|
||||
|
||||
·
|
||||
|
||||
{% if legislation.country %}
|
||||
<a href="/explorer/countries/{{ legislation.country.id }}">{{ legislation.country }}</a>
|
||||
|
||||
·
|
||||
{% endif %}
|
||||
<a href="/explorer/categories/{{ legislation.category.id }}">{{ legislation.category }}</a>
|
||||
|
||||
·
|
||||
|
||||
<a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
|
@ -9,16 +9,14 @@
|
|||
|
||||
<h2>Some randomly selected legislation</h2>
|
||||
|
||||
{% if legislation %}
|
||||
{% autoescape off %}
|
||||
{% if legislative_texts %}
|
||||
<ul>
|
||||
{% for text in legislation %}
|
||||
{{ text }}
|
||||
{% for text in legislative_texts %}
|
||||
<li><a href="{% url 'viewleg' text.id %}">{{ text.legislation_title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endautoescape %}
|
||||
{% else %}
|
||||
<p>No texts available. If you're the admin, you need to add some texts with the admin interface.</p>
|
||||
<p>No texts available</p>
|
||||
{% endif %}
|
||||
|
||||
<h2>About this instance</h2>
|
||||
|
|
|
@ -13,18 +13,7 @@
|
|||
|
||||
<p><i>{{ legislation.assembly }}/{{ legislation.committee }}/{{ legislation.docket_order }}</i></p>
|
||||
|
||||
<p>Sponsored by
|
||||
{% for sponsor in legislation.sponsors.all %}
|
||||
<a href="/explorer/sponsors/{{ sponsor.id }}">{{ sponsor.name }}</a>{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
|
||||
of <a href="/explorer/schools/{{ legislation.school.id }}">{{ legislation.school }}</a></p>
|
||||
|
||||
{% if legislation.country %}
|
||||
<p>The delegates above represented the <a href="/explorer/countries/{{ legislation.country.id }}">Delegation of {{ legislation.country }}</a>.</p>
|
||||
{% endif %}
|
||||
|
||||
<p>This legislation was filed in the <a href="/explorer/categories/{{ legislation.category.id }}">{{ legislation.category }}</a> category</p>
|
||||
<p>Sponsored by {{ legislation.sponsors }} of {{ legislation.school }}</p>
|
||||
|
||||
<p>Presented as part of the <a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a> conference</p>
|
||||
</div>
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
{% extends "explorer/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/tn.css" />
|
||||
|
||||
<div class="boxed">
|
||||
<h1>{{ result_name }}</h1>
|
||||
|
||||
<ul>
|
||||
{% for instance in instances %}
|
||||
<li><a href="{{ instance.get_absolute_url }}">{{ instance.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -6,12 +6,10 @@
|
|||
<div class="boxed">
|
||||
<h1>{{ result_name }}</h1>
|
||||
|
||||
{% autoescape off %}
|
||||
<ul>
|
||||
{% for text in legislation %}
|
||||
{{ text }}
|
||||
<li><a href="/explorer/legislation/{{ text.id }}">{{ text.legislation_title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
{% extends "explorer/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/tn.css" />
|
||||
<div class="boxed">
|
||||
<h1>Search legislation by keyword</h1>
|
||||
<form action="/explorer/search" method="get">
|
||||
<input type="text" id="search_term" name="search_term" />
|
||||
<button type="submit">Execute search</button>
|
||||
<p>
|
||||
You can use this page to search through legislation by keyword. The search is case sensitive, so be careful when pressing your shift key.
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -5,7 +5,7 @@
|
|||
<div class="boxed">
|
||||
<h1>Explorer statistics</h1>
|
||||
|
||||
<p>Total pieces of legislation: {{ all }}</p>
|
||||
<p>Total bills: {{ all }}</p>
|
||||
|
||||
<p>Red Senate Bills: {{ red_senate }}</p>
|
||||
|
||||
|
@ -19,10 +19,10 @@
|
|||
|
||||
<p>Blue House Bills: {{ blue_house }}</p>
|
||||
|
||||
<p>Red General Assembly Resolutions: {{ red_ga }}</p>
|
||||
<p>Red General Assembly Bills: {{ red_ga }}</p>
|
||||
|
||||
<p>White General Assembly Resolutions: {{ white_ga }}</p>
|
||||
<p>White General Assembly Bills: {{ white_ga }}</p>
|
||||
|
||||
<p>Blue General Assembly Resolutions: {{ blue_ga }}</p>
|
||||
<p>Blue General Assembly Bills: {{ blue_ga }}</p>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -7,20 +7,7 @@ urlpatterns = [
|
|||
path("all/", views.all, name="all"),
|
||||
path("stats/", views.stats, name="stats"),
|
||||
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"),
|
||||
path("topics/<int:model_id>/", views.get_all_classified_by_id, name="LegislationClassification.detail"),
|
||||
path("topics/", views.get_all_classifications, name="LegislationClassification"),
|
||||
path("search/", views.handle_search, name="search_legislation"),
|
||||
|
||||
# these are named weirdly -- see models.py School and Country definitions
|
||||
path("schools/<int:model_id>/", views.get_all_by_school, name="School.detail"),
|
||||
path("countries/<int:model_id>/", views.get_all_by_country, name="Country.detail"),
|
||||
path("sponsors/<int:model_id>/", views.get_all_by_sponsor, name="Sponsor.detail"),
|
||||
path("categories/<int:model_id>/", views.get_all_by_category, name="Category.detail"),
|
||||
path("conference/<int:model_id>/", views.get_all_by_conference, name="LegislationBook.detail"),
|
||||
path("schools/", views.get_all_schools, name="School"),
|
||||
path("countries/", views.get_all_countries, name="Country"),
|
||||
path("groups/", views.return_groups, name="Groups"),
|
||||
path("sponsors/", views.get_all_sponsors, name="Sponsor"),
|
||||
path("categories/", views.get_all_categories, name="Category"),
|
||||
path("conference/", views.get_all_conferences, name="LegislationBook"),
|
||||
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/", views.get_all_classifications, name="classificationview"),
|
||||
]
|
||||
|
|
|
@ -1,40 +1,15 @@
|
|||
from django.shortcuts import get_object_or_404, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponse
|
||||
|
||||
from .models import (
|
||||
LegislativeText,
|
||||
LegislationBook,
|
||||
LegislationClassification,
|
||||
School,
|
||||
Country,
|
||||
Sponsor,
|
||||
Category,
|
||||
models_in_index,
|
||||
)
|
||||
from .models import LegislativeText, LegislationBook, LegislationClassification
|
||||
|
||||
from random import sample
|
||||
|
||||
def legislation_to_html(legislation):
|
||||
return render_to_string("explorer/comp_legislation.html", {
|
||||
"legislation": legislation,
|
||||
})
|
||||
|
||||
def index(request):
|
||||
legislative_texts = list(LegislativeText.objects.all())
|
||||
try:
|
||||
legislative_texts = sample(legislative_texts, 5)
|
||||
except ValueError:
|
||||
# there's not enough texts, so just return nothing
|
||||
legislative_texts = []
|
||||
|
||||
legislative_texts = [
|
||||
legislation_to_html(text) for text in legislative_texts
|
||||
]
|
||||
|
||||
legislative_texts = sample(legislative_texts, 5)
|
||||
context = {
|
||||
"legislation": legislative_texts,
|
||||
"legislative_texts": legislative_texts,
|
||||
}
|
||||
return render(request, "explorer/index.html", context)
|
||||
|
||||
|
@ -79,8 +54,14 @@ def stats(request):
|
|||
}
|
||||
return render(request, "explorer/stats.html", context)
|
||||
|
||||
def get_all_classified_by_id(request, model_id):
|
||||
classification = get_object_or_404(LegislationClassification, pk=model_id)
|
||||
def get_all_classifications(request):
|
||||
classifications = LegislationClassification.objects.all()
|
||||
return render(request, "explorer/classifications.html", {
|
||||
"classifications": classifications,
|
||||
})
|
||||
|
||||
def get_all_classified_by_id(request, classification_id):
|
||||
classification = get_object_or_404(LegislationClassification, pk=classification_id)
|
||||
# this is very expensive; make a way for this to be cached please?
|
||||
|
||||
all_texts = LegislativeText.objects.all()
|
||||
|
@ -99,86 +80,3 @@ def get_all_classified_by_id(request, model_id):
|
|||
"legislation": matches,
|
||||
"result_name": "All legislation in topic {}".format(classification.name)
|
||||
})
|
||||
|
||||
def get_all_by_x(model):
|
||||
def wrapped(request, model_id):
|
||||
instance = get_object_or_404(model, pk=model_id)
|
||||
legislation = instance.legislativetext_set.all()
|
||||
legislation = [legislation_to_html(i) for i in legislation]
|
||||
return render(request, "explorer/results.html", {
|
||||
"result_name": "All legislation by {}".format(instance.name),
|
||||
"legislation": legislation
|
||||
})
|
||||
|
||||
return wrapped
|
||||
|
||||
def get_all_xs(model):
|
||||
def wrapper(request):
|
||||
instances = model.objects.all()
|
||||
try:
|
||||
# what the heck, django?????
|
||||
plural = model._meta.verbose_name_plural
|
||||
except:
|
||||
plural = model.__name__ + "s"
|
||||
|
||||
plural = plural.lower()
|
||||
|
||||
return render(request, "explorer/listing.html", {
|
||||
"result_name": "All {}".format(plural),
|
||||
"instances": instances,
|
||||
})
|
||||
|
||||
return wrapper
|
||||
|
||||
def return_groups(request):
|
||||
listing = {}
|
||||
for model in models_in_index:
|
||||
try:
|
||||
name = model._meta.verbose_name.lower()
|
||||
except:
|
||||
name = model.__name__.lower()
|
||||
|
||||
listing[name] = reverse(model.__name__)
|
||||
|
||||
print(listing)
|
||||
return render(request, "explorer/by_group.html", { "listing": listing })
|
||||
|
||||
def handle_search(request):
|
||||
try:
|
||||
query = request.GET['search_term']
|
||||
except KeyError:
|
||||
return render(request, "explorer/search.html", {})
|
||||
|
||||
f = LegislativeText.objects.filter
|
||||
|
||||
text_results = f(text__icontains=query)
|
||||
title_results = f(legislation_title__icontains=query)
|
||||
school_results = f(school__name__icontains=query)
|
||||
sponsor_results = f(sponsors__name__icontains=query)
|
||||
country_results = f(country__name__icontains=query)
|
||||
|
||||
results = text_results.union(
|
||||
title_results,
|
||||
school_results,
|
||||
sponsor_results,
|
||||
country_results
|
||||
)
|
||||
results = [legislation_to_html(i) for i in results]
|
||||
|
||||
return render(request, "explorer/results.html", {
|
||||
"result_name": "Results for search term '{}'".format(query),
|
||||
"legislation": results
|
||||
})
|
||||
|
||||
get_all_by_school = get_all_by_x(School)
|
||||
get_all_by_country = get_all_by_x(Country)
|
||||
get_all_by_sponsor = get_all_by_x(Sponsor)
|
||||
get_all_by_category = get_all_by_x(Category)
|
||||
get_all_by_conference = get_all_by_x(LegislationBook)
|
||||
|
||||
get_all_schools = get_all_xs(School)
|
||||
get_all_countries = get_all_xs(Country)
|
||||
get_all_sponsors = get_all_xs(Sponsor)
|
||||
get_all_categories = get_all_xs(Category)
|
||||
get_all_classifications = get_all_xs(LegislationClassification)
|
||||
get_all_conferences = get_all_xs(LegislationBook)
|
|
@ -2,12 +2,9 @@ files=$(find kb -type f | awk -F'/' '{print $NF}')
|
|||
IFS='
|
||||
'
|
||||
mkdir -p franklincce/staticfiles/kb
|
||||
mkdir -p franklincce/staticfiles/root
|
||||
|
||||
for file in $files; do
|
||||
without_extension=${file%.*}
|
||||
echo $file, $without_extension
|
||||
pandoc -s --template=./template.html -f markdown -t html -o "franklincce/staticfiles/kb/$without_extension.html" "kb/$without_extension.md" --lua-filter=links-to-html.lua
|
||||
done
|
||||
|
||||
cp franklincce/staticfiles/kb/web_root.html franklincce/staticfiles/root/index.html
|
||||
done
|
|
@ -4,7 +4,4 @@ title: "Franklin CCE Knowledgebase"
|
|||
|
||||
## Model UN
|
||||
|
||||
- [Writing a resolution](./writing-resolution.md)
|
||||
|
||||
Want to see more articles in the knowledgebase?
|
||||
[Learn how to contribute](./CONTRIBUTING.md).
|
||||
- [Writing a resolution](./writing-resolution.md)
|
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
title: "Franklin CCE Delegation website"
|
||||
---
|
||||
|
||||
This website contains some materials for the Franklin High School YMCA Center for Civic Engagement delegation.
|
||||
Specifically, a [bill database](/explorer) and a [collection of helpful articles](/knowledge) on various things are available here.
|
|
@ -4,20 +4,8 @@ upstream franklincce {
|
|||
|
||||
server {
|
||||
listen 80;
|
||||
server_name franklincce.beepboop.systems;
|
||||
port_in_redirect off;
|
||||
absolute_redirect off;
|
||||
server_name_in_redirect off;
|
||||
|
||||
location /explorer/ {
|
||||
proxy_pass http://franklincce;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $host;
|
||||
proxy_redirect off;
|
||||
client_max_body_size 100M;
|
||||
}
|
||||
|
||||
location /admin/ {
|
||||
location / {
|
||||
proxy_pass http://franklincce;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $host;
|
||||
|
@ -29,11 +17,7 @@ server {
|
|||
alias /home/app/web/staticfiles/;
|
||||
}
|
||||
|
||||
location /knowledge {
|
||||
location /kb {
|
||||
alias /home/app/web/staticfiles/kb;
|
||||
}
|
||||
|
||||
location / {
|
||||
alias /home/app/web/staticfiles/root/;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<nav id="navbar" class="boxed">
|
||||
<div id="leftnav">
|
||||
<a href="/explorer">explorer</a>
|
||||
<a href="/knowledge">knowledge</a>
|
||||
<a href="/kb">knowledge</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
|
Loading…
Reference in New Issue