Changeset - 4f71de1dbf4d
[Not reviewed]
Merge
0 2 0
Scott Bragg - 8 years ago 2016-08-15 04:10:21
jsbragg@scriptforge.org
Merge pull request #41 from lca2017/chrisjrn/20160815

Adds more fields to /review/admin
2 files changed with 41 insertions and 20 deletions:
0 comments (0 inline, 0 general)
symposion/reviews/urls.py
Show inline comments
...
 
@@ -16,25 +16,25 @@ from .views import (
 
    review_assignment_opt_out,
 
    review_all_proposals_csv,
 
)
 

	
 
urlpatterns = [
 
    url(r"^section/(?P<section_slug>[\w\-]+)/all/$", review_section, {"reviewed": "all"}, name="review_section"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/reviewed/$", review_section, {"reviewed": "reviewed"}, name="user_reviewed"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/not_reviewed/$", review_section, {"reviewed": "not_reviewed"}, name="user_not_reviewed"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/random/$", review_random_proposal, name="user_random"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/assignments/$", review_section, {"assigned": True}, name="review_section_assignments"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/status/$", review_status, name="review_status"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/status/(?P<key>\w+)/$", review_status, name="review_status"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/list/(?P<user_pk>\d+)/$", review_list, name="review_list_user"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/list_reviewer/(?P<user_pk>\d+)/$", review_list, name="review_list_user"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/admin/$", review_admin, name="review_admin"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/admin/accept/$", review_bulk_accept, name="review_bulk_accept"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/notification/(?P<status>\w+)/$", result_notification, name="result_notification"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/notification/(?P<status>\w+)/prepare/$", result_notification_prepare, name="result_notification_prepare"),
 
    url(r"^section/(?P<section_slug>[\w\-]+)/notification/(?P<status>\w+)/send/$", result_notification_send, name="result_notification_send"),
 

	
 

	
 
    url(r"^review/(?P<pk>\d+)/$", review_detail, name="review_detail"),
 

	
 
    url(r"^(?P<pk>\d+)/delete/$", review_delete, name="review_delete"),
 
    url(r"^assignments/$", review_assignments, name="review_assignments"),
 
    url(r"^assignment/(?P<pk>\d+)/opt-out/$", review_assignment_opt_out, name="review_assignment_opt_out"),
symposion/reviews/views.py
Show inline comments
...
 
@@ -138,58 +138,59 @@ def review_section(request, section_slug, assigned=False, reviewed="all"):
 
        "section": section,
 
        "reviewed": reviewed,
 
    }
 

	
 
    return render(request, "symposion/reviews/review_list.html", ctx)
 

	
 

	
 
@login_required
 
def review_all_proposals_csv(request):
 
    ''' Returns a CSV representation of all of the proposals this user has
 
    permisison to review. '''
 

	
 
    response = HttpResponse("text/csv")
 
    response['Content-Disposition'] = 'attachment; filename="proposals.csv"'
 
    writer = csv.writer(response, quoting=csv.QUOTE_NONNUMERIC)
 

	
 
    queryset = ProposalBase.objects.filter()
 

	
 
    # The fields from each proposal object to report in the csv
 
    fields = [
 
        "id", "proposal_type", "speaker_name","speaker_email", "title",
 
        "submitted", "cancelled", "status",
 
        "score", "total_votes", "minus_two", "minus_one", "plus_one", "plus_two",
 
    ]
 

	
 
    output = StringIO.StringIO()
 
    writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC)
 

	
 
    # Fields are the heading
 
    writer.writerow(fields)
 

	
 
    for proposal in proposals_generator(request, queryset, check_speaker=False):
 

	
 
        proposal.speaker_name = proposal.speaker.name
 
        section_slug = proposal.kind.section.slug
 
        proposal.proposal_type = section_slug
 

	
 
        if not request.user.has_perm("reviews.can_review_%s" % section_slug):
 
            continue
 

	
 
        csv_line = [getattr(proposal, field) for field in fields]
 

	
 
        # Enusre that unicode items are handled properly.
 
        for i, item in enumerate(csv_line):
 
            if isinstance(item, unicode):
 
                csv_line[i] = item.encode("utf8")
 

	
 
        writer.writerow(csv_line)
 

	
 
    return HttpResponse(output.getvalue(), "text/csv")
 
    return response
 

	
 

	
 
@login_required
 
def review_random_proposal(request, section_slug):
 
    # lca2017 #16 view for random proposal
 

	
 
    if not request.user.has_perm("reviews.can_review_%s" % section_slug):
 
        return access_not_permitted(request)
 

	
 
    section = get_object_or_404(ProposalSection, section__slug=section_slug)
 
    queryset = ProposalBase.objects.filter(kind__section=section.section)
 
    # Remove ones already reviewed
...
 
@@ -228,61 +229,75 @@ def review_list(request, section_slug, user_pk):
 
    queryset = ProposalBase.objects.select_related("speaker__user", "result")
 
    reviewed = LatestVote.objects.filter(user__pk=user_pk).values_list("proposal", flat=True)
 
    queryset = queryset.filter(pk__in=reviewed)
 
    proposals = queryset.order_by("submitted")
 

	
 
    admin = request.user.has_perm("reviews.can_manage_%s" % section_slug)
 

	
 
    proposals = proposals_generator(request, proposals, user_pk=user_pk, check_speaker=not admin)
 

	
 
    ctx = {
 
        "proposals": proposals,
 
    }
 
    return (request, "symposion/reviews/review_list.html", ctx)
 
    return render(request, "symposion/reviews/review_list.html", ctx)
 

	
 

	
 
@login_required
 
def review_admin(request, section_slug):
 

	
 
    if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
 
        return access_not_permitted(request)
 

	
 
    def reviewers():
 
        already_seen = set()
 

	
 
        for team in Team.objects.filter(permissions__codename="can_review_%s" % section_slug):
 
            for membership in team.memberships.filter(Q(state="member") | Q(state="manager")):
 
                user = membership.user
 
                if user.pk in already_seen:
 
                    continue
 
                already_seen.add(user.pk)
 

	
 
                user.comment_count = Review.objects.filter(user=user).count()
 
                user.total_votes = LatestVote.objects.filter(user=user).count()
 
                user.plus_two = LatestVote.objects.filter(
 
                user_votes = LatestVote.objects.filter(
 
                    user=user,
 
                    vote=LatestVote.VOTES.PLUS_TWO
 
                    proposal__kind__section__slug=section_slug,
 
                )
 
                print section_slug
 
                print [vote.proposal.kind.section.slug for vote in user_votes]
 
                user.total_votes = user_votes.exclude(
 
                    vote=LatestVote.VOTES.ABSTAIN,
 
                ).count()
 
                user.plus_one = LatestVote.objects.filter(
 
                    user=user,
 
                    vote=LatestVote.VOTES.PLUS_ONE
 
                user.plus_two = user_votes.filter(
 
                    vote=LatestVote.VOTES.PLUS_TWO,
 
                ).count()
 
                user.minus_one = LatestVote.objects.filter(
 
                    user=user,
 
                    vote=LatestVote.VOTES.MINUS_ONE
 
                user.plus_one = user_votes.filter(
 
                    vote=LatestVote.VOTES.PLUS_ONE,
 
                ).count()
 
                user.minus_two = LatestVote.objects.filter(
 
                    user=user,
 
                    vote=LatestVote.VOTES.MINUS_TWO
 
                user.minus_one = user_votes.filter(
 
                    vote=LatestVote.VOTES.MINUS_ONE,
 
                ).count()
 
                user.minus_two = user_votes.filter(
 
                    vote=LatestVote.VOTES.MINUS_TWO,
 
                ).count()
 
                user.abstain = user_votes.filter(
 
                    vote=LatestVote.VOTES.ABSTAIN,
 
                ).count()
 
                if user.total_votes == 0:
 
                    user.average = "-"
 
                else:
 
                    user.average = (
 
                        user.plus_two + user.plus_one +
 
                        user.minus_one + user.minus_two
 
                    ) / (user.total_votes * 1.0)
 

	
 
                yield user
 

	
 
    ctx = {
 
        "section_slug": section_slug,
 
        "reviewers": reviewers(),
 
    }
 
    return render(request, "symposion/reviews/review_admin.html", ctx)
 

	
 

	
 
# FIXME: This view is too complex according to flake8
 
@login_required
...
 
@@ -301,34 +316,40 @@ def review_detail(request, pk):
 

	
 
    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:
 
        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()
 

	
 
                return redirect(request.path)
 
                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:
0 comments (0 inline, 0 general)