From 6811708b334d3bd8ad4ea9cfe4c17ced028f43f4 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Mon, 4 Jul 2016 16:10:02 +1000 Subject: [PATCH 1/2] Adds a view that returns all proposals in CSV format. Fixes #27 --- symposion/reviews/urls.py | 6 +++++- symposion/reviews/views.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/symposion/reviews/urls.py b/symposion/reviews/urls.py index 0ecc34e2..6c35f3bb 100644 --- a/symposion/reviews/urls.py +++ b/symposion/reviews/urls.py @@ -14,6 +14,7 @@ from .views import ( review_delete, review_assignments, review_assignment_opt_out, + review_all_proposals_csv, ) urlpatterns = [ @@ -36,5 +37,8 @@ urlpatterns = [ url(r"^(?P\d+)/delete/$", review_delete, name="review_delete"), url(r"^assignments/$", review_assignments, name="review_assignments"), - url(r"^assignment/(?P\d+)/opt-out/$", review_assignment_opt_out, name="review_assignment_opt_out") + url(r"^assignment/(?P\d+)/opt-out/$", review_assignment_opt_out, name="review_assignment_opt_out"), + + url(r"^csv$", review_all_proposals_csv, name="review_all_proposals_csv"), + ] diff --git a/symposion/reviews/views.py b/symposion/reviews/views.py index 9bbbddf5..94ac7d70 100644 --- a/symposion/reviews/views.py +++ b/symposion/reviews/views.py @@ -1,7 +1,10 @@ +import csv import random +import StringIO from django.core.mail import send_mass_mail from django.db.models import Q +from django.http import HttpResponse from django.http import HttpResponseBadRequest, HttpResponseNotAllowed from django.shortcuts import render, redirect, get_object_or_404 from django.template import Context, Template @@ -107,6 +110,40 @@ def review_section(request, section_slug, assigned=False, reviewed="all"): 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. ''' + + queryset = ProposalBase.objects.filter() + + # The fields from each proposal object to report in the csv + fields = [ + "id", "kind", "speaker_name", "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 + proposal.kind = proposal.kind.section.slug + + if not request.user.has_perm("reviews.can_review_%s" % proposal.kind): + continue + + csv_line = [getattr(proposal, field) for field in fields] + + writer.writerow(csv_line) + + return HttpResponse(output.getvalue(), "text/csv") + + @login_required def review_random_proposal(request, section_slug): # lca2017 #16 view for random proposal From 6ebd0f09057b6625a488dfb5b489f51d3b13da7c Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Mon, 4 Jul 2016 16:28:31 +1000 Subject: [PATCH 2/2] snoops --- symposion/reviews/views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/symposion/reviews/views.py b/symposion/reviews/views.py index 94ac7d70..349966b8 100644 --- a/symposion/reviews/views.py +++ b/symposion/reviews/views.py @@ -119,7 +119,7 @@ def review_all_proposals_csv(request): # The fields from each proposal object to report in the csv fields = [ - "id", "kind", "speaker_name", "title", "submitted", "cancelled", "status", + "id", "proposal_type", "speaker_name", "title", "submitted", "cancelled", "status", "score", "total_votes", "minus_two", "minus_one", "plus_one", "plus_two", ] @@ -132,9 +132,10 @@ def review_all_proposals_csv(request): for proposal in proposals_generator(request, queryset, check_speaker=False): proposal.speaker_name = proposal.speaker.name - proposal.kind = proposal.kind.section.slug + section_slug = proposal.kind.section.slug + proposal.proposal_type = section_slug - if not request.user.has_perm("reviews.can_review_%s" % proposal.kind): + if not request.user.has_perm("reviews.can_review_%s" % section_slug): continue csv_line = [getattr(proposal, field) for field in fields]