Compare commits

..

3 Commits

Author SHA1 Message Date
61ba7f6a55 final doc commit 2024-06-30 00:31:44 -05:00
dee8d67161 change 2 (to squash) 2024-06-29 17:48:49 -05:00
2c31e7f3a5 some part of writing resolutions 2024-06-29 16:53:18 -05:00
31 changed files with 188 additions and 541 deletions

View File

@ -1,5 +1,5 @@
prod: # execute this target on the production server in the nix-shell 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 sh gen_kb.sh
sed "s|change_me|$(shell dd if=/dev/urandom bs=1024 count=1|base64)|g" .env.prod.orig > .env.prod 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 docker-compose -f docker-compose.prod.yml up -d --build

Binary file not shown.

Binary file not shown.

View File

@ -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";
};
};
}

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
python3 manage.py makemigrations python3 manage.py makemigrations
python3 manage.py migrate --run-syncdb python3 manage.py migrate
exec "$@" exec "$@"

View File

@ -11,11 +11,7 @@ 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],
[models.Country],
[models.Sponsor],
[models.Category],
] ]
for i in to_register: for i in to_register:
admin.site.register(*i) admin.site.register(*i)

View File

@ -163,63 +163,45 @@ class CCEParserBase():
for legislative_text in splitted: for legislative_text in splitted:
# there are some blocks that contain just one value # there are some blocks that contain just one value
# and are aligned to some x value on the pdf # and are aligned to some x value on the pdf
# it's an easy way to extract stuff # 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() leg_code = get_block_by_x_value(legislative_text, 88).text.rstrip()
try: 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: except AttributeError:
try: 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: except AttributeError:
school = "you tell me, man" school = "you tell me, man"
try: 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: except AttributeError:
try: 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: except AttributeError:
sponsors = "you tell me, man" 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:]]) 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) handled = self.handle_the_rest(the_rest)
title = handled["title"] title = handled["title"]
bill_text = handled["bill_text"] 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({ output.append({
"assembly": assembly, "code": leg_code,
"year": year,
"committee": committee,
"docket_order": docket_order,
"category": category,
"country": country,
"school": school, "school": school,
"sponsors": sponsors, "sponsors": sponsors,
"legislation_title": title, "subcommittee": subcommittee,
"text": bill_text "title": title,
"bill_text": bill_text
}) })
self.output = output self.output = output
@ -273,33 +255,22 @@ class HSYIG24(CCEParserBase):
# it's an easy way to extract stuff # it's an easy way to extract stuff
legislative_text = remove_block_by_x_value(legislative_text, 565) # remove page numbers 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() leg_code = get_block_by_x_value(legislative_text, 88).text.rstrip()
school = get_block_by_x_value(legislative_text, 163).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().lstrip() 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:]]) the_rest = ''.join([i.text for i in legislative_text[6:]])
handled = self.handle_the_rest(the_rest) handled = self.handle_the_rest(the_rest)
title = handled["title"] title = handled["title"]
bill_text = handled["bill_text"] 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({ output.append({
"assembly": assembly, "code": leg_code,
"year": year,
"committee": committee,
"docket_order": docket_order,
"category": category,
"country": None, # this is a yig bill
"school": school, "school": school,
"sponsors": sponsors, "sponsors": sponsors,
"legislation_title": title, "subcommittee": subcommittee,
"text": bill_text "title": title,
"bill_text": bill_text
}) })
self.output = output self.output = output
@ -316,9 +287,8 @@ def main():
return return
for text in doc.output: for text in doc.output:
print("{} {} {} ---------------------------- {}".format( print("{} ---------------------------- {}".format(
text["country"], text["category"], text["title"], text["bill_text"]
text["legislation_title"], text["text"]
)) ))
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -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 from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
@ -12,16 +12,6 @@ class Migration(migrations.Migration):
] ]
operations = [ 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( migrations.CreateModel(
name='LegislationBook', name='LegislationBook',
fields=[ 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)), ('conference_type', models.CharField(choices=[('M', 'Middle School'), ('H', 'High School')], default='H', max_length=1)),
('pdf', models.FileField(upload_to='uploads/')), ('pdf', models.FileField(upload_to='uploads/')),
('name', models.CharField(max_length=256)), ('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)), ('import_strategy', models.CharField(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)),
], ],
), ),
migrations.CreateModel( migrations.CreateModel(
@ -71,17 +30,10 @@ class Migration(migrations.Migration):
('text', models.TextField()), ('text', models.TextField()),
('year', models.IntegerField()), ('year', models.IntegerField()),
('committee', models.IntegerField()), ('committee', models.IntegerField()),
('category', models.CharField(max_length=256)),
('docket_order', models.IntegerField()), ('docket_order', models.IntegerField()),
('legislation_title', models.CharField(max_length=512)), ('school', models.CharField(max_length=256)),
('country', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='explorer.country')), ('sponsors', models.CharField(max_length=256)),
('from_book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='explorer.legislationbook')), ('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',
},
), ),
] ]

View File

@ -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'),
),
]

View File

@ -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,
),
]

View File

@ -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),
),
]

View File

@ -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)),
],
),
]

View File

@ -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,
),
]

View File

@ -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',
),
]

View File

@ -1,6 +1,5 @@
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.urls import reverse
from .leglib import HSYIG24, HSMUN23 from .leglib import HSYIG24, HSMUN23
import io import io
@ -8,70 +7,7 @@ import fitz
from collections import namedtuple 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 LegislationBook(models.Model):
class Meta:
verbose_name = "Book"
verbose_name_plural = "Books"
class ConferenceType(models.TextChoices): class ConferenceType(models.TextChoices):
MIDDLE = "M", _("Middle School") MIDDLE = "M", _("Middle School")
HIGH = "H", _("High School") HIGH = "H", _("High School")
@ -111,40 +47,30 @@ class LegislationBook(models.Model):
return return
for text in parsed.output: for text in parsed.output:
text["school"] = InstantiateIfNone(School, text["school"]) print(text["code"])
if text["country"]: codesplit = text["code"].split('/')
# there's sometimes "Dominican Republic" and "Dominican Republic 2" assembly = codesplit[0]
# handle that gracefully dashsplit = codesplit[1].split('-')
text["country"] = text["country"].replace(" 2", "") year = 2000 + int(dashsplit[0])
text["country"] = InstantiateIfNone(Country, text["country"]) committee = int(dashsplit[1])
docket_order = int(dashsplit[2])
if not text["category"] or text["category"] == "Select One--": text = LegislativeText(
text["category"] = "No category" assembly=assembly,
text["category"] = InstantiateIfNone(Category, text["category"]) year=year,
committee=committee,
sponsors = text["sponsors"].split(', ') docket_order=docket_order,
sponsors = [InstantiateIfNone(Sponsor, sponsor) for sponsor in sponsors] school=text["school"],
sponsors=text["sponsors"],
del text["sponsors"] legislation_title=text["title"],
text=text["bill_text"],
text = LegislativeText(**text, from_book=self) from_book=self
)
text.save() text.save()
for sponsor in sponsors:
text.sponsors.add(sponsor)
def __str__(self): def __str__(self):
return "{}".format(self.name) 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 LegislativeText(models.Model):
class Meta:
verbose_name = "Legislation"
verbose_name_plural = "Legislation"
class Assemblies(models.TextChoices): class Assemblies(models.TextChoices):
RGA = "RGA", _("Red General Assembly") RGA = "RGA", _("Red General Assembly")
BGA = "BGA", _("Blue General Assembly") BGA = "BGA", _("Blue General Assembly")
@ -167,13 +93,16 @@ class LegislativeText(models.Model):
text = models.TextField() text = models.TextField()
year = models.IntegerField() year = models.IntegerField()
committee = models.IntegerField() committee = models.IntegerField()
category = models.ForeignKey(Category, on_delete=models.CASCADE)
docket_order = models.IntegerField() docket_order = models.IntegerField()
school = models.ForeignKey(School, on_delete=models.CASCADE) school = models.CharField(max_length=256)
sponsors = models.ManyToManyField(Sponsor, blank=True) 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)
country = models.ForeignKey(Country, on_delete=models.CASCADE, null=True) country = models.CharField(
max_length=512,
null=True,
blank=True
)
def __str__(self): def __str__(self):
return "{}/{}-{}-{}".format( return "{}/{}-{}-{}".format(
@ -207,10 +136,6 @@ class LegislativeText(models.Model):
return False return False
class LegislationClassification(models.Model): 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.") name = models.CharField(max_length=256, help_text="Name of this classification.")
text_to_match = models.CharField( text_to_match = models.CharField(
max_length=256, max_length=256,
@ -219,16 +144,3 @@ class LegislationClassification(models.Model):
def __str__(self): def __str__(self):
return "{}".format(self.name) 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
]

View File

@ -14,11 +14,11 @@
<nav id="navbar" class="boxed"> <nav id="navbar" class="boxed">
<div id="leftnav"> <div id="leftnav">
<a href="/explorer">explorer</a> <a href="/explorer">explorer</a>
<a href="/knowledge">knowledge</a> <a href="/kb">knowledge</a>
</div> </div>
<div id="rightnav"> <div id="rightnav">
<a href="/explorer/all">all</a> <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/search">search</a>
<a href="/explorer/stats">stats</a> <a href="/explorer/stats">stats</a>
</div> </div>

View File

@ -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 %}

View File

@ -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>
&middot;
{% for sponsor in legislation.sponsors.all %}
<a href="/explorer/sponsors/{{ sponsor.id }}">{{ sponsor.name }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
&middot;
<a href="/explorer/schools/{{ legislation.school.id }}">{{ legislation.school }}</a>
&middot;
{% if legislation.country %}
<a href="/explorer/countries/{{ legislation.country.id }}">{{ legislation.country }}</a>
&middot;
{% endif %}
<a href="/explorer/categories/{{ legislation.category.id }}">{{ legislation.category }}</a>
&middot;
<a href="/explorer/conference/{{ legislation.from_book.id }}">{{ legislation.from_book.name }}</a>
</p>
</div>
</div>

View File

@ -9,16 +9,14 @@
<h2>Some randomly selected legislation</h2> <h2>Some randomly selected legislation</h2>
{% if legislation %} {% if legislative_texts %}
{% autoescape off %}
<ul> <ul>
{% for text in legislation %} {% for text in legislative_texts %}
{{ text }} <li><a href="{% url 'viewleg' text.id %}">{{ text.legislation_title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endautoescape %}
{% else %} {% 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 %} {% endif %}
<h2>About this instance</h2> <h2>About this instance</h2>

View File

@ -13,18 +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 <p>Sponsored by {{ legislation.sponsors }} of {{ legislation.school }}</p>
{% 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>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>

View File

@ -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 %}

View File

@ -6,12 +6,10 @@
<div class="boxed"> <div class="boxed">
<h1>{{ result_name }}</h1> <h1>{{ result_name }}</h1>
{% autoescape off %}
<ul> <ul>
{% for text in legislation %} {% for text in legislation %}
{{ text }} <li><a href="/explorer/legislation/{{ text.id }}">{{ text.legislation_title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endautoescape %}
</div> </div>
{% endblock content %} {% endblock content %}

View File

@ -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 %}

View File

@ -5,7 +5,7 @@
<div class="boxed"> <div class="boxed">
<h1>Explorer statistics</h1> <h1>Explorer statistics</h1>
<p>Total pieces of legislation: {{ all }}</p> <p>Total bills: {{ all }}</p>
<p>Red Senate Bills: {{ red_senate }}</p> <p>Red Senate Bills: {{ red_senate }}</p>
@ -19,10 +19,10 @@
<p>Blue House Bills: {{ blue_house }}</p> <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> </div>
{% endblock content %} {% endblock content %}

View File

@ -7,20 +7,7 @@ urlpatterns = [
path("all/", views.all, name="all"), path("all/", views.all, name="all"),
path("stats/", views.stats, name="stats"), path("stats/", views.stats, name="stats"),
path("legislation/<int:legislation_id>/", views.view_legislation, name="viewleg"), 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("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
path("topics/", views.get_all_classifications, name="LegislationClassification"), path("topics/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
path("search/", views.handle_search, name="search_legislation"), path("topics/", views.get_all_classifications, name="classificationview"),
# 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"),
] ]

View File

@ -1,40 +1,15 @@
from django.shortcuts import get_object_or_404, render 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 django.http import HttpResponse
from .models import ( from .models import LegislativeText, LegislationBook, LegislationClassification
LegislativeText,
LegislationBook,
LegislationClassification,
School,
Country,
Sponsor,
Category,
models_in_index,
)
from random import sample from random import sample
def legislation_to_html(legislation):
return render_to_string("explorer/comp_legislation.html", {
"legislation": legislation,
})
def index(request): def index(request):
legislative_texts = list(LegislativeText.objects.all()) legislative_texts = list(LegislativeText.objects.all())
try:
legislative_texts = sample(legislative_texts, 5) 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
]
context = { context = {
"legislation": legislative_texts, "legislative_texts": legislative_texts,
} }
return render(request, "explorer/index.html", context) return render(request, "explorer/index.html", context)
@ -79,8 +54,14 @@ def stats(request):
} }
return render(request, "explorer/stats.html", context) return render(request, "explorer/stats.html", context)
def get_all_classified_by_id(request, model_id): def get_all_classifications(request):
classification = get_object_or_404(LegislationClassification, pk=model_id) 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? # this is very expensive; make a way for this to be cached please?
all_texts = LegislativeText.objects.all() all_texts = LegislativeText.objects.all()
@ -99,86 +80,3 @@ def get_all_classified_by_id(request, model_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_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)

View File

@ -2,12 +2,9 @@ files=$(find kb -type f | awk -F'/' '{print $NF}')
IFS=' IFS='
' '
mkdir -p franklincce/staticfiles/kb mkdir -p franklincce/staticfiles/kb
mkdir -p franklincce/staticfiles/root
for file in $files; do for file in $files; do
without_extension=${file%.*} without_extension=${file%.*}
echo $file, $without_extension 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 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 done
cp franklincce/staticfiles/kb/web_root.html franklincce/staticfiles/root/index.html

View File

@ -5,6 +5,3 @@ title: "Franklin CCE Knowledgebase"
## Model UN ## Model UN
- [Writing a resolution](./writing-resolution.md) - [Writing a resolution](./writing-resolution.md)
Want to see more articles in the knowledgebase?
[Learn how to contribute](./CONTRIBUTING.md).

View File

@ -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.

View File

@ -4,20 +4,8 @@ upstream franklincce {
server { server {
listen 80; listen 80;
server_name franklincce.beepboop.systems;
port_in_redirect off;
absolute_redirect off;
server_name_in_redirect off;
location /explorer/ { location / {
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/ {
proxy_pass http://franklincce; proxy_pass http://franklincce;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host; proxy_set_header Host $host;
@ -29,11 +17,7 @@ server {
alias /home/app/web/staticfiles/; alias /home/app/web/staticfiles/;
} }
location /knowledge { location /kb {
alias /home/app/web/staticfiles/kb; alias /home/app/web/staticfiles/kb;
} }
location / {
alias /home/app/web/staticfiles/root/;
}
} }

View File

@ -14,7 +14,7 @@
<nav id="navbar" class="boxed"> <nav id="navbar" class="boxed">
<div id="leftnav"> <div id="leftnav">
<a href="/explorer">explorer</a> <a href="/explorer">explorer</a>
<a href="/knowledge">knowledge</a> <a href="/kb">knowledge</a>
</div> </div>
</nav> </nav>