Merge pull request #28 from lca2017/chrisjrn/27-better-csv

Adds a view that returns all proposals in CSV format.
This commit is contained in:
Scott Bragg 2016-07-04 21:26:18 +10:00 committed by GitHub
commit 9c47421d5a
2 changed files with 43 additions and 1 deletions

View file

@ -14,6 +14,7 @@ from .views import (
review_delete, review_delete,
review_assignments, review_assignments,
review_assignment_opt_out, review_assignment_opt_out,
review_all_proposals_csv,
) )
urlpatterns = [ urlpatterns = [
@ -36,5 +37,8 @@ urlpatterns = [
url(r"^(?P<pk>\d+)/delete/$", review_delete, name="review_delete"), url(r"^(?P<pk>\d+)/delete/$", review_delete, name="review_delete"),
url(r"^assignments/$", review_assignments, name="review_assignments"), 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") url(r"^assignment/(?P<pk>\d+)/opt-out/$", review_assignment_opt_out, name="review_assignment_opt_out"),
url(r"^csv$", review_all_proposals_csv, name="review_all_proposals_csv"),
] ]

View file

@ -1,7 +1,10 @@
import csv
import random import random
import StringIO
from django.core.mail import send_mass_mail from django.core.mail import send_mass_mail
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse
from django.http import HttpResponseBadRequest, HttpResponseNotAllowed from django.http import HttpResponseBadRequest, HttpResponseNotAllowed
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.template import Context, Template from django.template import Context, Template
@ -107,6 +110,41 @@ def review_section(request, section_slug, assigned=False, reviewed="all"):
return render(request, "symposion/reviews/review_list.html", ctx) 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", "proposal_type", "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
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]
writer.writerow(csv_line)
return HttpResponse(output.getvalue(), "text/csv")
@login_required @login_required
def review_random_proposal(request, section_slug): def review_random_proposal(request, section_slug):
# lca2017 #16 view for random proposal # lca2017 #16 view for random proposal