cleanup: refactor by_group view

This commit is contained in:
stupidcomputer 2024-07-24 01:03:19 -05:00
parent 2a6e42da9c
commit c35c96e16b
4 changed files with 21 additions and 8 deletions

View File

@ -201,4 +201,6 @@ class LegislationClassification(models.Model):
def get_absolute_url(self):
our_name = __class__.__name__
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id})
models_in_index = [LegislationClassification, School, Country, Sponsor]

View File

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

View File

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

View File

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