def event(request, e_slug): """Render event questions.""" event = Event.objects.get(slug=e_slug) questions = (Question.objects.filter(event=event) .annotate(vote_count=Count('votes')) .order_by('-vote_count')) question_form = None if not event.archived: question_form = QuestionForm(request.POST or None) if question_form and question_form.is_valid(): question = question_form.save(commit=False) question.asked_by = request.user question.event = event question.save() Vote.objects.create(user=request.user, question=question) return redirect(reverse('event', kwargs={'e_slug': event.slug})) return render(request, 'questions.html', {'user': request.user, 'open': not event.archived, 'event': event, 'questions': questions, 'q_form': question_form})
def show_event(request, e_slug, q_id=None): """Render event questions.""" event = get_object_or_404(Event, slug=e_slug) question = None user = request.user # Do not display NDA events to non NDA members or non employees. if event.is_nda and not user.userprofile.is_nda_member: raise Http404 if q_id: question = Question.objects.get(id=q_id) questions_q = Question.objects.filter(event=event).annotate( vote_count=Count("votes")) if user.userprofile.is_admin: questions = questions_q.order_by("-vote_count") else: questions = questions_q.order_by("?") question_form = QuestionForm(request.POST or None, instance=question) is_replied = False if question_form.is_valid() and not event.archived: question_obj = question_form.save(commit=False) # Do not change the user if posting a reply if not question_obj.id: if not question_obj.is_anonymous: question_obj.asked_by = user elif not user.userprofile.is_admin: raise Http404 else: is_replied = True question_obj.event = event question_obj.save() if (not Vote.objects.filter(user=user, question=question_obj).exists() and not is_replied): Vote.objects.create(user=user, question=question_obj) return redirect(reverse("event", kwargs={"e_slug": event.slug})) return render( request, "questions.jinja", { "user": user, "open": not event.archived, "event": event, "questions": questions, "q_form": question_form, }, )
def event(request, e_slug, q_id=None): """Render event questions.""" event = Event.objects.get(slug=e_slug) question = None user = request.user # Do not display NDA events to non NDA members or non employees. if event.is_nda and not user.userprofile.is_nda_member: raise Http404 if q_id: question = Question.objects.get(id=q_id) questions_q = Question.objects.filter(event=event).annotate( vote_count=Count('votes')) questions = questions_q.order_by('-vote_count') question_form = QuestionForm(request.POST or None, instance=question) is_replied = False if question_form.is_valid() and not event.archived: question_obj = question_form.save(commit=False) # Do not change the user if posting a reply if not question_obj.id: question_obj.asked_by = user elif not user.userprofile.is_admin: raise Http404 else: is_replied = True question_obj.event = event question_obj.save() if not Vote.objects.filter( user=user, question=question_obj).exists() and not is_replied: Vote.objects.create(user=user, question=question_obj) return redirect(reverse('event', kwargs={'e_slug': event.slug})) return render( request, 'questions.jinja', { 'user': user, 'open': not event.archived, 'event': event, 'questions': questions, 'q_form': question_form })
def show_event(request, e_slug, q_id=None): """Render event questions.""" event = get_object_or_404(Event, slug=e_slug) question = None user = request.user # Do not display NDA events to non NDA members or non employees. if event.is_nda and not user.userprofile.is_nda_member: raise Http404 if q_id: question = Question.objects.get(id=q_id) questions_q = Question.objects.filter(event=event).annotate(vote_count=Count('votes')) questions = questions_q.order_by('-vote_count') question_form = QuestionForm(request.POST or None, instance=question) is_replied = False if question_form.is_valid() and not event.archived: question_obj = question_form.save(commit=False) # Do not change the user if posting a reply if not question_obj.id: if not question_obj.is_anonymous: question_obj.asked_by = user elif not user.userprofile.is_admin: raise Http404 else: is_replied = True question_obj.event = event question_obj.save() if not Vote.objects.filter(user=user, question=question_obj).exists() and not is_replied: Vote.objects.create(user=user, question=question_obj) return redirect(reverse('event', kwargs={'e_slug': event.slug})) return render(request, 'questions.jinja', {'user': user, 'open': not event.archived, 'event': event, 'questions': questions, 'q_form': question_form})
def event(request, e_slug, q_id=None): """Render event questions.""" event = Event.objects.get(slug=e_slug) question = None user = request.user if q_id: question = Question.objects.get(id=q_id) questions = (Question.objects.filter(event=event) .annotate(vote_count=Count('votes')) .order_by('-vote_count')) question_form = QuestionForm(request.POST or None, instance=question) is_reply = False if question_form.is_valid() and not event.archived: question_obj = question_form.save(commit=False) # Do not change the user if posting an reply if not question_obj.id: question_obj.asked_by = user elif not user.userprofile.is_admin: raise Http404 else: is_reply = True question_obj.event = event question_obj.save() if (not Vote.objects.filter(user=user, question=question_obj).exists() and not is_reply): Vote.objects.create(user=user, question=question_obj) return redirect(reverse('event', kwargs={'e_slug': event.slug})) return render(request, 'questions.html', {'user': user, 'open': not event.archived, 'event': event, 'questions': questions, 'q_form': question_form})
def event(request, e_slug): """Render event questions.""" event = Event.objects.get(slug=e_slug) questions = Question.objects.filter(event=event).annotate(vote_count=Count("votes")).order_by("-vote_count") if request.POST: question_form = QuestionForm(request.POST) if question_form.is_valid(): question = question_form.save(commit=False) question.asked_by = request.user question.event = event question.save() return redirect(reverse("event", kwargs={"e_slug": event.slug})) else: question_form = QuestionForm() return render( request, "questions.html", {"user": request.user, "event": event, "questions": questions, "q_form": question_form}, )