1.1 --- a/macros/VotingStars.py Sat Mar 01 21:45:56 2008 +0100
1.2 +++ b/macros/VotingStars.py Sat Mar 01 21:57:01 2008 +0100
1.3 @@ -66,11 +66,13 @@
1.4 return results
1.5
1.6 def execute(macro, args):
1.7 + fmt = macro.formatter
1.8 +
1.9 args = args.split(",")
1.10 args = map(unicode.strip, args)
1.11
1.12 if len(args) < 1:
1.13 - return macro.formatter.rawHTML('<pre>[[Vote: Insufficient macro arguments]]</pre>')
1.14 + return fmt.rawHTML('<pre>[[Vote: Insufficient macro arguments]]</pre>')
1.15
1.16 pageName = args[0]
1.17 voteName = pageName
1.18 @@ -84,7 +86,7 @@
1.19 voter = request.user.name
1.20 else:
1.21 voter = ''
1.22 - thisPage = macro.formatter.page
1.23 + thisPage = fmt.page
1.24 votes = loadVotes(thisPage, voteName)
1.25
1.26 # votes are stored in a dictionary as {user: candidate} to avoid duplicate votes
1.27 @@ -95,7 +97,7 @@
1.28 try:
1.29 saveVotes(thisPage, voteName, votes)
1.30 except: # XXX
1.31 - return macro.formatter.rawHTML('<a id="voteform"><pre>[[Vote: failed to store vote]]</pre>')
1.32 + return fmt.rawHTML('<pre>[[Vote: failed to store vote]]</pre>')
1.33
1.34 # generate dictionary {candidate: numvotes}
1.35 results = countVotes(votes)
1.36 @@ -114,10 +116,10 @@
1.37 hasVoted = voter in votes
1.38
1.39 # spit out votes table (as part of a form if the user hasn't voted yet)
1.40 - html = '<a id="voteform"><table class="votestars"><tr><td>'
1.41 + html = []
1.42
1.43 if voter:
1.44 - html += '''
1.45 + html.append('''
1.46 <form method="get" name="%(formname)s" action="%(url)s#voteform">\n
1.47 <input type="hidden" name="voteName" value="%(voteName)s">\n
1.48 <input type="hidden" name="vote" value="0">
1.49 @@ -125,20 +127,22 @@
1.50 'formname': voteName,
1.51 'url': thisPage.url(request),
1.52 'voteName': voteName,
1.53 - }
1.54 + }
1.55 + )
1.56 btnstar = '<input type="image" src="%(isrc)s" OnClick="document.%(form)s.vote.value=%(value)s">\n'
1.57 for i in range(1,6):
1.58 if i <= average:
1.59 - html += btnstar % {'isrc':src_litstar, 'form':voteName, 'value': i}
1.60 + html.append(btnstar % {'isrc':src_litstar, 'form':voteName, 'value': i})
1.61 if i > average:
1.62 - html += btnstar % {'isrc':src_unlitstar, 'form':voteName, 'value': i}
1.63 + html.append(btnstar % {'isrc':src_unlitstar, 'form':voteName, 'value': i})
1.64 if average == 0:
1.65 - html += ' No Rating'
1.66 + html.append(' No Rating')
1.67 #else:
1.68 - # html += ' %(avg)s ' % { 'avg': average }
1.69 - html += '</form></td></tr></table></a>'
1.70 + # html.append(' %(avg)s ' % { 'avg': average })
1.71 + html.append('</form>')
1.72 else:
1.73 - html += 'You must be logged in to Rate.</td></tr></table></a>'
1.74 + html.append('Please log in to vote.')
1.75
1.76 - return macro.formatter.rawHTML(html)
1.77 -
1.78 + return fmt.rawHTML(''.join(html))
1.79 +
1.80 +# vim: tabstop=4 expandtab shiftwidth=4