def get_publishedPolls '''Retrieve list of published polls''' poll_list = [] published_polls = get_value('published_polls') if not published_polls: set_value('published_polls',[]) # p is a poll key for p in published_polls: poll_list = get_value(p) polls.append(poll_list)
def publish_poll(key): '''Add poll with published=True to list of published polls''' published_polls = get_value('published_polls') if not published_polls: set_value('published_polls',[]) if key not in published_polls: published_polls.append(key) set_value('published_polls', published_polls)
def unpublish_poll(key): '''Remove poll with published=False from list of published polls''' published_polls = get_value('published_polls') if not published_polls: set_value('published_polls',[]) if key in published_polls: published_polls.remove(key) set_value('published_polls',published_polls)
def cast_vote(question_key, choice): '''Sets vote of selected choice of question to 1''' poll = get_value(question_key) for d in poll['choices']: if d['options'] == choice: d['votes'] += 1 set_value(question_key, poll) return poll
def get_poll(key): '''Retrieve a single poll''' poll = get_value(key) return poll