Beispiel #1
0
def proposal_detail(request, pk):
    queryset = Proposal.objects.select_related("speaker", "speaker__user")
    proposal = get_object_or_404(queryset, pk=pk)
    
    if request.user not in [p.user for p in proposal.speakers()]:
        raise Http404()
    
    message_form = SpeakerCommentForm()
    if request.method == "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()
            
            ProposalMessage = SpeakerCommentForm.Meta.model
            reviewers = User.objects.filter(
                id__in=ProposalMessage.objects.filter(
                    proposal=proposal
                ).exclude(
                    user=request.user
                ).distinct().values_list("user", flat=True)
            )
            
            for reviewer in reviewers:
                ctx = {
                    "proposal": proposal,
                    "message": message,
                    "reviewer": True,
                }
                send_email(
                    [reviewer.email], "proposal_new_message",
                    context = ctx
                )
            
            return redirect(request.path)
    else:
        message_form = SpeakerCommentForm()
    
    ctx = {
        "proposal": proposal,
        "message_form": message_form
    }
    ctx = RequestContext(request, ctx)
    return render_to_response("proposals/proposal_detail.html", ctx)
Beispiel #2
0
def review_detail(request, pk):
    proposals = Proposal.objects.select_related("result")
    proposal = get_object_or_404(proposals, pk=pk)
    
    admin = request.user.groups.filter(name="reviewers-admins").exists()
    speakers = [s.user for s in proposal.speakers()]
    
    if proposal.session_type == Proposal.SESSION_TYPE_TUTORIAL:
        if not request.user.groups.filter(name="reviewers-tutorials").exists():
            return access_not_permitted(request)
    else:
        if not request.user.groups.filter(name="reviewers").exists():
            return access_not_permitted(request)
    
    if not admin and request.user in speakers:
        return access_not_permitted(request)
    
    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 proposal.invited:
            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)
        elif "result_submit" in request.POST:
            if admin:
                result = request.POST["result_submit"]
                
                if result == "accept":
                    proposal.result.accepted = True
                    proposal.result.save()
                elif result == "reject":
                    proposal.result.accepted = False
                    proposal.result.save()
                elif result == "undecide":
                    proposal.result.accepted = None
                    proposal.result.save()
            
            return redirect(request.path)
    else:
        initial = {}
        if latest_vote:
            initial["vote"] = latest_vote.vote
        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")
    
    return render_to_response("reviews/review_detail.html", {
        "proposal": proposal,
        "latest_vote": latest_vote,
        "reviews": reviews,
        "review_form": review_form,
        "message_form": message_form
    }, context_instance=RequestContext(request))