예제 #1
0
def validate(firstname, lastname, email, passwd):
    c = d.cursor()
    statement = '''select staff_id from Staff
        where first_name ="%s" and last_name ="%s";'''\
        % (firstname, lastname)
    try:
        c.execute(statement)
        rows = c.fetchall()
        for row in rows:
            staff_id = int(row[0])
        print staff_id
        statement = '''select count(ref_staff_id) from
            Login where ref_staff_id = "%s";''' % (staff_id)
        c.execute(statement)
        rows = c.fetchall()
        for row in rows:
            num = int(row[0])
        if num == 0:
            passwd = generate_password_hash(passwd)
            statement = '''INSERT INTO Login VALUES
                ("%s","%s","%s");''' % (email, passwd, staff_id)
            c.execute(statement)
            d.commit()
            return True
        return False
    except:
        return False
예제 #2
0
def create_strategy(ref_type, area, description, days):
    try:
        c = d.cursor()
        
        statement = '''INSERT INTO Strategy(ref_type_id, area, description)
        VALUES(%s, "%s", "%s");''' % (ref_type, area, description)
        c.execute(statement)
        d.commit()
        statement = '''SELECT strategy_id FROM Strategy
        WHERE area = "%s" and ref_type_id = %s;''' % (area, ref_type)
        c.execute(statement)
        rows = c.fetchall()
        for row in rows:
            areaid = row[0]
        print "areaid"
        print areaid
        print ref_type
        print days
        for day in days:
            statement = '''INSERT INTO Rota (ref_strategy_id,
            day) VALUES
            (%s, %s);''' % (areaid, day)
            c.execute(statement)
            d.commit()
            print "rota added"
        return True
    except:
        return False
예제 #3
0
def set_notes(u_id, notes):
    c = d.cursor()
    statement = '''delete from Notes where
    Ref_Staff_id = %s;''' % (u_id)
    c.execute(statement)
    
    statement = '''INSERT INTO Notes VALUES (%s, CURRENT_TIMESTAMP,
    "%s");''' % (u_id, notes)
    c.execute(statement)
    d.commit()
예제 #4
0
def create_check(ref_type, area, comment, ref_staff_id):
    print ref_type
    print area
    print comment
    print int(ref_staff_id)
    try:
        c = d.cursor()
        statement = '''SELECT Strategy_Id from Strategy WHERE
        Area = "%s" and ref_type_id= %s;''' % (area, ref_type)
        c.execute(statement)
        rows = c.fetchall()
        for row in rows:
            ref_area_id = int(row[0])
            print ref_area_id
        statement = '''INSERT INTO Checks(Ref_Type_id, ref_strategy_id,
        ref_staff_id, comment, complete) VALUES (%s, %s, %s, "%s", True);''' \
        % (ref_type, ref_area_id, int(ref_staff_id), comment)
        c.execute(statement)
        d.commit()
        return True
    except:
        return False