1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.core.urlresolvers import reverse_lazy
6 from django.views.generic import ListView
7 from django.views.generic.edit import FormView
8 from .forms import QuestionForm
9 from .models import Question, Tag
12 class QuestionFormView(FormView):
13 form_class = QuestionForm
14 template_name = "questions/question_form.html"
15 success_url = reverse_lazy("questions_thanks")
17 def form_valid(self, form):
19 return super(QuestionFormView, self).form_valid(form)
22 class QuestionListView(ListView):
23 def get(self, request, *args, **kwargs):
25 if 'tag' in request.GET:
27 self.tag = Tag.objects.get(slug=request.GET['tag'])
28 except Tag.DoesNotExist:
30 return super(QuestionListView, self).get(request, *args, **kwargs)
32 def get_queryset(self):
33 qs = Question.objects.filter(published=True
34 ).order_by('-published_at')
35 if 'tag' in self.request.GET:
36 qs = qs.filter(tags__slug=self.request.GET['tag'])
39 def get_context_data(self, *args, **kwargs):
40 context = super(QuestionListView, self).get_context_data(*args, **kwargs)
41 context['tags'] = Tag.objects.all()
42 context['tag'] = self.tag