示例#1
0
文件: models.py 项目: Alapan/pollApp
    def addPoll(self, **kwargs):
        '''Add a Poll object to the memcache'''

        self.poll_dict['question'] = kwargs.get('question')
        for k,v in kwargs.iteritems():

            if 'choice' not in k continue
            if not v continue            

            choice_dict = {

                'option' : self.option,
                'text': v,
                'votes': 0,
            }
            self.choices.append(choice_dict)
            self.option += 1
        
        self.poll_dict['id'] = Poll.counter + 1
        self.poll_dict['choices'] = self.choices
        self.poll_dict['publish'] = kwargs.get('publish')

        set_value(self.poll_dict['id'],self.poll_dict)

        if self.poll_dict['publish'] == True:

            publish_poll(self.poll_dict['id'])
示例#2
0
文件: views.py 项目: Alapan/pollApp
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)
示例#3
0
文件: views.py 项目: Alapan/pollApp
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)
示例#4
0
文件: views.py 项目: Alapan/pollApp
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
示例#5
0
文件: views.py 项目: Alapan/pollApp
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)