1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/get_votes.py Mon Mar 03 00:47:50 2008 +0100
1.3 @@ -0,0 +1,61 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +try:
1.7 + import cPickle as pickle
1.8 +except ImportError:
1.9 + import pickle
1.10 +
1.11 +import os
1.12 +import sys
1.13 +
1.14 +def compare_results(a, b):
1.15 + return cmp(a[1], b[1])
1.16 +
1.17 +if __name__ == "__main__":
1.18 + wiki = sys.argv[1]
1.19 + if len(sys.argv) > 2:
1.20 + correction = int(sys.argv[2])
1.21 + else:
1.22 + correction = 0
1.23 +
1.24 + combined = {}
1.25 +
1.26 + print "Looking for polls under", wiki
1.27 +
1.28 + for dirpath, dirnames, filenames in os.walk(wiki):
1.29 + if os.path.split(dirpath)[-1] == "poll":
1.30 + for filename in filenames:
1.31 + pathname = os.path.join(dirpath, filename)
1.32 + f = open(pathname, "rb")
1.33 + try:
1.34 + combined[filename] = pickle.load(f)
1.35 + finally:
1.36 + f.close()
1.37 +
1.38 + averages = []
1.39 + totals = []
1.40 +
1.41 + print
1.42 + print "Results:"
1.43 + for poll, results in combined.items():
1.44 + print poll, results
1.45 + values = results.values()
1.46 + len_values = len(values)
1.47 + sum_values = sum(values) + len_values * correction
1.48 + averages.append((poll, float(sum_values) / len_values))
1.49 + totals.append((poll, sum_values))
1.50 +
1.51 + averages.sort(compare_results, reverse=1)
1.52 + totals.sort(compare_results, reverse=1)
1.53 +
1.54 + print
1.55 + print "Results by averages:"
1.56 + for poll, result in averages:
1.57 + print "%-15s%d" % (poll, result)
1.58 +
1.59 + print
1.60 + print "Results by totals:"
1.61 + for poll, result in totals:
1.62 + print "%-15s%d" % (poll, result)
1.63 +
1.64 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/macros/VoteRecorder.py Sun Mar 02 18:31:45 2008 +0100
2.2 +++ b/macros/VoteRecorder.py Mon Mar 03 00:47:50 2008 +0100
2.3 @@ -11,6 +11,7 @@
2.4
2.5 from MoinMoin.util import filesys, lock
2.6 from MoinMoin import wikiutil
2.7 +import MoinMoin.user
2.8 import os
2.9 try:
2.10 import cPickle as pickle
2.11 @@ -88,17 +89,24 @@
2.12 output.append(fmt.sysmsg(on=0))
2.13 return ''.join(output)
2.14
2.15 - # Show a message if the user is not logged in.
2.16 + # Check for extra arguments.
2.17 + # NOTE: This is only adequate protection if an ACL stops untrusted users
2.18 + # NOTE: from editing the page. This should actually query the ACL in order
2.19 + # NOTE: to prevent such exploits.
2.20 +
2.21 + public = "public" in args[1:]
2.22
2.23 # Get the user, if known.
2.24 + # Show a message if the user is not logged in and the poll is not public.
2.25
2.26 - if not request.user.valid:
2.27 + if not public and not request.user.valid:
2.28 output.append(fmt.emphasis(on=1))
2.29 output.append(fmt.text("Please log in to vote!"))
2.30 output.append(fmt.emphasis(on=0))
2.31 return ''.join(output)
2.32
2.33 - username = request.user.name
2.34 + username = MoinMoin.user.getUserIdentification(request)
2.35 + #username = request.user.valid and request.user.name or request.user.host()
2.36 votes = get_all_votes(page, poll_name)
2.37
2.38 # Handle any vote.