def get_context_data(self, **kwargs): context = super(Detail, self).get_context_data(**kwargs) context['sidebar_admin_url'] = reverse('admin:qanda_question_change', args=(context['object'].pk, )) context['answers'] = context['object'].answers.select_related('user') context['answer_form'] = AnswerForm() foia = self.object.foia if foia is not None: foia.public_file_count = (FOIAFile.objects.filter( foia=foia, access='public').aggregate(count=Count('id'))['count']) return context
def get_context_data(self, **kwargs): context = super(Detail, self).get_context_data(**kwargs) context['sidebar_admin_url'] = reverse('admin:qanda_question_change', args=(context['object'].pk, )) context['answers'] = context['object'].answers.select_related('user') context['answer_form'] = AnswerForm() foia = self.object.foia if foia is not None: foia.public_file_count = foia.files.filter(access='public').count() context['foia_viewable'] = (foia is not None and foia.has_perm( self.request.user, 'view')) return context
def create_answer(request, slug, idx): """Create an answer""" question = get_object_or_404(Question, slug=slug, pk=idx) if request.method == 'POST': form = AnswerForm(request.POST) if form.is_valid(): answer = form.save(commit=False) answer.user = request.user answer.date = datetime.now() answer.question = question answer.save() return redirect(answer.question) else: form = AnswerForm() return render( request, 'forms/answer.html', { 'form': form, 'question': question }, )
def get_context_data(self, **kwargs): context = super(Detail, self).get_context_data(**kwargs) context["sidebar_admin_url"] = reverse("admin:qanda_question_change", args=(context["object"].pk, )) context["answers"] = (context["object"].answers.filter( user__is_active=True).select_related("user__profile")) context["answer_form"] = AnswerForm() foia = self.object.foia if foia is not None: foia.public_file_count = foia.get_files().count() context["foia_viewable"] = foia is not None and foia.has_perm( self.request.user, "view") return context