def get_serialized_votes(self): # updated_post.votes is a StringListProperty. Each vote_str is inflated to a dictionary # that looks like: # {"vote_for": 1, # "user": {"fb_uid": "152343", # ...} # } logging.info("For question [%s], returning %d votes.", self.question, len(self.votes)) return [Vote.from_string_for_choosie_post(vote_str) for vote_str in self.votes]
def get_serialized_votes(self): # updated_post.votes is a StringListProperty. Each vote_str is inflated to a dictionary # that looks like: # {"vote_for": 1, # "user": {"fb_uid": "152343", # ...} # } logging.info('For question [%s], returning %d votes.', self.question, len(self.votes)) return [ Vote.from_string_for_choosie_post(vote_str) for vote_str in self.votes ]
def add_vote_to_post_internal(self, new_vote): logging.info("Adding vote.") # Before adding a new vote, remove any existing votes by the same user. for existing_vote_str in self.votes: # updated_post.votes is a StringListProperty. To make the comparison, # each vote is 'inflated' to a dictionary, and its user ID is compared to the new_vote's. existing_vote_dict = Vote.from_string_for_choosie_post(existing_vote_str, keep_shallow=True) if existing_vote_dict["user"]["fb_uid"] == new_vote.user_fb_id: self.votes.remove(existing_vote_str) break # updated_post.votes is a StringListProperty. We add the new vote as a string. self.votes.append(new_vote.to_string_for_choosie_post())
def add_vote_to_post_internal(self, new_vote): logging.info("Adding vote.") # Before adding a new vote, remove any existing votes by the same user. for existing_vote_str in self.votes: # updated_post.votes is a StringListProperty. To make the comparison, # each vote is 'inflated' to a dictionary, and its user ID is compared to the new_vote's. existing_vote_dict = Vote.from_string_for_choosie_post( existing_vote_str, keep_shallow=True) if existing_vote_dict["user"]["fb_uid"] == new_vote.user_fb_id: self.votes.remove(existing_vote_str) break # updated_post.votes is a StringListProperty. We add the new vote as a string. self.votes.append(new_vote.to_string_for_choosie_post())