# HG changeset patch # User Paul Boddie # Date 1204405021 -3600 # Node ID 1657592ee6373fa317fa7a99c805f017b67a06f3 # Parent 2ad73c3e6ff02f61f5240e49beddc062caf018ce Tidied up the emitted HTML, removing unnecessary tables. diff -r 2ad73c3e6ff0 -r 1657592ee637 macros/VotingStars.py --- a/macros/VotingStars.py Sat Mar 01 21:45:56 2008 +0100 +++ b/macros/VotingStars.py Sat Mar 01 21:57:01 2008 +0100 @@ -66,11 +66,13 @@ return results def execute(macro, args): + fmt = macro.formatter + args = args.split(",") args = map(unicode.strip, args) if len(args) < 1: - return macro.formatter.rawHTML('
[[Vote: Insufficient macro arguments]]
') + return fmt.rawHTML('
[[Vote: Insufficient macro arguments]]
') pageName = args[0] voteName = pageName @@ -84,7 +86,7 @@ voter = request.user.name else: voter = '' - thisPage = macro.formatter.page + thisPage = fmt.page votes = loadVotes(thisPage, voteName) # votes are stored in a dictionary as {user: candidate} to avoid duplicate votes @@ -95,7 +97,7 @@ try: saveVotes(thisPage, voteName, votes) except: # XXX - return macro.formatter.rawHTML('
[[Vote: failed to store vote]]
') + return fmt.rawHTML('
[[Vote: failed to store vote]]
') # generate dictionary {candidate: numvotes} results = countVotes(votes) @@ -114,10 +116,10 @@ hasVoted = voter in votes # spit out votes table (as part of a form if the user hasn't voted yet) - html = '
' + html = [] if voter: - html += ''' + html.append('''
\n \n @@ -125,20 +127,22 @@ 'formname': voteName, 'url': thisPage.url(request), 'voteName': voteName, - } + } + ) btnstar = '\n' for i in range(1,6): if i <= average: - html += btnstar % {'isrc':src_litstar, 'form':voteName, 'value': i} + html.append(btnstar % {'isrc':src_litstar, 'form':voteName, 'value': i}) if i > average: - html += btnstar % {'isrc':src_unlitstar, 'form':voteName, 'value': i} + html.append(btnstar % {'isrc':src_unlitstar, 'form':voteName, 'value': i}) if average == 0: - html += ' No Rating' + html.append(' No Rating') #else: - # html += ' %(avg)s ' % { 'avg': average } - html += '
' + # html.append(' %(avg)s ' % { 'avg': average }) + html.append('') else: - html += 'You must be logged in to Rate.' + html.append('Please log in to vote.') - return macro.formatter.rawHTML(html) - + return fmt.rawHTML(''.join(html)) + +# vim: tabstop=4 expandtab shiftwidth=4