Compare commits
No commits in common. "281473262a85b0fe6b49c063850f104d42b87fe5" and "37e6a03bb39fcd519fff91c1e57fbddce3be50af" have entirely different histories.
281473262a
...
37e6a03bb3
|
@ -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
|
||||||
|
@ -27,10 +26,6 @@ class School(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
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):
|
class Country(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
|
|
||||||
|
@ -40,10 +35,6 @@ class Country(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return 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:
|
class Meta:
|
||||||
verbose_name = "Book"
|
verbose_name = "Book"
|
||||||
|
@ -168,8 +159,8 @@ class LegislativeText(models.Model):
|
||||||
|
|
||||||
class LegislationClassification(models.Model):
|
class LegislationClassification(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Topic"
|
verbose_name = "Classification"
|
||||||
verbose_name_plural = "Topics"
|
verbose_name_plural = "Classifications"
|
||||||
|
|
||||||
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(
|
||||||
|
@ -179,7 +170,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})
|
|
|
@ -18,7 +18,7 @@
|
||||||
</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>
|
||||||
|
|
|
@ -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>
|
|
||||||
<li><a href="/explorer/countries/">By country</a></li>
|
|
||||||
<li><a href="/explorer/schools/">By school</a></li>
|
|
||||||
<li><a href="/explorer/topics/">By topic</a></li>
|
|
||||||
</ul>
|
|
||||||
</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>{{ result_name }}</h1>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
{% for instance in instances %}
|
|
||||||
<li><a href="{{ instance.get_absolute_url }}">{{ instance.name }}</a></li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{% endblock content %}
|
|
|
@ -8,13 +8,8 @@ urlpatterns = [
|
||||||
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("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
||||||
path("topics/<int:model_id>/", views.get_all_classified_by_id, name="LegislationClassification.detail"),
|
path("topics/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
|
||||||
path("topics/", views.get_all_classifications, name="LegislationClassification"),
|
path("topics/", views.get_all_classifications, name="classificationsview"),
|
||||||
|
path("schools/<int:school_id>/", views.get_all_by_school, name="schoolview"),
|
||||||
# these are named weirdly -- see models.py School and Country definitions
|
path("countries/<int:country_id>/", views.get_all_by_country, name="countryview"),
|
||||||
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("schools/", views.get_all_schools, name="School"),
|
|
||||||
path("countries/", views.get_all_countries, name="Country"),
|
|
||||||
path("groups/", views.return_groups, name="Groups")
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -54,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()
|
||||||
|
@ -75,40 +81,18 @@ def get_all_classified_by_id(request, model_id):
|
||||||
"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 get_all_by_school(request, school_id):
|
||||||
def wrapped(request, model_id):
|
school = get_object_or_404(School, pk=school_id)
|
||||||
instance = get_object_or_404(model, pk=model_id)
|
|
||||||
return render(request, "explorer/results.html", {
|
return render(request, "explorer/results.html", {
|
||||||
"result_name": "All legislation by {}".format(instance.name),
|
"result_name": "All legislation by {}".format(school.name),
|
||||||
"legislation": instance.legislativetext_set.all()
|
"legislation": school.legislativetext_set.all()
|
||||||
})
|
})
|
||||||
|
|
||||||
return wrapped
|
def get_all_by_country(request, country_id):
|
||||||
|
country = get_object_or_404(Country, pk=country_id)
|
||||||
|
|
||||||
def get_all_xs(model):
|
return render(request, "explorer/results.html", {
|
||||||
def wrapper(request):
|
"result_name": "All legislation by country {}".format(country.name),
|
||||||
instances = model.objects.all()
|
"legislation": country.legislativetext_set.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):
|
|
||||||
return render(request, "explorer/by_group.html", {})
|
|
||||||
|
|
||||||
get_all_by_school = get_all_by_x(School)
|
|
||||||
get_all_by_country = get_all_by_x(Country)
|
|
||||||
|
|
||||||
get_all_schools = get_all_xs(School)
|
|
||||||
get_all_countries = get_all_xs(Country)
|
|
||||||
get_all_classifications = get_all_xs(LegislationClassification)
|
|
Loading…
Reference in New Issue