diff --git a/helios/forms.py b/helios/forms.py index cb10cfab8b7179b315f866de6ff1705dcb0d83f5..86fc18e5e3a0e88e4a65f32b62ef12b2bc1dea56 100644 --- a/helios/forms.py +++ b/helios/forms.py @@ -4,8 +4,8 @@ Forms for Helios from django import forms from models import Election -from widgets import * -from fields import * +from widgets import SplitSelectDateTimeWidget +from fields import SplitDateTimeField from django.conf import settings diff --git a/helios/management/commands/helios_trustee_decrypt.py b/helios/management/commands/helios_trustee_decrypt.py index 3dc75a4af8cd60562fed548483878603f7dd2875..4788330201a8d450a93be278d18506c86b32ff49 100644 --- a/helios/management/commands/helios_trustee_decrypt.py +++ b/helios/management/commands/helios_trustee_decrypt.py @@ -8,12 +8,10 @@ ben@adida.net 2010-05-22 """ -from django.core.management.base import BaseCommand, CommandError -import csv, datetime +from django.core.management.base import BaseCommand -from helios import utils as helios_utils +from helios.models import Trustee -from helios.models import * class Command(BaseCommand): args = '' diff --git a/helios/management/commands/load_voter_files.py b/helios/management/commands/load_voter_files.py index 5b82285a68650b1a06ae36c0f3bb3dd0cea236e7..c34e682aba306f9bd1380a5ed1dafa91cb247b8b 100644 --- a/helios/management/commands/load_voter_files.py +++ b/helios/management/commands/load_voter_files.py @@ -8,12 +8,15 @@ ben@adida.net 2010-05-22 """ -from django.core.management.base import BaseCommand, CommandError -import csv, datetime +import datetime + +import csv +import uuid +from django.core.management.base import BaseCommand from helios import utils as helios_utils +from helios.models import User, Voter, VoterFile -from helios.models import * ## ## UTF8 craziness for CSV @@ -27,42 +30,45 @@ def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs): # decode UTF-8 back to Unicode, cell by cell: yield [unicode(cell, 'utf-8') for cell in row] + def utf_8_encoder(unicode_csv_data): for line in unicode_csv_data: yield line.encode('utf-8') - + + def process_csv_file(election, f): reader = unicode_csv_reader(f) - + num_voters = 0 for voter in reader: - # bad line - if len(voter) < 1: - continue - - num_voters += 1 - voter_id = voter[0] - name = voter_id - email = voter_id - - if len(voter) > 1: - email = voter[1] - - if len(voter) > 2: - name = voter[2] - - # create the user - user = User.update_or_create(user_type='password', user_id=voter_id, info = {'password': helios_utils.random_string(10), 'email': email, 'name': name}) - user.save() - - # does voter for this user already exist - voter = Voter.get_by_election_and_user(election, user) - - # create the voter - if not voter: - voter_uuid = str(uuid.uuid1()) - voter = Voter(uuid= voter_uuid, voter_type = 'password', voter_id = voter_id, name = name, election = election) - voter.save() + # bad line + if len(voter) < 1: + continue + + num_voters += 1 + voter_id = voter[0] + name = voter_id + email = voter_id + + if len(voter) > 1: + email = voter[1] + + if len(voter) > 2: + name = voter[2] + + # create the user + user = User.update_or_create(user_type='password', user_id=voter_id, + info={'password': helios_utils.random_string(10), 'email': email, 'name': name}) + user.save() + + # does voter for this user already exist + voter = Voter.get_by_election_and_user(election, user) + + # create the voter + if not voter: + voter_uuid = str(uuid.uuid1()) + voter = Voter(uuid=voter_uuid, voter_type='password', voter_id=voter_id, name=name, election=election) + voter.save() return num_voters @@ -70,7 +76,7 @@ def process_csv_file(election, f): class Command(BaseCommand): args = '' help = 'load up voters from unprocessed voter files' - + def handle(self, *args, **options): # load up the voter files in order of last uploaded files_to_process = VoterFile.objects.filter(processing_started_at=None).order_by('uploaded_at') @@ -86,5 +92,3 @@ class Command(BaseCommand): file_to_process.processing_finished_at = datetime.datetime.utcnow() file_to_process.num_voters = num_voters file_to_process.save() - - diff --git a/helios/management/commands/verify_cast_votes.py b/helios/management/commands/verify_cast_votes.py index 5b7f39253615b82637937467db7fccf8b91c9e36..e2fab7186d318b4c67b500c345b93eb5d5d3dd79 100644 --- a/helios/management/commands/verify_cast_votes.py +++ b/helios/management/commands/verify_cast_votes.py @@ -6,12 +6,10 @@ ben@adida.net 2010-05-22 """ -from django.core.management.base import BaseCommand, CommandError -import csv, datetime +from django.core.management.base import BaseCommand -from helios import utils as helios_utils +from helios.models import CastVote -from helios.models import * def get_cast_vote_to_verify(): # fixme: add "select for update" functionality here diff --git a/helios/security.py b/helios/security.py index c0228213b3db56ff51a8e6e59c97b32ea38ce8c7..0e1861dcabfcdeb01f3d9e8f122e08f6914429a3 100644 --- a/helios/security.py +++ b/helios/security.py @@ -8,11 +8,11 @@ Ben Adida (ben@adida.net) from functools import update_wrapper from django.core.urlresolvers import reverse -from django.core.exceptions import * -from django.http import * +from django.core.exceptions import PermissionDenied +from django.http import Http404 from django.conf import settings -from models import * +from models import Voter, Trustee, Election from helios_auth.security import get_user from django.http import HttpResponseRedirect diff --git a/helios/stats_views.py b/helios/stats_views.py index 74c12f90feb511ed0aa5e13586013118c698c583..9c01a7f8d59f8f11e154d74f76c7960c074280f1 100644 --- a/helios/stats_views.py +++ b/helios/stats_views.py @@ -2,18 +2,19 @@ Helios stats views """ -from django.core.urlresolvers import reverse -from django.core.mail import send_mail -from django.core.paginator import Paginator -from django.http import * -from django.db import transaction -from django.db.models import * +import datetime -from security import * -from helios_auth.security import get_user, save_in_session_across_logouts -from view_utils import * +from django.core.paginator import Paginator +from django.core.urlresolvers import reverse +from django.db.models import Max, Count +from django.http import HttpResponseRedirect from helios import tasks +from helios.models import CastVote, Election +from helios_auth.security import get_user +from security import PermissionDenied +from view_utils import render_template + def require_admin(request): user = get_user(request) diff --git a/helios_auth/auth_systems/cas.py b/helios_auth/auth_systems/cas.py index 8202ad262712f527b8f8896b02b7a2b47b445917..6d0055f22485054ba677d1d2a783b3c18e899609 100644 --- a/helios_auth/auth_systems/cas.py +++ b/helios_auth/auth_systems/cas.py @@ -5,11 +5,14 @@ Some code borrowed from https://sp.princeton.edu/oit/sdp/CAS/Wiki%20Pages/Python.aspx """ -from django.http import * -from django.core.mail import send_mail +import datetime +import re +import urllib +import urllib2 +import uuid from django.conf import settings - -import sys, os, cgi, urllib, urllib2, re, uuid, datetime +from django.core.mail import send_mail +from django.http import HttpResponseRedirect from xml.etree import ElementTree CAS_EMAIL_DOMAIN = "princeton.edu" diff --git a/helios_auth/auth_systems/clever.py b/helios_auth/auth_systems/clever.py index dcd52d0e522b4bf2039a6d5752dca26090eefa9c..498951f8dbf0e3d60f2460c83d580be0b703bb64 100644 --- a/helios_auth/auth_systems/clever.py +++ b/helios_auth/auth_systems/clever.py @@ -3,14 +3,11 @@ Clever Authentication """ -from django.http import * -from django.core.mail import send_mail +import base64 +import httplib2 +import json +import urllib from django.conf import settings - -import httplib2,json,base64 - -import sys, os, cgi, urllib, urllib2, re - from oauth2client.client import OAuth2WebServerFlow, OAuth2Credentials # some parameters to indicate that status updating is not possible diff --git a/helios_auth/auth_systems/google.py b/helios_auth/auth_systems/google.py index 7caa32fc2f03e810f2f675b587d37ea01d41cf40..03419915600fe58636ce9e2098a0219075fa804d 100644 --- a/helios_auth/auth_systems/google.py +++ b/helios_auth/auth_systems/google.py @@ -3,14 +3,10 @@ Google Authentication """ -from django.http import * -from django.core.mail import send_mail +import httplib2 +import json from django.conf import settings - -import httplib2,json - -import sys, os, cgi, urllib, urllib2, re - +from django.core.mail import send_mail from oauth2client.client import OAuth2WebServerFlow # some parameters to indicate that status updating is not possible diff --git a/helios_auth/auth_systems/yahoo.py b/helios_auth/auth_systems/yahoo.py index 16bc0343cd40b78386a95fb0279c05c02b23f317..5131a19be520301ab4ea6643e88d97015d186d0f 100644 --- a/helios_auth/auth_systems/yahoo.py +++ b/helios_auth/auth_systems/yahoo.py @@ -3,12 +3,8 @@ Yahoo Authentication """ -from django.http import * -from django.core.mail import send_mail from django.conf import settings - -import sys, os, cgi, urllib, urllib2, re -from xml.etree import ElementTree +from django.core.mail import send_mail from openid import view_helpers