def ShowMyShifts(self, username):
        username = (username,)
        mydb = mysql.connector.connect(host="localhost", user="******", password='******', database='flight_manager',
                                       auth_plugin='mysql_native_password')
        mycursor = mydb.cursor()
        query = """
         SELECT flight_manager.staffing.flight_date, flight_manager.staffing.flight_type, flight_manager.staffing.leader , shifts.notes
        FROM flight_manager.staffing join flight_manager.shifts 
        where flight_manager.staffing.flight_type = flight_manager.shifts.flight_type
        and flight_manager.staffing.flight_date = flight_manager.shifts.flight_date
        and personal_num= %s

        """
        mycursor.execute(query, username)
        results = mycursor.fetchall()
        mydb.commit()
        my_shifts = []
        for row in results:
            shift = Shift()
            shift.flight_date = str(row[0])
            shift.flight_type = str(row[1])
            shift.leader = str(row[2])
            shift.notes =  str(row[3])
            my_shifts.append(shift)
        return my_shifts
Esempio n. 2
0
    def myweek(self):
        today = datetime.today().strftime('%Y-%m-%d')
        mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net", user="******",
                                       password='******', database='heroku_947e29c06a5b4a3')

        mycursor = mydb.cursor()
        query = """SELECT *
    FROM   shifts left join staffing 
    on staffing.flight_date = shifts.flight_date
    and staffing.flight_type = shifts.flight_type
    WHERE  YEARWEEK(shifts.flight_date) =   YEARWEEK(curdate());
                                 """
        mycursor.execute(query, )
        results = mycursor.fetchall()
        mydb.commit()
        mycursor.close()
        shifts = []
        for row in results:
            shift = Shift()
            shift.flight_date = str(row[0])
            shift.flight_type = str(row[1]).capitalize()
            shift.notes = str(row[2]).capitalize()
            if shift.flight_date < today:
                shift.status = 'Done'
            else:
                shift.status = "Not Done"
            shifts.append(shift)
        return shifts