Changeset 6

Show
Ignore:
Timestamp:
11/29/04 09:22:06 (4 years ago)
Author:
athomas
Message:

Allowed multiple anonymous votes in PollMacro.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/macros/Poll.py

    r5 r6  
    4040        html += "<input type='hidden' name='poll' value='%s'>\n" % self.label 
    4141 
    42         user = hdf.getValue("trac.authname", "") 
     42        user = hdf.getValue("trac.authname", "anonymous") 
    4343        poll = hdf.getValue("args.poll", "")  
    44         pollvalue = int(hdf.getValue("args.pollvalue", "")) 
     44        pollvalue = int(hdf.getValue("args.pollvalue", "0")) 
    4545 
    4646        error = "" 
     
    4949        if poll == self.label: 
    5050            for i, option in enumerate(self.options): 
    51                 if user in option[1] and pollvalue != i: 
    52                     error = "<div class='system-message'><strong>Changed your vote.</strong></div>\n" 
    53                     del(self.options[i][1][user]) 
     51                if user in option[1]: 
     52                    if pollvalue != i: 
     53                        error = "<div class='system-message'><strong>Changed your vote.</strong></div>\n" 
     54                    if user != "anonymous": 
     55                        del(self.options[i][1][user]) 
    5456                    commit = 1 
    5557 
     
    5860            checked = "" 
    5961            if poll == self.label and pollvalue == i: 
    60                 self.options[i][1][user] = 1 
     62                if self.options[i][1].has_key(user): 
     63                    self.options[i][1][user] += 1 
     64                else: 
     65                    self.options[i][1][user] = 1 
    6166                commit = 1 
    6267            if user in self.options[i][1]: 
     
    6469            voters = "" 
    6570            if len(option[1]): 
    66                 voters = " <strong>(%s)</strong>" % ", ".join(option[1].keys()) 
     71                voters = "<strong>" 
     72                voter_list = [] 
     73                for voter in option[1].keys(): 
     74                    if option[1][voter] > 1: 
     75                        voter_list.append('%s &times; %i' % (voter, option[1][voter])) 
     76                    else: 
     77                        voter_list.append(voter) 
     78                voters = " <strong>(%s)</strong>" % ", ".join(voter_list) 
    6779            html += "<input type='radio' name='pollvalue' value='%i'%s> %s%s<br>\n" % (i, checked, option[0], voters) 
    6880        html += "<input type='submit' value='Vote'>\n"