Exemple #1
0
    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'])
Exemple #2
0
def edit_poll(**kwargs):
    choices_arr = []
    poll = get_poll(str(kwargs.get('slug')))
    poll_dict = {}
    poll_dict['question'] = kwargs.get('question')
    for k, v in kwargs.items():
        if 'choice' not in k: continue
        this_choice = [
            c for c in poll.get('choices')
            if int(k.strip('choice')) == c.get('id')
        ]
        if not len(this_choice):
            return False
        else:
            this_choice = this_choice[0]
        choice_dict = {
            'id': this_choice.get('id'),
            'text': v,
            'value': this_choice.get('value'),
        }
        choices_arr.append(choice_dict)
    slug = str(kwargs.get('slug'))
    poll_dict['slug'] = slug
    poll_dict['choices'] = choices_arr
    set_value(slug, poll_dict)
    if kwargs.get('publish'):
        publish_poll(slug)
    else:
        unpublish_poll(slug)
    return poll_dict
Exemple #3
0
def edit_poll(**kwargs):
    choices_arr = []
    poll = get_poll(str(kwargs.get('slug')))
    poll_dict = {}
    poll_dict['question'] = kwargs.get('question')
    for k,v in kwargs.items():
        if 'choice' not in k: continue
        this_choice = [c for c in poll.get('choices') if int(k.strip('choice')) == c.get('id')]
        if not len(this_choice):
            return False
        else:
            this_choice = this_choice[0]
        choice_dict = {
            'id': this_choice.get('id'),
            'text': v,
            'value': this_choice.get('value'),
        }
        choices_arr.append(choice_dict)
    slug = str(kwargs.get('slug'))
    poll_dict['slug'] = slug
    poll_dict['choices'] = choices_arr
    set_value(slug,poll_dict)
    if kwargs.get('publish'):
        publish_poll(slug)
    else:
        unpublish_poll(slug)
    return poll_dict
Exemple #4
0
def add_poll(**kwargs):
    choices_arr = []
    count = 1
    poll_dict = {}
    poll_dict['question'] = kwargs.get('question')
    for k, v in kwargs.items():
        if 'choice' not in k: continue
        if not v: continue
        choice_dict = {'id': count, 'text': v, 'value': 0}
        choices_arr.append(choice_dict)
        count += 1
    slug = slugify(kwargs.get('question'))
    poll_dict['slug'] = slug
    poll_dict['choices'] = choices_arr
    set_value(slug, poll_dict)
    if kwargs.get('publish'):
        publish_poll(slug)
Exemple #5
0
def add_poll(**kwargs):
    choices_arr = []
    count = 1
    poll_dict = {}
    poll_dict['question'] = kwargs.get('question')
    for k,v in kwargs.items():
        if 'choice' not in k: continue
        if not v: continue
        choice_dict = {
            'id': count,
            'text': v,
            'value': 0
        }
        choices_arr.append(choice_dict)
        count += 1
    slug = slugify(kwargs.get('question')) 
    poll_dict['slug'] = slug
    poll_dict['choices'] = choices_arr
    set_value(slug,poll_dict)
    if kwargs.get('publish'):
        publish_poll(slug)