Example #1
0
 def load_session(self):
     conn = pool.take()
     cursor = conn.cursor()
     cursor.execute("select data from session where uuid = %s",(self.uuid,))
     row = cursor.fetchone()
     if row == None:
         raise InvalidCookieException()
     self.data = loads(row[0])
     cursor.close()
     pool.give(conn)
Example #2
0
def delete(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """update user set deleted=true where id=%s""",
        (id,)
    )
    conn.commit()
    c.close()
    pool.give(conn)
Example #3
0
def update(id, name, email, password):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """update user set name=%s, email=%s, password=%s
        where id=%s and deleted=false""",
        (name, email, password, id)
    )
    conn.commit()
    c.close()
    pool.give(conn)
Example #4
0
 def save_session(self):
     if not self.changed:
         return
     conn = pool.take()
     cursor = conn.cursor()
     cursor.execute(
         "update session set data=%s where uuid = %s",
         (dumps(self.data,-1), self.uuid)
     )
     cursor.close()
     conn.commit()
     pool.give(conn)
Example #5
0
 def new_session(self):
     self.uuid = str(uuid4())
     self.data = dict()
     conn = pool.take()
     cursor = conn.cursor()
     cursor.execute(
         "insert into session (uuid, data) VALUES(%s,%s)",
         (self.uuid,dumps(self.data,-1))
     )
     cursor.close()
     conn.commit()
     pool.give(conn)
Example #6
0
def add_user(name, email, inst_id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """insert into user (name, email, password, institution_id)
        values(%s,%s,%s,%s)""",
        (name, email, _generate_password(), inst_id)
    )
    id = conn.insert_id()
    conn.commit()
    c.close()
    pool.give(conn)
    return id
Example #7
0
def update(id, name, email, phone, password):
    conn = pool.take()
    c = conn.cursor()
    try:
        c.execute(
            """update institution set name=%s, email=%s, phone=%s, password=%s
            where id=%s and deleted=false""",
            (name, email, phone, password, id)
        )
    finally:
        conn.commit()
        c.close()
        pool.give(conn)
Example #8
0
def id_exists(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select 1 from user where deleted=false and id=%s""",
        (id,)
    )
    conn.commit()
    try:
        return c.fetchone != None
    finally:
        c.close()
        pool.give(conn)
Example #9
0
def get_name(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select name
        from institution where id = %s and deleted=false""",
        (id,)
    )
    conn.commit()
    try:
        return c.fetchone()[0]
    finally:
        c.close()
        pool.give(conn)
Example #10
0
def get_image(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select image
        from user where id = %s and deleted=false""",
        (id,)
    )
    conn.commit()
    try:
        return c.fetchone()
    finally:
        c.close()
        pool.give(conn)
Example #11
0
def get_instid(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select institution_id
        from user where id = %s""",
        (id,)
    )
    conn.commit()
    try:
        return c.fetchone()[0]
    finally:
        c.close()
        pool.give(conn)
Example #12
0
def get_data(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select name, email, password
        from user where id = %s and deleted=false""",
        (id,)
    )
    conn.commit()
    try:
        return c.fetchone()
    finally:
        c.close()
        pool.give(conn)
Example #13
0
def get_frontpage_data(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """
        select name from user where id = %s
        """,
        (id,)
    )
    conn.commit()
    try:
        return c.fetchone()
    finally:
        c.close()
        pool.give(conn)
Example #14
0
def update_section(id, title, content):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """update documentation_section
        set title=%s, content=%s
        where id=%s
        and deleted=false""",
        (title, content, id)
    )
    try:
        conn.commit()
        return c.fetchone()
    finally:
        c.close()
        pool.give(conn)
Example #15
0
def get_list():
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select id, name, email, phone from institution where deleted=false"""
    )
    conn.commit()
    try:
        while True:
            row = c.fetchone()
            if row == None:
                break
            yield row
    finally:
        c.close()
        pool.give(conn)
Example #16
0
def login(email,password):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select id
        from user where email=%s and password=%s and deleted=false""",
        (email,password)
    )
    conn.commit()
    row = c.fetchone()
    c.close()
    pool.give(conn)
    if row == None:
        return False
    (id,) = row
    local.session["login_user"] = id
    return True
Example #17
0
def login(password):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select id
        from institution where password = %s and deleted=false""",
        (password,)
    )
    conn.commit()
    row = c.fetchone()
    c.close()
    pool.give(conn)
    if row == None:
        return False
    (id,) = row
    local.session["login_institution"] = id
    return True
Example #18
0
def get_document(id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select d.id, d.title, d.time_modified, u.name, u.email
        from documentation d, user u
        where
            u.id = d.user_id
        and d.id = %s""",
        (id,)
    )
    try:
        conn.commit()
        return c.fetchone()
    finally:
        c.close()
        pool.give(conn)
Example #19
0
def get_list_by_institution(inst_id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select id, name, email
        from user
        where institution_id=%s and deleted=false""",
        (inst_id,)
    )
    conn.commit()
    try:
        while True:
            row = c.fetchone()
            if row == None:
                break
            yield row
    finally:
        c.close()
        pool.give(conn)
Example #20
0
def get_list_by_user(user_id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select id, title, time_created, time_modified, 2
        from documentation
        where user_id=%s and deleted=false order by time_modified desc""",
        (user_id,)
    )
    conn.commit()
    try:
        while True:
            row = c.fetchone()
            if row == None:
                break
            yield row
    finally:
        c.close()
        pool.give(conn)
Example #21
0
def get_document_sections(documentation_id):
    conn = pool.take()
    c = conn.cursor()
    c.execute(
        """select id, title, content
        from documentation_section
        where
            documentation_id=%s
            and deleted=false
        order by `order`""",
        (documentation_id,)
    )
    conn.commit()
    try:
        while True:
            row = c.fetchone()
            if row == None:
                break
            yield row
    finally:
        c.close()
        pool.give(conn)