Author: humbedooh
Date: Sun Mar 22 09:23:22 2015
New Revision: 1668346
URL: http://svn.apache.org/r1668346
Log:
add a 'list' call for listing elections owned by $user
Modified:
steve/trunk/pytest/www/cgi-bin/rest_admin.py
Modified: steve/trunk/pytest/www/cgi-bin/rest_admin.py
URL:
http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_admin.py?rev=1668346&r1=1668345&r2=1668346&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Sun Mar 22 09:23:22 2015
@@ -61,9 +61,27 @@ else:
action = l[0]
election = l[1] if len(l) > 1 else None
-
+ # List all existing/previous elections?
+ if action == "list":
+ output = []
+ path = os.path.join(homedir, "issues")
+ elections = [ f for f in listdir(path) if
os.path.isdir(os.path.join(path,f))]
+ for election in elections:
+ try:
+ elpath = os.path.join(homedir, "issues", election)
+ with open(elpath + "/basedata.json", "r") as f:
+ basedata = json.loads(f.read())
+ f.close()
+ if 'hash' in basedata:
+ del basedata['hash']
+ basedata['id'] = election
+ if karma >= 5 or ('owner' in basedata and
basedata['owner'] == whoami):
+ output.append(basedata)
+ except:
+ pass
+ response.respond(200, { 'elections': output})
# Set up new election?
- if action == "setup":
+ elif action == "setup":
if karma >= 5: # karma of 5 required to set up an election base
if election:
if os.path.isdir(os.path.join(homedir, "issues",
election)):