@election_admin()
def voters_upload(request, election):
  """
  Upload a CSV of password-based voters with
  voter_id, email, name
  
  name and email are needed only if voter_type is static
  """

  ## TRYING this: allowing voters upload by admin when election is frozen
  #if election.frozen_at and not election.openreg:
  #  raise PermissionDenied()

  if request.method == "GET":
    return render_template(request, 'voters_upload', {'election': election, 'error': request.GET.get('e',None)})
    
  if request.method == "POST":
    if bool(request.POST.get('confirm_p', 0)):
      # launch the background task to parse that file
      tasks.voter_file_process.delay(voter_file_id = request.session['voter_file_id'])
      del request.session['voter_file_id']

      return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(voters_list_pretty, args=[election.uuid]))
    else:
      # we need to confirm
      if request.FILES.has_key('voters_file'):
        voters_file = request.FILES['voters_file']
        voter_file_obj = election.add_voters_file(voters_file)

        request.session['voter_file_id'] = voter_file_obj.id

        problems = []

        # import the first few lines to check
        try:
          voters = [v for v in voter_file_obj.itervoters()][:5]
        except:
          voters = []
          problems.append("your CSV file could not be processed. Please check that it is a proper CSV file.")

        # check if voter emails look like emails
        if False in [validate_email(v['email']) for v in voters]:
          problems.append("those don't look like correct email addresses. Are you sure you uploaded a file with email address as second field?")

        return render_template(request, 'voters_upload_confirm', {'election': election, 'voters': voters, 'problems': problems})
      else:
        return HttpResponseRedirect((settings.SECURE_URL_HOST + reverse(voters_upload, args=[election.uuid]), urllib.urlencode({'e':'no voter file specified, try again'})) % "%s?%s")
dataset/ETHPy150Open benadida/helios-server/helios/views.py/voters_upload/swapped operands of `%`