From c35c96e16b8231faf5ff3d96083ea5b3baf71491 Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Wed, 24 Jul 2024 01:03:19 -0500 Subject: [PATCH] cleanup: refactor by_group view --- franklincce/explorer/models.py | 4 +++- .../explorer/templates/explorer/by_group.html | 7 +++---- franklincce/explorer/urls.py | 2 +- franklincce/explorer/views.py | 16 ++++++++++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/franklincce/explorer/models.py b/franklincce/explorer/models.py index 6bdbfa5..a06f2dc 100644 --- a/franklincce/explorer/models.py +++ b/franklincce/explorer/models.py @@ -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}) \ No newline at end of file + return reverse("{}.detail".format(our_name), kwargs={"model_id": self.id}) + +models_in_index = [LegislationClassification, School, Country, Sponsor] \ No newline at end of file diff --git a/franklincce/explorer/templates/explorer/by_group.html b/franklincce/explorer/templates/explorer/by_group.html index 7a79121..8e4992f 100644 --- a/franklincce/explorer/templates/explorer/by_group.html +++ b/franklincce/explorer/templates/explorer/by_group.html @@ -7,10 +7,9 @@

View legislation

{% endblock content %} \ No newline at end of file diff --git a/franklincce/explorer/urls.py b/franklincce/explorer/urls.py index c334dba..d02a913 100644 --- a/franklincce/explorer/urls.py +++ b/franklincce/explorer/urls.py @@ -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") ] diff --git a/franklincce/explorer/views.py b/franklincce/explorer/views.py index f468e39..46aa244 100644 --- a/franklincce/explorer/views.py +++ b/franklincce/explorer/views.py @@ -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)