def review_detail(request, pk): proposals = ProposalBase.objects.select_related( "result").select_subclasses() proposal = get_object_or_404(proposals, pk=pk) if not request.user.has_perm( "reviews.can_review_%s" % proposal.kind.section.slug): return access_not_permitted(request) speakers = [s.user for s in proposal.speakers()] if not request.user.is_superuser and request.user in speakers: return access_not_permitted(request) admin = request.user.is_staff try: latest_vote = LatestVote.objects.get(proposal=proposal, user=request.user) except LatestVote.DoesNotExist: latest_vote = None review_form = None message_form = None proposal_tags_form = None if request.method == "POST": if request.user in speakers: return access_not_permitted(request) if "vote_submit" in request.POST \ and (is_voting_period_active(proposal) or is_review_period_active(proposal)): if is_voting_period_active(proposal): review_form = ReviewForm(request.POST) else: review_form = NonVotingReviewForm(request.POST) if review_form.is_valid(): review = review_form.save(commit=False) review.user = request.user review.proposal = proposal review.save() return redirect(request.path) else: message_form = SpeakerCommentForm() elif "tags_submit" in request.POST: proposal_tags_form = ProposalTagsForm(request.POST) if proposal_tags_form.is_valid(): tags = proposal_tags_form.cleaned_data['tags'] proposal.tags.set(*tags) return redirect(request.path) else: message_form = SpeakerCommentForm() if request.user not in speakers: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if is_voting_period_active(proposal): review_form = ReviewForm(initial=initial) elif is_review_period_active(proposal): review_form = NonVotingReviewForm() elif "message_submit" in request.POST and is_review_period_active( proposal): message_form = SpeakerCommentForm(request.POST) if message_form.is_valid(): message = message_form.save(commit=False) message.user = request.user message.proposal = proposal message.save() for speaker in speakers: if speaker and speaker.email: ctx = { "proposal": proposal, "message": message, "reviewer": False, } send_email([speaker.email], "proposal_new_message", context=ctx) return redirect(request.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request.user not in speakers: if is_voting_period_active(proposal): review_form = ReviewForm(initial=initial) elif is_review_period_active(proposal): review_form = NonVotingReviewForm() elif "result_submit" in request.POST: if admin: result = request.POST["result_submit"] if result == "accept": proposal.result.status = "accepted" proposal.result.save() elif result == "reject": proposal.result.status = "rejected" proposal.result.save() elif result == "undecide": proposal.result.status = "undecided" proposal.result.save() elif result == "standby": proposal.result.status = "standby" proposal.result.save() return redirect(request.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request.user not in speakers: if is_voting_period_active(proposal): review_form = ReviewForm(initial=initial) elif is_review_period_active(proposal): review_form = NonVotingReviewForm() tags = edit_string_for_tags(proposal.tags.all()) proposal_tags_form = ProposalTagsForm(initial={'tags': tags}) if is_review_period_active(proposal) and request.user not in speakers: message_form = SpeakerCommentForm() proposal.comment_count = proposal.result.comment_count proposal.total_votes = proposal.result.vote_count proposal.plus_one = proposal.result.plus_one proposal.plus_zero = proposal.result.plus_zero proposal.minus_zero = proposal.result.minus_zero proposal.minus_one = proposal.result.minus_one reviews = Review.objects.filter( proposal=proposal).order_by("-submitted_at") messages = proposal.messages.order_by("submitted_at") return render( request, "reviews/review_detail.html", { "proposal": proposal, "latest_vote": latest_vote, "reviews": reviews, "review_messages": messages, "review_form": review_form, "proposal_tags_form": proposal_tags_form, "message_form": message_form, })
def review_detail(request_review_detail, pk): proposals = ProposalBase.objects.select_related( "result").select_subclasses() proposal = get_object_or_404(proposals, pk=pk) if not request_review_detail.user.has_perm( "reviews.can_review_%s" % proposal.kind.section.slug): return render(request_review_detail, "symposion/reviews/access_not_permitted.html", "you do not have access to review details") speakers = [s.user for s in proposal.speakers()] if not request_review_detail.user.is_superuser and request_review_detail.user in speakers: return render(request_review_detail, "symposion/reviews/access_not_permitted.html", "you do not have access to review details for speakers") admin = request_review_detail.user.is_staff try: latest_vote = LatestVote.objects.get(proposal=proposal, user=request_review_detail.user) except LatestVote.DoesNotExist: latest_vote = None if request_review_detail.method == "POST": if request_review_detail.user in speakers: return render( request_review_detail, "symposion/reviews/access_not_permitted.html", "you do not have access to review details for speakers") if "vote_submit" in request_review_detail.POST: review_form = ReviewForm(request_review_detail.POST) if review_form.is_valid(): review = review_form.save(commit=False) review.user = request_review_detail.user review.proposal = proposal review.save() return redirect(request_review_detail.path) else: message_form = SpeakerCommentForm() elif "message_submit" in request_review_detail.POST: message_form = SpeakerCommentForm(request_review_detail.POST) if message_form.is_valid(): message = message_form.save(commit=False) message.user = request_review_detail.user message.proposal = proposal message.save() for speaker in speakers: if speaker and speaker.email: ctx = { "proposal": proposal, "message": message, "reviewer": False, } send_email([speaker.email], "proposal_new_message", context=ctx) return redirect(request_review_detail.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request_review_detail.user in speakers: review_form = None else: review_form = ReviewForm(initial=initial) elif "result_submit" in request_review_detail.POST: if admin: result = request_review_detail.POST["result_submit"] if result == "accept": proposal.result.status = "accepted" proposal.result.save() elif result == "reject": proposal.result.status = "rejected" proposal.result.save() elif result == "undecide": proposal.result.status = "undecided" proposal.result.save() elif result == "standby": proposal.result.status = "standby" proposal.result.save() return redirect(request_review_detail.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request_review_detail.user in speakers: review_form = None else: review_form = ReviewForm(initial=initial) message_form = SpeakerCommentForm() proposal.comment_count = proposal.result.comment_count proposal.total_votes = proposal.result.vote_count proposal.plus_one = proposal.result.plus_one proposal.plus_zero = proposal.result.plus_zero proposal.minus_zero = proposal.result.minus_zero proposal.minus_one = proposal.result.minus_one reviews = Review.objects.filter( proposal=proposal).order_by("-submitted_at") messages = proposal.messages.order_by("submitted_at") return render( request_review_detail, "symposion/reviews/review_detail.html", { "proposal": proposal, "latest_vote": latest_vote, "reviews": reviews, "review_messages": messages, "review_form": review_form, "message_form": message_form })
def review_detail(request, pk): proposals = ProposalBase.objects.select_related("result").select_subclasses() proposal = get_object_or_404(proposals, pk=pk) if not request.user.has_perm("reviews.can_review_%s" % proposal.kind.section.slug): return access_not_permitted(request) speakers = [s.user for s in proposal.speakers()] if not request.user.is_superuser and request.user in speakers: return access_not_permitted(request) admin = request.user.is_staff try: latest_vote = LatestVote.objects.get(proposal=proposal, user=request.user) except LatestVote.DoesNotExist: latest_vote = None if request.method == "POST": if request.user in speakers: return access_not_permitted(request) if "vote_submit" in request.POST: review_form = ReviewForm(request.POST) if review_form.is_valid(): review = review_form.save(commit=False) review.user = request.user review.proposal = proposal review.save() return redirect(request.path) else: message_form = SpeakerCommentForm() elif "message_submit" in request.POST: message_form = SpeakerCommentForm(request.POST) if message_form.is_valid(): message = message_form.save(commit=False) message.user = request.user message.proposal = proposal message.save() for speaker in speakers: if speaker and speaker.email: ctx = { "proposal": proposal, "message": message, "reviewer": False, } send_email( [speaker.email], "proposal_new_message", context=ctx ) return redirect(request.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request.user in speakers: review_form = None else: review_form = ReviewForm(initial=initial) elif "result_submit" in request.POST: if admin: result = request.POST["result_submit"] if result == "accept": proposal.result.status = "accepted" proposal.result.save() elif result == "reject": proposal.result.status = "rejected" proposal.result.save() elif result == "undecide": proposal.result.status = "undecided" proposal.result.save() elif result == "standby": proposal.result.status = "standby" proposal.result.save() return redirect(request.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request.user in speakers: review_form = None else: review_form = ReviewForm(initial=initial) message_form = SpeakerCommentForm() proposal.comment_count = proposal.result.comment_count proposal.total_votes = proposal.result.vote_count proposal.plus_one = proposal.result.plus_one proposal.plus_zero = proposal.result.plus_zero proposal.minus_zero = proposal.result.minus_zero proposal.minus_one = proposal.result.minus_one reviews = Review.objects.filter(proposal=proposal).order_by("-submitted_at") messages = proposal.messages.order_by("submitted_at") return render(request, "symposion/reviews/review_detail.html", { "proposal": proposal, "latest_vote": latest_vote, "reviews": reviews, "review_messages": messages, "review_form": review_form, "message_form": message_form })
def review_detail(request, pk): proposals = ProposalBase.objects.select_related( "result").select_subclasses() proposal = get_object_or_404(proposals, pk=pk) if not request.user.has_perm( "reviews.can_review_%s" % proposal.kind.section.slug): return access_not_permitted(request) speakers = [s.user for s in proposal.speakers()] if not request.user.is_superuser and request.user in speakers: return access_not_permitted(request) admin = request.user.has_perm("reviews.can_manage_%s" % proposal.kind.section.slug) try: latest_vote = LatestVote.objects.get(proposal=proposal, user=request.user) except LatestVote.DoesNotExist: latest_vote = None if request.method == "POST": if request.user in speakers: return access_not_permitted(request) if "vote_submit" in request.POST or "vote_submit_and_random" in request.POST: review_form = ReviewForm(request.POST) if review_form.is_valid(): review = review_form.save(commit=False) review.user = request.user review.proposal = proposal review.save() if "vote_submit_and_random" in request.POST: next_page = redirect("user_random", proposal.kind.section.slug) next_page["Location"] += "#invalid_fragment" # Hack. else: next_page = redirect(request.path) return next_page else: message_form = SpeakerCommentForm() elif "message_submit" in request.POST and admin: message_form = SpeakerCommentForm(request.POST) if message_form.is_valid(): message = message_form.save(commit=False) message.user = request.user message.proposal = proposal message.save() for speaker in speakers: if speaker and speaker.email: ctx = { "proposal": proposal, "message": message, "reviewer": False, } send_email([speaker.email], "proposal_new_message", context=ctx) return redirect(request.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request.user in speakers: review_form = None else: review_form = ReviewForm(initial=initial) elif "result_submit" in request.POST: if admin: result = request.POST["result_submit"] if result == "accept": proposal.result.status = "accepted" proposal.result.save() elif result == "reject": proposal.result.status = "rejected" proposal.result.save() elif result == "undecide": proposal.result.status = "undecided" proposal.result.save() elif result == "standby": proposal.result.status = "standby" proposal.result.save() return redirect(request.path) elif "publish_changes" in request.POST: if admin and proposal.result.status == "accepted": promote_proposal(proposal) return redirect(request.path) else: initial = {} if latest_vote: initial["vote"] = latest_vote.vote if request.user in speakers: review_form = None else: review_form = ReviewForm(initial=initial) message_form = SpeakerCommentForm() proposal.comment_count = proposal.result.comment_count proposal.total_votes = proposal.result.vote_count proposal.plus_two = proposal.result.plus_two proposal.plus_one = proposal.result.plus_one proposal.minus_one = proposal.result.minus_one proposal.minus_two = proposal.result.minus_two reviews = Review.objects.filter( proposal=proposal).order_by("-submitted_at") messages = proposal.messages.order_by("submitted_at") return render( request, "symposion/reviews/review_detail.html", { "proposal": proposal, "latest_vote": latest_vote, "reviews": reviews, "review_messages": messages, "review_form": review_form, "message_form": message_form, "is_manager": admin })