예제 #1
0
def managerstaffing(request):
    shift_manager = ShiftManager()
    usernamequery = (str(request.user), )
    name = shift_manager.getname(usernamequery)
    shifts = Shift()
    all_shifts = shifts.ShowAllShifts()
    all_staffing = shifts.ShowAllStaffing()
    if request.method == 'POST':
        form = AddShiftForm(request.POST)
        if form.is_valid():
            flight_type = form.cleaned_data['flight_type']
            flight_date = form.cleaned_data['flight_date']
            notes = form.cleaned_data['notes']
            shift_manager.insertshift(flight_type, flight_date, notes)
            template = 'base/staffingshow.html'
            args = {
                'form': form,
                'flight_type': flight_type,
                'flight_date': flight_date
            }
    else:
        form = AddShiftForm()
        template = 'base/managerstaffing1.html'
        args = {
            'name': name,
            'all_shifts': all_shifts,
            'all_staffing': all_staffing,
            'form': form
        }
    return render(request, template, args)
예제 #2
0
def newshift(request):
    try:
        personal_num = str(request.user)
        air_crew = AirCrew()
        if air_crew.CheckPilot(personal_num):
            crew_role = 'pilot'
        else:
            crew_role = 'navigator'
        flight_date = request.GET.get('flight_date')
        flight_type = request.GET.get('flight_type')
        leader = str(request.GET.get('leader'))
        newshift = Shift()
        newshift.InsertToStaffing(flight_date, flight_type, personal_num, crew_role, leader)
        if leader == '0':
            leader = ' Number 2'
        elif leader == '1':
            leader == 'Movil'
        if leader == '3':
            leader = ' '

        context = {
            'flight_date': flight_date, 'flight_type': flight_type, 'leader': leader
        }
        return render (request, 'base/newshift1.html', context)
    except:
        return redirect ('/profile')
예제 #3
0
def managershifts(request):
    shifts = Shift()
    shift_manager = ShiftManager()
    all_shifts = shifts.ShowAllShifts()
    totalgoal = shift_manager.totalgoal()
    totaldid = shift_manager.totaldid()
    remain = float(totalgoal) - float(totaldid)
    args = {'all_shifts': all_shifts,'totalgoal': totalgoal, 'totaldid': totaldid, 'remain': remain}
    return render(request, 'base/managershifts1.html', args)
예제 #4
0
def Profile(request):
    if request.user.is_staff:
        shift_manager = ShiftManager()
        usernamequery = (str(request.user), )
        name = shift_manager.getname(usernamequery)
        totalgoal = shift_manager.totalgoal()
        totaldid = shift_manager.totaldid()
        remain = float(totalgoal) - float(totaldid)
        args = {
            'name': name,
            'totalgoal': totalgoal,
            'totaldid': totaldid,
            'remain': remain
        }
        return render(request, 'base/managerpage.html', args)
    else:
        username = str(request.user)
        usernamequery = (str(request.user), )
        mydb = mysql.connector.connect(host="localhost",
                                       user="******",
                                       password='******',
                                       database='flight_manager',
                                       auth_plugin='mysql_native_password')
        mycursor = mydb.cursor()
        query = """
         SELECT goal FROM flight_manager.air_crew WHERE personal_number = %s 
        """
        mycursor.execute(query, usernamequery)
        results = mycursor.fetchall()
        mydb.commit()
        for row in results:
            shift = str(row[0])
        new_shift = Shift()
        all_shifts = new_shift.ShowAllShifts()
        if len(shift) == 0:
            shift = '0'
        air_crew = AirCrew()
        future_shifts = air_crew.ShowFutureShifts(username)
        name = air_crew.getname(usernamequery)
        howmanydid = air_crew.howmanydid(username)
        howmanytot = air_crew.howmanytot(usernamequery)
        name = air_crew.getname(usernamequery)
        try:
            left = int(shift) - int(howmanydid[0])
        except:
            left = str('0')
        finally:
            args = {
                'user': name,
                'shifts': shift,
                'all_shifts': all_shifts,
                'howmanydid': howmanydid[0],
                'left': left,
                'shift': shift
            }
            return render(request, 'base/profile.html', args)
예제 #5
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
예제 #6
0
def unmannedshifts(request):
    air_crew = AirCrew()
    shift = Shift()
    all_shifts = shift.ShowAllShifts()
    username = str(request.user)
    if air_crew.CheckLeader(username) == True:
        if air_crew.CheckPilot(username) == True:
            available = air_crew.ShowAvailableShiftsLeaders('pilot')
        elif air_crew.CheckPilot(username) == False:
            available = air_crew.ShowAvailableShiftsLeaders('navigator')

    elif not air_crew.CheckLeader(username) == True:
        if air_crew.CheckPilot(username):
            available = air_crew.ShowAvailableShifts('pilot')
        elif air_crew.CheckPilot(username) == False:
            available = air_crew.ShowAvailableShifts('navigator')
    args = {'available': available}
    return render(request, 'base/unmannedshifts.html', args)
예제 #7
0
def managershowalljobs(request):
    shifts = Shift()
    all_jobs = shifts.showalljobs()
    if request.method == 'POST':
        form = AddShiftForm(request.POST)
        if form.is_valid():
            shift_manager = ShiftManager()
            flight_type = form.cleaned_data['flight_type']
            flight_date = form.cleaned_data['flight_date']
            notes = form.cleaned_data['notes']
            shift_manager.insertshift(flight_date, flight_type, notes)
            args = {'form': form}
            return redirect('/managershowalljobs')

    else:
        form = AddShiftForm()
    template = 'base/manageralljobs.html'
    args = {'form': form, 'all_jobs': all_jobs}
    return render(request, template, args)
    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
 def ShowAvailableShifts(self, status):
     arg = (status,)
     mydb = mysql.connector.connect(host="localhost", user="******", password='******', database='flight_manager',
                                    auth_plugin='mysql_native_password')
     mycursor = mydb.cursor()
     query = """
     SELECT flight_manager.shifts.flight_date,  flight_manager.shifts.flight_type,  flight_manager.type_of_shift.crew_role,  flight_manager.type_of_shift.leader
     from flight_manager.shifts join flight_manager.type_of_shift
     on shifts.flight_type = type_of_shift.flight_type 
     left join flight_manager.staffing
     on flight_manager.shifts.flight_date = flight_manager.staffing.flight_date
     and flight_manager.type_of_shift.flight_type = flight_manager.staffing.flight_type
     and (flight_manager.type_of_shift.crew_role = flight_manager.staffing.crew_role
     or flight_manager.type_of_shift.crew_role = 'all')
     and flight_manager.type_of_shift.leader = flight_manager.staffing.leader
     where personal_num is NULL
     and (type_of_shift.crew_role = %s or type_of_shift.crew_role = 'all')
     and (type_of_shift.leader ='0' or type_of_shift.leader = '3')
     and flight_manager.shifts.flight_date > CURDATE()
     
     """
     mycursor.execute(query, arg)
     results = mycursor.fetchall()
     mydb.commit()
     available_shifts1 = []
     for row in results:
         shift = Shift()
         shift.flight_date = str(row[0])
         shift.flight_type = str(row[1])
         shift.crew_role = str(row[2])
         shift.leader = str(row[3])
         available_shifts1.append(shift)
     return available_shifts1
예제 #10
0
    def unmannedshifts(self):
        mydb = mysql.connector.connect(host="localhost",
                                       user="******",
                                       password='******',
                                       database='flight_manager',
                                       auth_plugin='mysql_native_password')
        mycursor = mydb.cursor()
        query = """
            SELECT flight_manager.shifts.flight_date,  flight_manager.shifts.flight_type,  flight_manager.type_of_shift.crew_role,  flight_manager.type_of_shift.leader
            from flight_manager.shifts join flight_manager.type_of_shift
            on shifts.flight_type = type_of_shift.flight_type 
            left join flight_manager.staffing
            on flight_manager.shifts.flight_date = flight_manager.staffing.flight_date
            and flight_manager.type_of_shift.flight_type = flight_manager.staffing.flight_type
            and (flight_manager.type_of_shift.crew_role = flight_manager.staffing.crew_role
            or flight_manager.type_of_shift.crew_role = 'all')
            and flight_manager.type_of_shift.leader = flight_manager.staffing.leader
            where personal_num is NULL

            
                """
        mycursor.execute(query)
        results = mycursor.fetchall()
        mydb.commit()
        unmenned_shifts = []
        count = 1
        for row in results:
            shift = Shift()
            shift.number = count
            count = count + 1
            shift.flight_date = str(row[0])
            shift.flight_type = str(row[1]).capitalize()
            shift.crew_role = str(row[2]).capitalize()
            if str(row[3]) == '1':
                shift.leader = 'Must Be Movil'
            elif str(row[3]) == '0':
                shift.leader = 'Number 2'
            else:
                shift.leader = 'All'
            unmenned_shifts.append(shift)
        return unmenned_shifts
예제 #11
0
    def unmannedshifts(self):
        mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net", user="******",
                                       password='******', database='heroku_947e29c06a5b4a3')

        mycursor = mydb.cursor()
        query = """
            SELECT shifts.flight_date,  shifts.flight_type,  type_of_shift.crew_role,  type_of_shift.leader
            from shifts join type_of_shift
            on shifts.flight_type = type_of_shift.flight_type 
            left join staffing
            on shifts.flight_date = staffing.flight_date
            and type_of_shift.flight_type = staffing.flight_type
            and (type_of_shift.crew_role = staffing.crew_role
            or type_of_shift.crew_role = 'all')
            and type_of_shift.leader = staffing.leader
            where personal_num is NULL

            
                """
        mycursor.execute(query)
        results = mycursor.fetchall()
        mydb.commit()
        mycursor.close()
        unmenned_shifts = []
        count = 1
        for row in results:
            shift = Shift()
            shift.number = count
            count = count +1
            shift.flight_date = str(row[0])
            shift.flight_type = str(row[1]).capitalize()
            shift.crew_role =str(row[2]).capitalize()
            if str(row[3]) =='1':
                shift.leader = 'Must Be Movil'
            elif str(row[3]) == '0':
                shift.leader = 'Number 2'
            else :
                shift.leader = 'All'
            unmenned_shifts.append(shift)
        return unmenned_shifts
예제 #12
0
def allshifts(request):
    shift = Shift()
    all_shifts = shift.ShowAllShifts()
    args = {'all_shifts' : all_shifts}
    return render(request, 'base/allshifts.html', args)