Example #1
0
 def user_vote(self, user):
     """Return copy of user's vote choices. Raises KeyError if none recorded."""
     packed_user_id = pack_user_id(user.get_user_id())
     
     if not self.votes.has_key(packed_user_id):
         raise KeyError
     
     return self.votes[packed_user_id][:]
Example #2
0
 def record_vote(self, user, choices):
     """Record a users vote. Choices is a list of choice indicies mapping
     to self.choices list. Assumes user access permissions are valid, but
     checks choices for validity.
     
     Raises ValueError if choices are invalid.
     Raises KeyError if user is not allowed to re-vote.
     
     """
     
     if not self.choices_valid(choices):
         raise ValueError
         
     packed_user_id = pack_user_id(user.get_user_id())
     
     if not self.voter_can_revise and self.votes.has_key(packed_user_id):
         raise KeyError
     
     self.votes[packed_user_id] = PersistentList(choices)
     self.__cached_tally = None
Example #3
0
 def has_voted(self, user):
     """Return True if user is in votes tree."""
     if not user:
         return False
     return self.votes.has_key(pack_user_id(user.get_user_id()))