generalize the view generation into a factory
This commit is contained in:
parent
37e6a03bb3
commit
0a6ed6ffe2
|
@ -10,6 +10,6 @@ urlpatterns = [
|
||||||
path("conference/<int:conference_id>/", views.view_conference, name="viewconf"),
|
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/<int:classification_id>/", views.get_all_classified_by_id, name="classificationview"),
|
||||||
path("topics/", views.get_all_classifications, name="classificationsview"),
|
path("topics/", views.get_all_classifications, name="classificationsview"),
|
||||||
path("schools/<int:school_id>/", views.get_all_by_school, name="schoolview"),
|
path("schools/<int:model_id>/", views.get_all_by_school, name="schoolview"),
|
||||||
path("countries/<int:country_id>/", views.get_all_by_country, name="countryview"),
|
path("countries/<int:model_id>/", views.get_all_by_country, name="countryview"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -81,18 +81,15 @@ def get_all_classified_by_id(request, classification_id):
|
||||||
"result_name": "All legislation in topic {}".format(classification.name)
|
"result_name": "All legislation in topic {}".format(classification.name)
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_all_by_school(request, school_id):
|
def get_all_by_x(model):
|
||||||
school = get_object_or_404(School, pk=school_id)
|
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", {
|
get_all_by_school = get_all_by_x(School)
|
||||||
"result_name": "All legislation by {}".format(school.name),
|
get_all_by_country = get_all_by_x(Country)
|
||||||
"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()
|
|
||||||
})
|
|
Loading…
Reference in New Issue