generalize the view generation into a factory

This commit is contained in:
stupidcomputer 2024-06-30 21:05:34 -05:00
parent 37e6a03bb3
commit 0a6ed6ffe2
2 changed files with 13 additions and 16 deletions

View File

@ -10,6 +10,6 @@ urlpatterns = [
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
path("topics/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
path("topics/", views.get_all_classifications, name="classificationsview"),
path("schools/<int:school_id>/", views.get_all_by_school, name="schoolview"),
path("countries/<int:country_id>/", views.get_all_by_country, name="countryview"),
path("schools/<int:model_id>/", views.get_all_by_school, name="schoolview"),
path("countries/<int:model_id>/", views.get_all_by_country, name="countryview"),
]

View File

@ -81,18 +81,15 @@ def get_all_classified_by_id(request, classification_id):
"result_name": "All legislation in topic {}".format(classification.name)
})
def get_all_by_school(request, school_id):
school = get_object_or_404(School, pk=school_id)
def get_all_by_x(model):
def wrapped(request, model_id):
instance = get_object_or_404(model, pk=model_id)
return render(request, "explorer/results.html", {
"result_name": "All legislation by {}".format(instance.name),
"legislation": instance.legislativetext_set.all()
})
return wrapped
return render(request, "explorer/results.html", {
"result_name": "All legislation by {}".format(school.name),
"legislation": school.legislativetext_set.all()
})
def get_all_by_country(request, country_id):
country = get_object_or_404(Country, pk=country_id)
return render(request, "explorer/results.html", {
"result_name": "All legislation by country {}".format(country.name),
"legislation": country.legislativetext_set.all()
})
get_all_by_school = get_all_by_x(School)
get_all_by_country = get_all_by_x(Country)