question as csv
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from django.http import HttpResponseNotFound, HttpResponse, HttpResponseBadRequest
|
||||
from django.shortcuts import render
|
||||
|
||||
from content.models import Question
|
||||
@@ -12,3 +13,14 @@ def search_question(request):
|
||||
else:
|
||||
items = published.all()[:10]
|
||||
return render(request, 'questions.html', {'items': items})
|
||||
|
||||
|
||||
def as_csv(request, **kwargs):
|
||||
try:
|
||||
q = Question.objects.get(id=kwargs['id'])
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
return q.to_csv(fh=response)
|
||||
except KeyError:
|
||||
return HttpResponseBadRequest('No id given')
|
||||
except Question.DoesNotExist:
|
||||
return HttpResponseNotFound('Question not found')
|
||||
|
||||
Reference in New Issue
Block a user