You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2015/03/23 10:57:27 UTC
svn commit: r1668579 - in /steve/trunk/pysteve/www/cgi-bin: lib/election.py
rest_admin.py
Author: humbedooh
Date: Mon Mar 23 09:57:26 2015
New Revision: 1668579
URL: http://svn.apache.org/r1668579
Log:
move election creation into election.py
Modified:
steve/trunk/pysteve/www/cgi-bin/lib/election.py
steve/trunk/pysteve/www/cgi-bin/rest_admin.py
Modified: steve/trunk/pysteve/www/cgi-bin/lib/election.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/lib/election.py?rev=1668579&r1=1668578&r2=1668579&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/lib/election.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/lib/election.py Mon Mar 23 09:57:26 2015
@@ -18,6 +18,7 @@ import hashlib
import json
import os
import random
+import time
from __main__ import homedir, config
@@ -73,6 +74,24 @@ def getVotes(electionID, issueID):
issuedata = json.loads(data)
return issuedata
+def createElection(eid, title, owner, monitors, starts, ends, isopen):
+ elpath = os.path.join(homedir, "issues", eid)
+ os.mkdir(elpath)
+ with open(elpath + "/basedata.json", "w") as f:
+ f.write(json.dumps({
+ 'title': title,
+ 'owner': owner,
+ 'monitors': monitors,
+ 'starts': starts,
+ 'ends': ends,
+ 'hash': hashlib.sha512("%f-stv-%s" % (time.time(), os.environ['REMOTE_ADDR'])).hexdigest(),
+ 'open': isopen
+ }))
+ f.close()
+ with open(elpath + "/voters.json", "w") as f:
+ f.write("{}")
+ f.close()
+
def listIssues(election):
"List all issues in an election"
Modified: steve/trunk/pysteve/www/cgi-bin/rest_admin.py
URL: http://svn.apache.org/viewvc/steve/trunk/pysteve/www/cgi-bin/rest_admin.py?rev=1668579&r1=1668578&r2=1668579&view=diff
==============================================================================
--- steve/trunk/pysteve/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pysteve/www/cgi-bin/rest_admin.py Mon Mar 23 09:57:26 2015
@@ -86,7 +86,7 @@ else:
elif action == "setup":
if karma >= 5: # karma of 5 required to set up an election base
if electionID:
- if os.path.isdir(os.path.join(homedir, "issues", electionID)):
+ if election.exists(electionID):
response.respond(403, {'message': "Election already exists!"})
else:
try:
@@ -97,22 +97,15 @@ else:
raise Exception("Required fields missing: %s" % ", ".join(xr))
else:
xr.pop(0)
- elpath = os.path.join(homedir, "issues", electionID)
- os.mkdir(elpath)
- with open(elpath + "/basedata.json", "w") as f:
- f.write(json.dumps({
- 'title': form.getvalue('title'),
- 'owner': form.getvalue('owner'),
- 'monitors': [x.strip() for x in form.getvalue('monitors').split(",")],
- 'starts': form.getvalue('starts'),
- 'ends': form.getvalue('ends'),
- 'hash': hashlib.sha512("%f-stv-%s" % (time.time(), os.environ['REMOTE_ADDR'])).hexdigest(),
- 'open': form.getvalue('open')
- }))
- f.close()
- with open(elpath + "/voters.json", "w") as f:
- f.write("{}")
- f.close()
+ election.createElection(
+ electionID,
+ form.getvalue('title'),
+ form.getvalue('owner'),
+ [x.strip() for x in form.getvalue('monitors').split(",")],
+ form.getvalue('starts'),
+ form.getvalue('ends'),
+ form.getvalue('open')
+ )
response.respond(201, {'message': 'Created!', 'id': electionID})
except Exception as err:
response.respond(500, {'message': "Could not create electionID: %s" % err})