Exemple #1
0
    def get_open_polls():
        time = datetime.now()
        datenow = date(time.year, time.month, time.day)
        curs.execute("""SELECT * 
                        FROM poll
                        WHERE ends>'%s'""" % (datenow))
        p = curs.fetchone()
        polls = []
        while not p == None:
            curs.execute("""SELECT choice_value 
                        FROM choice 
                        WHERE poll_id=%s""" % (int(p['poll_id'])))
            result_choices = curs.fetchall()

            choices = []
            for choice in result_choices:
                choices.append(choice['choice_value'])

            public_key = str_to_key(p['public_key'])

            poll = Poll(int(p['poll_id']), p['name'],
                        p['description'], p['created'], p['ends'],
                        int(p['base']), int(p['state']), public_key, choices,
                        p['private_key'])

            polls.append(poll)
            p = curs.fetchone()
        return polls
Exemple #2
0
 def get_open_polls():
     time = datetime.now()
     datenow = date(time.year, time.month, time.day)
     curs.execute("""SELECT * 
                     FROM poll
                     WHERE ends>'%s'"""
                     % (datenow))
     p = curs.fetchone()
     polls = []
     while not p == None:
         curs.execute("""SELECT choice_value 
                     FROM choice 
                     WHERE poll_id=%s""" 
                     % (int(p['poll_id'])))
         result_choices = curs.fetchall()
     
         choices = []
         for choice in result_choices:
             choices.append(choice['choice_value'])
             
         public_key = str_to_key(p['public_key'])
         
         poll = Poll(int(p['poll_id']), p['name'], p['description'], p['created'], p['ends'], 
                 int(p['base']), int(p['state']), public_key, choices, p['private_key'])
         
         polls.append(poll)
         p = curs.fetchone()
     return polls
Exemple #3
0
    def get_by_id(poll_id):
        curs.execute("""SELECT * 
                        FROM poll 
                        WHERE poll_id=%s""" % (poll_id))
        p = curs.fetchone()

        if p == None:
            return 0

        curs.execute("""SELECT choice_value 
                        FROM choice 
                        WHERE poll_id=%s""" % (poll_id))
        result_choices = curs.fetchall()

        choices = []
        for choice in result_choices:
            choices.append(choice['choice_value'])
        public_key = str_to_key(p['public_key'])

        return Poll(int(p['poll_id']), p['name'],
                    p['description'], p['created'], p['ends'], int(p['base']),
                    int(p['state']), public_key, choices, p['private_key'])
Exemple #4
0
 def get_by_id(poll_id):        
     curs.execute("""SELECT * 
                     FROM poll 
                     WHERE poll_id=%s"""
                     % (poll_id))
     p = curs.fetchone()
     
     if p == None:
         return 0
     
     curs.execute("""SELECT choice_value 
                     FROM choice 
                     WHERE poll_id=%s""" 
                     % (poll_id))
     result_choices = curs.fetchall()
     
     choices = []
     for choice in result_choices:
         choices.append(choice['choice_value'])
     public_key = str_to_key(p['public_key'])
     
     return Poll(int(p['poll_id']), p['name'], p['description'], p['created'], p['ends'], 
                 int(p['base']), int(p['state']), public_key, choices, p['private_key'])