cleanup: refactor by_group view
This commit is contained in:
parent
2a6e42da9c
commit
c35c96e16b
|
@ -202,3 +202,5 @@ class LegislationClassification(models.Model):
|
|||
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]
|
|
@ -7,10 +7,9 @@
|
|||
<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>
|
||||
<li><a href="/explorer/sponsors/">By sponsor</a></li>
|
||||
{% for name, url in listing.items %}
|
||||
<li><a href="{{ url }}">By {{ name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -18,5 +18,5 @@ urlpatterns = [
|
|||
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="Sponsors")
|
||||
path("sponsors/", views.get_all_sponsors, name="Sponsor")
|
||||
]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.shortcuts import get_object_or_404, render
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponse
|
||||
|
||||
from .models import (
|
||||
|
@ -7,7 +8,8 @@ from .models import (
|
|||
LegislationClassification,
|
||||
School,
|
||||
Country,
|
||||
Sponsor
|
||||
Sponsor,
|
||||
models_in_index,
|
||||
)
|
||||
|
||||
from random import sample
|
||||
|
@ -115,7 +117,17 @@ def get_all_xs(model):
|
|||
return wrapper
|
||||
|
||||
def return_groups(request):
|
||||
return render(request, "explorer/by_group.html", {})
|
||||
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 })
|
||||
|
||||
get_all_by_school = get_all_by_x(School)
|
||||
get_all_by_country = get_all_by_x(Country)
|
||||
|
|
Loading…
Reference in New Issue