Exemplo n.º 1
0
def delete_votation_by_id(votation_id):
    """Delete the votation from the DB"""
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("delete from votation where votation_id = ?", (votation_id,))
    c.close()
    conn.close()
Exemplo n.º 2
0
def delete_dto(o):
    """delete guarantor_dto """   
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("delete from guarantor where votation_id = ? and user_id = ?",(o.votation_id, o.u.user_id) )
    c.close()
    conn.close()
Exemplo n.º 3
0
def set_passphrase_ok(user_id,votation_id):
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("""update guarantor set passphrase_ok = 1 where 
                    votation_id = ? and
                    user_id = ?""",(votation_id, user_id) )
    c.close()
    conn.close()
Exemplo n.º 4
0
def delete_dto(o):
    """Delete the candidate_dto from the DB"""
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("delete from candidate where votation_id = ? and user_id = ?",
              (o.votation_id, o.u.user_id))
    c.close()
    conn.close()
Exemplo n.º 5
0
def insert_user_dto(u):
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("insert into voting_user(user_name,pass_word) values(?,?)",
              (u.user_name, u.pass_word))
    u.user_id = c.lastrowid
    c.close()
    conn.close()
Exemplo n.º 6
0
def insert_dto(o):
    """Insert the guarantor_dto into the DB"""   
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("""insert into guarantor(
                    votation_id, 
                    user_id, hash_ok, passphrase_ok,order_n) 
                    select ?,?,0,0,count(*)+1 from guarantor a where a.votation_id = ?""",(o.votation_id, o.u.user_id,o.votation_id) )
    c.close()
    conn.close()
Exemplo n.º 7
0
def insert_dto(o):
    """Insert the candidate_dto into the DB"""
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute(
        """insert into candidate(
                    votation_id, 
                    user_id, passphrase_ok,order_n) select ?,?,0,count(*)+1 from candidate where votation_id = ?""",
        (o.votation_id, o.u.user_id, o.votation_id))
    c.close()
    conn.close()
Exemplo n.º 8
0
def check_for_duplicate(o):
    """Returns true/false"""
    result = False
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select 1 from guarantor where votation_id = ? and user_id=?", (o.votation_id,o.u.user_id) )
    row = c.fetchone()
    if row:
        result = True
    c.close()
    conn.close()
    return result
Exemplo n.º 9
0
def load_guarantor(votation_id, user_id):
    """Returns a guarantor_dto"""
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select * from guarantor c where c.votation_id = ? and user_id = ?", (votation_id,user_id) )
    row = c.fetchone()
    g = guarantor_dto()
    g.votation_id = row['votation_id'] 
    g.hash_ok = row['hash_ok'] 
    g.passphrase_ok = row['passphrase_ok'] 
    g.order_n = row['order_n'] 
    g.u = user.load_user_by_id(row['user_id'])
    c.close()
    conn.close()
    return g
Exemplo n.º 10
0
def load_user_by_id(user_id):
    """Returns a user_dto object or None"""
    u = None
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select * from voting_user where user_id = ?", (user_id, ))
    row = c.fetchone()
    if row:
        u = user_dto()
        u.user_id = row['user_id']
        u.user_name = row['user_name']
        u.pass_word = row['pass_word']
    c.close()
    conn.close()
    return u
Exemplo n.º 11
0
def load_candidate(votation_id, user_id):
    """Returns a candidate_dto """
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute(
        "select * from candidate c where c.votation_id = ? and c.user_id = ?",
        (votation_id, user_id))
    row = c.fetchone()
    o = candidate_dto()
    o.votation_id = row['votation_id']
    o.passphrase_ok = row['passphrase_ok']
    o.order_n = row['order_n']
    o.u = user.load_user_by_id(row['user_id'])
    c.close()
    conn.close()
    return o
Exemplo n.º 12
0
def load_guarantor_by_votation(votation_id):
    """Returns a guarantor_dto array"""
    ar = []
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select * from guarantor c where c.votation_id = ? order by order_n", (votation_id,) )
    row = c.fetchone()
    while row:
        g = guarantor_dto()
        g.votation_id = row['votation_id'] 
        g.hash_ok = row['hash_ok'] 
        g.passphrase_ok = row['passphrase_ok'] 
        g.order_n = row['order_n'] 
        g.u = user.load_user_by_id(row['user_id'])
        ar.append(g)
        row = c.fetchone()
    c.close()
    conn.close()
    return ar
Exemplo n.º 13
0
def load_votation_by_id(votation_id):
    """Returns a votation_dto object or None"""
    v = None
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select * from votation where votation_id = ?", (votation_id,))
    row = c.fetchone()
    if row:
        v = votation_dto()
        v.votation_id = row['votation_id']
        v.promoter_user = user.load_user_by_id( row['promoter_user_id'] )
        v.votation_description = row['votation_description']
        v.begin_date = row['begin_date']
        v.end_date = row['end_date']
        v.votation_type = row['votation_type']
        v.votation_status = row['votation_status']
    c.close()
    conn.close()
    return v
Exemplo n.º 14
0
def insert_votation_dto(v):
    """Insert the votation_dto into the DB"""
    result = True
    #try:
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("""insert into votation(
                    promoter_user_id, 
                    votation_description, 
                    begin_date, 
                    end_date, 
                    votation_type,
                    votation_status) values(?,?,?,?,?,?)""", (v.promoter_user.user_id, v.votation_description, v.begin_date, v.end_date, v.votation_type, v.votation_status))
    v.votation_id = c.lastrowid
    c.close()
    conn.close()
    #except sqlite3.IntegrityError::
    #    print(e)
    #    result = False
    return result
Exemplo n.º 15
0
def load_candidate_by_votation(votation_id):
    """Returns a candidate_dto array"""
    ar = []
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute(
        "select * from candidate c where c.votation_id = ? order by order_n",
        (votation_id, ))
    row = c.fetchone()
    while row:
        o = candidate_dto()
        o.votation_id = row['votation_id']
        o.passphrase_ok = row['passphrase_ok']
        o.order_n = row['order_n']
        o.u = user.load_user_by_id(row['user_id'])
        ar.append(o)
        row = c.fetchone()
    c.close()
    conn.close()
    return ar
Exemplo n.º 16
0
def load_user_by_username(user_name):
    u = None
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select * from voting_user where user_name = ?", (user_name, ))
    row = c.fetchone()
    if row:
        u = user_dto()
        u.user_id = row['user_id']
        u.user_name = row['user_name']
        u.pass_word = row['pass_word']
    c.close()
    conn.close()
    if config.AUTH_METHOD == 'ldap':
        if u == None:
            u = user_dto()
            u.user_name = user_name
            u.pass_word = 'ldap user'
            insert_user_dto(u)
    return u
Exemplo n.º 17
0
def load_votations():
    """Returns a votation_dto array"""
    ar = []
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("select * from votation")
    row = c.fetchone()
    while row:
        v = votation_dto()
        v.votation_id = row['votation_id']
        v.promoter_user = user.load_user_by_id( row['promoter_user_id'] )
        v.votation_description = row['votation_description']
        v.begin_date = row['begin_date']
        v.end_date = row['end_date']
        v.votation_type = row['votation_type']
        v.votation_status = row['votation_status']
        ar.append(v)
        row = c.fetchone()
    c.close()
    conn.close()
    return ar
Exemplo n.º 18
0
def update_status(votation_id, new_status):
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("update votation set votation_status=? where votation_id = ?", (new_status,votation_id,))
    c.close()
    conn.close()
Exemplo n.º 19
0
def delete_user_by_username(user_name):
    conn = dbmanager.get_connection()
    c = conn.cursor()
    c.execute("delete from voting_user where user_name = ?", (user_name, ))
    c.close()
    conn.close()