def register(request):
    mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net", user="******", password='******',
                                   database='heroku_947e29c06a5b4a3')
    if request.user.is_authenticated:
        return render(request, 'base/profile.html')
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            air_crew = AirCrew()
            if air_crew.is_auth(form.cleaned_data['username']):
                user = User.objects.create_user(first_name =form.cleaned_data['first_name'], username = form.cleaned_data['username'],
                                                last_name = form.cleaned_data['last_name'], email=form.cleaned_data['Email'], password =form.cleaned_data['password'], )
                user.save()
                aircrew = AirCrew()
                aircrew.personal_num = form.cleaned_data['username']
                aircrew.movil = form.cleaned_data['movil']
                aircrew.category = form.cleaned_data['category']
                aircrew.status = form.cleaned_data['status']
                aircrew.InsertToDb()
                return redirect('/profile')
            else:
                return render(request, 'base/notauthorized.html')
    else:
        form = ContactForm()
    args = {'form': form}
    return render(request,'base/register.html', args)
def myshifts(request):
    username = str(request.user)
    air_crew = AirCrew()
    my_shifts = air_crew.ShowMyShifts(username)
    future_shifts = air_crew.ShowFutureShifts(username)
    args = {'my_shifts' : my_shifts, 'future_shifts': future_shifts}
    return render(request, 'base/myshifts1.html', args)
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')
def airgoalsinfo(request):
    air_crew = AirCrew()
    username = request.GET.get('personal_num')
    usernamequery = (str(username),)
    name = air_crew.getname(usernamequery)
    air_info  = air_crew.ShowMyShifts(username)
    args = {'air_info' : air_info, 'name':name}
    return render(request, 'base/airgoalinfo1.html', args)
def contact(request):
    aircrew = AirCrew()
    user = aircrew.getname((str(request.user),))
    if request.method == "POST":
        form = ContactMe(request.POST)
        if form.is_valid():
            contact = Contact()
            contact.personal_num = str(request.user)
            contact.content = form.cleaned_data['content']
            contact.insertcontent(contact.personal_num, contact.content)
            return redirect('/profile')
    else:
        form = ContactMe()
    args = {'form': form, 'user': user}
    return render(request,'base/contact1.html',args)
Beispiel #6
0
 def goaltracker(self):
     mydb = mysql.connector.connect(host="localhost",
                                    user="******",
                                    password='******',
                                    database='flight_manager',
                                    auth_plugin='mysql_native_password')
     mycursor = mydb.cursor()
     query = """
         select flight_manager.air_crew.personal_number, flight_manager.auth_user.first_name, flight_manager.auth_user.last_name, 
         flight_manager.air_crew.goal, count(flight_manager.staffing.personal_num) As achieved
         from flight_manager.auth_user  join flight_manager.air_crew
         on flight_manager.auth_user.username = flight_manager.air_crew.personal_number
         left join flight_manager.staffing
         on flight_manager.air_crew.personal_number = flight_manager.staffing.personal_num
         group by air_crew.personal_number;
         
         """
     mycursor.execute(query)
     results = mycursor.fetchall()
     mydb.commit()
     air_goals = []
     for row in results:
         air_crew = AirCrew()
         air_crew.personal_num = str(row[0])
         air_crew.first_name = str(row[1]).capitalize()
         air_crew.last_name = str(row[2]).capitalize()
         air_crew.goal = str(row[3])
         air_crew.achieved = str(row[4])
         air_goals.append(air_crew)
     return air_goals
Beispiel #7
0
    def goaltracker(self):
        mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net", user="******",
                                       password='******', database='heroku_947e29c06a5b4a3')

        mycursor = mydb.cursor()
        query = """
            select air_crew.personal_number, auth_user.first_name, auth_user.last_name, 
            air_crew.goal, count(staffing.personal_num) As achieved
            from auth_user  join air_crew
            on auth_user.username = air_crew.personal_number
            left join staffing
            on air_crew.personal_number = staffing.personal_num
            group by air_crew.personal_number;
            
            """
        mycursor.execute(query)
        results = mycursor.fetchall()
        mydb.commit()
        mycursor.close()
        air_goals = []
        for row in results:
            air_crew = AirCrew()
            air_crew.personal_num = str(row[0])
            air_crew.first_name = str(row[1]).capitalize()
            air_crew.last_name = str(row[2]).capitalize()
            air_crew.goal = str(row[3])
            air_crew.achieved = str(row[4])
            air_goals.append(air_crew)
        return air_goals
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)
Beispiel #9
0
    def insertcontent(self, personal_num, content):
        mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net",
                                       user="******",
                                       password='******',
                                       database='heroku_947e29c06a5b4a3')

        air_crew = AirCrew()
        val = (personal_num, content)
        mycursor = mydb.cursor()
        query = """ insert into contact(personal_num, date, content)
                               VALUES(%s, curdate(),%s)"""
        mycursor.execute(query, val)
        mydb.commit()
Beispiel #10
0
 def insertcontent(self, personal_num, content):
     air_crew = AirCrew()
     val = (personal_num, content)
     mydb = mysql.connector.connect(host="localhost",
                                    user="******",
                                    password='******',
                                    database='flight_manager',
                                    auth_plugin='mysql_native_password')
     mycursor = mydb.cursor()
     query = """ insert into contact(personal_num, date, content)
                            VALUES(%s, curdate(),%s)"""
     mycursor.execute(query, val)
     mydb.commit()
Beispiel #11
0
    def getletters(self):
        mydb = mysql.connector.connect(host="us-cdbr-iron-east-01.cleardb.net", user="******",
                                       password='******', database='heroku_947e29c06a5b4a3')

        mycursor = mydb.cursor()
        query = """
                    select * from contact
               """
        mycursor.execute(query)
        results = mycursor.fetchall()
        mydb.commit()
        mycursor.close()
        letters = []
        for row in results:
            contact = Contact()
            air_crew = AirCrew()
            contact.personal_num = str(row[0])
            personal_num = str(row[0]).capitalize()
            contact.date = str(row[1])
            contact.content = str(row[2])
            contact.name = air_crew.getname((personal_num,))
            letters.append(contact)
        return letters
Beispiel #12
0
 def getletters(self):
     mydb = mysql.connector.connect(host="localhost",
                                    user="******",
                                    password='******',
                                    database='flight_manager',
                                    auth_plugin='mysql_native_password')
     mycursor = mydb.cursor()
     query = """
                 select * from flight_manager.contact
            """
     mycursor.execute(query)
     results = mycursor.fetchall()
     mydb.commit()
     letters = []
     for row in results:
         contact = Contact()
         air_crew = AirCrew()
         contact.personal_num = str(row[0])
         personal_num = str(row[0]).capitalize()
         contact.date = str(row[1])
         contact.content = str(row[2])
         contact.name = air_crew.getname((personal_num, ))
         letters.append(contact)
     return letters
def register(request):
    if request.user.is_authenticated:
        return render(request, 'base/profile.html')
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                first_name=form.cleaned_data['first_name'],
                username=form.cleaned_data['username'],
                last_name=form.cleaned_data['last_name'],
                password=form.cleaned_data['password'],
            )
            user.save()
            aircrew = AirCrew()
            aircrew.personal_num = form.cleaned_data['username']
            aircrew.movil = form.cleaned_data['movil']
            aircrew.category = form.cleaned_data['category']
            aircrew.status = form.cleaned_data['status']
            aircrew.InsertToDb()
            return redirect('/profile')
    else:
        form = ContactForm()
    args = {'form': form}
    return render(request, 'base/register.html', args)
def unmannedshifts(request):
    air_crew = AirCrew()
    shift = Shift()
    all_shifts = shift.ShowAllShifts()
    username = str(request.user)
    usernamequery = (str(username),)
    shift_manager = ShiftManager()
    #user = shift_manager.getname(usernamequery)
    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/unmannedshifts1.html', args)