Create JSON endpoint for Service
and Genre
list and detail views
#1612
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Returns JSON responses to requests to
Service
andGenre
urls if the request'sAccept
header isapplication/json
.Implements a new class
JSONResponseMixin
that handles the content negotiation according to theAccept
header. Classes inheriting from this mixin should define ajson_fields
attribute that lists the fields on the model that should be returned in the JSON response.JSON responses are in the form of a object with a key being the model name (singular, in the case of a
DetailView
and plural in the case of aListView
-- this matches the CantusDB standard for urls).For example, a request to
/services
withAccept: application/json
will return:A request to
/service/1234
withAccept: application/json
will return:The PR also adds appropriate tests for the
GenreDetail
,GenreList
,ServiceDetail
, andServiceList
views. These tests weren't really making use of Django'sTestCase
functionality for setting up test data, so I did some refactoring there too.Finally, the
GenreListView
was inheriting from aSearchableListMixin
but was not making use of that mixin's functionality (the filtering for that view was implemented in the overwrittenget_queryset
method), so I removed that inheritance.Closes #1609.