pedagogy: support json response from search API

This commit is contained in:
Antoine Bartuccio 2019-06-19 00:56:59 +02:00
parent e11d45b51e
commit 2cbef2babc
Signed by: klmp200
GPG Key ID: E7245548C53F904B

View File

@ -31,8 +31,10 @@ from django.views.generic import (
FormView, FormView,
View, View,
) )
from django.core.urlresolvers import reverse_lazy from django.core import serializers
from django.utils import html from django.utils import html
from django.http import HttpResponse
from django.core.urlresolvers import reverse_lazy
from core.views import ( from core.views import (
DetailFormView, DetailFormView,
@ -147,6 +149,17 @@ class UVListView(CanViewMixin, CanCreateUVFunctionMixin, ListView):
ordering = ["code"] ordering = ["code"]
template_name = "pedagogy/guide.jinja" template_name = "pedagogy/guide.jinja"
def get(self, *args, **kwargs):
if not self.request.GET.get("json", None):
# Return normal full template response
return super(UVListView, self).get(*args, **kwargs)
# Return serialized response
return HttpResponse(
serializers.serialize("json", self.get_queryset()),
content_type="application/json",
)
def get_queryset(self): def get_queryset(self):
query = self.request.GET.get("query", None) query = self.request.GET.get("query", None)