# HG changeset patch # User Paul Boddie # Date 1204501670 -3600 # Node ID 284f8ddc5f2d1d13351408f074ad738f00b095ef # Parent 6f7d92be6061a3ac6e2cc9343d146f637117d41d Added a public voting option to the VoteRecorder macro. Added a script which can summarise the voting in a Wiki. diff -r 6f7d92be6061 -r 284f8ddc5f2d get_votes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/get_votes.py Mon Mar 03 00:47:50 2008 +0100 @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +try: + import cPickle as pickle +except ImportError: + import pickle + +import os +import sys + +def compare_results(a, b): + return cmp(a[1], b[1]) + +if __name__ == "__main__": + wiki = sys.argv[1] + if len(sys.argv) > 2: + correction = int(sys.argv[2]) + else: + correction = 0 + + combined = {} + + print "Looking for polls under", wiki + + for dirpath, dirnames, filenames in os.walk(wiki): + if os.path.split(dirpath)[-1] == "poll": + for filename in filenames: + pathname = os.path.join(dirpath, filename) + f = open(pathname, "rb") + try: + combined[filename] = pickle.load(f) + finally: + f.close() + + averages = [] + totals = [] + + print + print "Results:" + for poll, results in combined.items(): + print poll, results + values = results.values() + len_values = len(values) + sum_values = sum(values) + len_values * correction + averages.append((poll, float(sum_values) / len_values)) + totals.append((poll, sum_values)) + + averages.sort(compare_results, reverse=1) + totals.sort(compare_results, reverse=1) + + print + print "Results by averages:" + for poll, result in averages: + print "%-15s%d" % (poll, result) + + print + print "Results by totals:" + for poll, result in totals: + print "%-15s%d" % (poll, result) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 6f7d92be6061 -r 284f8ddc5f2d macros/VoteRecorder.py --- a/macros/VoteRecorder.py Sun Mar 02 18:31:45 2008 +0100 +++ b/macros/VoteRecorder.py Mon Mar 03 00:47:50 2008 +0100 @@ -11,6 +11,7 @@ from MoinMoin.util import filesys, lock from MoinMoin import wikiutil +import MoinMoin.user import os try: import cPickle as pickle @@ -88,17 +89,24 @@ output.append(fmt.sysmsg(on=0)) return ''.join(output) - # Show a message if the user is not logged in. + # Check for extra arguments. + # NOTE: This is only adequate protection if an ACL stops untrusted users + # NOTE: from editing the page. This should actually query the ACL in order + # NOTE: to prevent such exploits. + + public = "public" in args[1:] # Get the user, if known. + # Show a message if the user is not logged in and the poll is not public. - if not request.user.valid: + if not public and not request.user.valid: output.append(fmt.emphasis(on=1)) output.append(fmt.text("Please log in to vote!")) output.append(fmt.emphasis(on=0)) return ''.join(output) - username = request.user.name + username = MoinMoin.user.getUserIdentification(request) + #username = request.user.valid and request.user.name or request.user.host() votes = get_all_votes(page, poll_name) # Handle any vote.