feature: refactor bill display into components
This commit is contained in:
parent
d713f4106d
commit
36c558821d
|
@ -0,0 +1,38 @@
|
||||||
|
{% 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 }}"></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>
|
|
@ -6,10 +6,12 @@
|
||||||
<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 %}
|
||||||
<li><a href="/explorer/legislation/{{ text.id }}">{{ text.legislation_title }}</a></li>
|
{{ text }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endautoescape %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
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.urls import reverse
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
@ -34,6 +35,11 @@ def all(request):
|
||||||
}
|
}
|
||||||
return render(request, "explorer/all.html", context)
|
return render(request, "explorer/all.html", context)
|
||||||
|
|
||||||
|
def legislation_to_html(legislation):
|
||||||
|
return render_to_string("explorer/comp_legislation.html", {
|
||||||
|
"legislation": legislation,
|
||||||
|
})
|
||||||
|
|
||||||
def view_legislation(request, legislation_id):
|
def view_legislation(request, legislation_id):
|
||||||
legislation = get_object_or_404(LegislativeText, pk=legislation_id)
|
legislation = get_object_or_404(LegislativeText, pk=legislation_id)
|
||||||
context = {
|
context = {
|
||||||
|
@ -92,9 +98,11 @@ def get_all_classified_by_id(request, model_id):
|
||||||
def get_all_by_x(model):
|
def get_all_by_x(model):
|
||||||
def wrapped(request, model_id):
|
def wrapped(request, model_id):
|
||||||
instance = get_object_or_404(model, pk=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", {
|
return render(request, "explorer/results.html", {
|
||||||
"result_name": "All legislation by {}".format(instance.name),
|
"result_name": "All legislation by {}".format(instance.name),
|
||||||
"legislation": instance.legislativetext_set.all()
|
"legislation": legislation
|
||||||
})
|
})
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
@ -144,15 +152,17 @@ def handle_search(request):
|
||||||
sponsor_results = f(sponsors__name__icontains=query)
|
sponsor_results = f(sponsors__name__icontains=query)
|
||||||
country_results = f(country__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", {
|
return render(request, "explorer/results.html", {
|
||||||
"result_name": "Results for search term '{}'".format(query),
|
"result_name": "Results for search term '{}'".format(query),
|
||||||
"legislation": text_results.union(
|
"legislation": results
|
||||||
title_results,
|
|
||||||
school_results,
|
|
||||||
sponsor_results,
|
|
||||||
country_results
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get_all_by_school = get_all_by_x(School)
|
get_all_by_school = get_all_by_x(School)
|
||||||
|
|
Loading…
Reference in New Issue