2024-07-13 14:38:42 +02:00
|
|
|
from django.http import HttpResponseNotFound, HttpResponse, HttpResponseBadRequest
|
2024-07-12 17:22:17 +02:00
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
|
|
from content.models import Question
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search_question(request):
|
|
|
|
|
term = request.GET.get('term')
|
|
|
|
|
items = []
|
2024-07-13 10:19:49 +02:00
|
|
|
published = Question.objects.filter(is_published=True)
|
2024-07-12 17:22:17 +02:00
|
|
|
if term:
|
2024-07-13 10:19:49 +02:00
|
|
|
items = Question.get_by_tearchterm(term, published)
|
2024-07-12 17:22:17 +02:00
|
|
|
else:
|
2024-07-13 10:19:49 +02:00
|
|
|
items = published.all()[:10]
|
2024-07-12 17:22:17 +02:00
|
|
|
return render(request, 'questions.html', {'items': items})
|
2024-07-13 14:38:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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')
|