cleanup: refactor by_group view
This commit is contained in:
parent
2a6e42da9c
commit
c35c96e16b
|
@ -201,4 +201,6 @@ class LegislationClassification(models.Model):
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
our_name = __class__.__name__
|
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]
|
|
@ -7,10 +7,9 @@
|
||||||
<h1>View legislation</h1>
|
<h1>View legislation</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/explorer/countries/">By country</a></li>
|
{% for name, url in listing.items %}
|
||||||
<li><a href="/explorer/schools/">By school</a></li>
|
<li><a href="{{ url }}">By {{ name }}</a></li>
|
||||||
<li><a href="/explorer/topics/">By topic</a></li>
|
{% endfor %}
|
||||||
<li><a href="/explorer/sponsors/">By sponsor</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
|
@ -18,5 +18,5 @@ urlpatterns = [
|
||||||
path("schools/", views.get_all_schools, name="School"),
|
path("schools/", views.get_all_schools, name="School"),
|
||||||
path("countries/", views.get_all_countries, name="Country"),
|
path("countries/", views.get_all_countries, name="Country"),
|
||||||
path("groups/", views.return_groups, name="Groups"),
|
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.shortcuts import get_object_or_404, render
|
||||||
|
from django.urls import reverse
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
|
@ -7,7 +8,8 @@ from .models import (
|
||||||
LegislationClassification,
|
LegislationClassification,
|
||||||
School,
|
School,
|
||||||
Country,
|
Country,
|
||||||
Sponsor
|
Sponsor,
|
||||||
|
models_in_index,
|
||||||
)
|
)
|
||||||
|
|
||||||
from random import sample
|
from random import sample
|
||||||
|
@ -115,7 +117,17 @@ def get_all_xs(model):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def return_groups(request):
|
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_school = get_all_by_x(School)
|
||||||
get_all_by_country = get_all_by_x(Country)
|
get_all_by_country = get_all_by_x(Country)
|
||||||
|
|
Loading…
Reference in New Issue