Exemplo n.º 1
0
def edit_flight_log(request, index, max_pax, is_submitted = False):
    dajax = Dajax()
    
    request.session["current_index"] = index - 1
    
    fuel_station_name = None
    list_log_section = get_list_session_object(request)
    edit_object = list_log_section[index-1]
    
    if edit_object.flight_data_fuel_station:
        fuel_station_name = edit_object.flight_data_fuel_station.location_name
    form = FlightLogDetail(instance = edit_object, partial_range = edit_object.flight_time,
                           max_pax = max_pax)
    
    render = render_to_string(constant.popup_page ,{constant.single_form:form,
                                                    constant.IS_EDIT : "true",
                                                    constant.is_submitted:is_submitted})
    dajax.script(constant.prepend_table_popup %render.replace('\n', ""))
    dajax.script("if($(\"#id_load_schedule\").is(\":checked\")){\
            $(\"#id_flight_data_cg\").parent().find(\"span span\").css(\"display\", \"none\");\
            $(\"#id_flight_data_range_from\").parent().find(\"span span\").css(\"display\", \"none\");\
            $(\"#id_flight_data_range_to\").parent().find(\"span span\").css(\"display\", \"none\");\
            }");

    '''
        Generate data into fuel station
    '''
    pour_fuel_station_popup(dajax)
    if fuel_station_name:
        scr_name = 'set_fuel_station("'+ str(fuel_station_name) +'");' 
        dajax.script(scr_name)
    return dajax.json()
Exemplo n.º 2
0
def edit_flight_log(request, index, max_pax, is_submitted = False):
    dajax = Dajax()
    
    request.session["current_index"] = index - 1
    
    fuel_station_name = None
    list_log_section = get_list_session_object(request)
    edit_object = list_log_section[index-1]
    
    if edit_object.flight_data_fuel_station:
        fuel_station_name = edit_object.flight_data_fuel_station.location_name
    form = FlightLogDetail(instance = edit_object, partial_range = edit_object.flight_time,
                           max_pax = max_pax)
    render = render_to_string(constant.popup_page ,{constant.single_form:form,
                                                    constant.IS_EDIT : "true",
                                                    constant.is_submitted:is_submitted})
    
    dajax.script(constant.prepend_table_popup %render.replace('\n', ""))

    '''
        Generate data into fuel station
    '''
    pour_fuel_station_popup(dajax)
    if fuel_station_name:
        scr_name = 'set_fuel_station("'+ str(fuel_station_name) +'");' 
        dajax.script(scr_name)
    return dajax.json()
Exemplo n.º 3
0
def ajax_model_request(request, mode):
    
    from_value = ""
    to_value = ""
    mass_gross = ""
    list_ac = []
    model_obj = None
    msg = ""
    max_pax = ""
    dic = []
    
    if mode:
        list_ac = A1C.objects.filter(model=mode)
        model_obj = Model.objects.get(id_model=mode)
     
        for c in list_ac:
            dic.append({'name': c.a1c_name, 'id': c.id_a1c})
            
        """
            Check max_passenger of model
        """
        list_log_section = []
        mass_gross = model_obj.max_gross_weight
        from_value = model_obj.me_load_schedule_cg_range_from
        to_value = model_obj.me_load_schedule_cg_range_to
        max_pax = model_obj.max_passenger
        try:
            list_log_section = get_list_session_object(request)
        except:
            pass
        msg = pax_error(model_obj.max_passenger, list_log_section)
    """
        Render to html
    """
    return simplejson.dumps({'list_ac': dic, 
                             'mass_gross':mass_gross,
                             'from':from_value,
                             'to' : to_value,
                             'pass_message':msg,
                             'delete_mess':"delete",
                             'max_pax': max_pax})
Exemplo n.º 4
0
def add_flight_log(request, next_order_id, fuel, max_pax):
    '''
        Get list object from session
    '''
    list_log_section = get_list_session_object(request)
    try:
        fuel = list_log_section[len(list_log_section)-1].fuel_wheels_down
    except:
        pass
    '''
        Initial Flight Log Session form 
    '''
    form = FlightLogDetail(next_order_id = next_order_id, fuel = fuel, max_pax = max_pax)
    
    render = render_to_string(constant.popup_page ,{constant.single_form:form,
                                                    constant.IS_EDIT : "false"})
    
    dajax = Dajax()
    dajax.script(constant.prepend_table_popup %render.replace('\n', ""))
    pour_fuel_station_popup(dajax)
    return dajax.json()
Exemplo n.º 5
0
def save_flight_log(request, forms, max_pax, partial_range, 
                    before_fuel_location, list_fuel_location,
                    is_edit):
    dajax = Dajax()
    
    ''' Remove all errors message in popup '''
    dajax.remove(constant.class_error_mess)
    ''' Generate new form '''
    form = FlightLogDetail(deserialize_form(forms), partial_range = partial_range, max_pax = max_pax)
    if form.is_valid():
        ''' Get object form data '''
        result = form.save(commit = False)
        
        ''' If add new flight legs '''
        if is_edit == "false":
            dajax.script(constant.append_flight_log_form 
                         %save_add_case(request, result))
            """
                Announce after saved
            """
            dajax.script(constant.append_save_succ_mess %constant.add_succ_mess)
        
        ''' Edit flight legs '''
        if is_edit == "true":
            current_location = None
            location_name = None
            try:
                location = Location.objects.get(id_location = before_fuel_location)
                if location:
                    before_fuel_location = location.location_name
            except:
                pass
        

            if result.flight_data_fuel_station:
                current_location = result.flight_data_fuel_station.location_name
                
            '''
                Check location in fuel expenses is conflict with flight log session or not
                - If not when change
                - If has conflict so announce and return
            '''
            remove_older_location = False
            list_location_temp = []
            list_object = get_list_session_object(request)
            
            ''' Get older station location '''
            for obj in list_object:
                if obj.flight_data_fuel_station:
                    location_name = obj.flight_data_fuel_station.location_name
                    if location_name:
                        list_location_temp.append(str(location_name))
                if before_fuel_location == str(location_name) != "None" and not remove_older_location:
                    list_location_temp.remove(before_fuel_location)
                    remove_older_location = True
            ''' Input new station into list '''
            if current_location:   
                list_location_temp.append(current_location)
            ''' Verify whether conflict '''    
            for val in list_fuel_location:
                if str(val) != "None" and str(val) != "" and str(val) not in list_location_temp:
                    dajax.alert(constant.announce_mess_fuel_location_change)
                    pour_fuel_station_popup(dajax)
                    dajax.script(constant.prevent_default)
                    return dajax.json()
                
            ''' Change data of flight log in sessio '''    
            lst = request.session[constant.list_flight_log]
            lst[request.session["current_index"]] = serializers.serialize(constant.json, [result, ])
            request.session[constant.list_flight_log] = lst
            
            """
                Announce after edited
            """
            dajax.script(constant.append_save_succ_mess %constant.edited_succ_mess)
            
        ''' Modify data for hidden combobox and used for fuel expenses sessio '''
        dajax.remove("#hiddenff option")
        import operator
        sorted_list_fuel_station = sorted(fuel_station_list(request).items(), key=operator.itemgetter(1))
        for local_id, name in sorted_list_fuel_station:
            dajax.append('#hiddenff', 'innerHTML', "<option value="+str(local_id)+">"+str(name)+"</option>")
            
        '''
            Modify flight legs table
        '''
        dajax.remove(constant.id_rs_flight_log_form)
        render = render_to_string(constant.flight_log_table_page,
                                  {constant.forms:get_list_session_object(request)})
        dajax.script(constant.prepend_flight_log_table 
                     %render.replace('\n', ""))
        
    else:#Form not valid
        dajax.remove(constant.class_pop_main)
        render = render_to_string(constant.popup_page ,{constant.single_form:form})
        dajax.script(constant.prepend_table_popup %render.replace('\n', ""))
        dajax.script("if(!$('#id_load_schedule').is(':checked') & \
                ($('#id_flight_data_range_from').val() == '' || \
                $('#id_flight_data_range_to').val() == '')){\
                $('#range_to_error_id').css('display','block');}")
        
        ''' Pour data for fuel station in popup '''
        pour_fuel_station_popup(dajax)
        
        dajax.script(constant.prevent_default)
    
    ''' Announce message when edit flight legs '''
    list_log_section = []
    try:
        list_log_section = get_list_session_object(request)
    except:
        pass
    msg = pax_error(max_pax, list_log_section)
    
    dajax.script(constant.append_error_mess % msg)
    if msg:
        dajax.script(constant.remove_save_succ_mess)
        
    pour_fuel_station_popup(dajax)
    return dajax.json()
Exemplo n.º 6
0
def delete_flight_log(request, index, max_pax, list_fuel_location):
    dajax = Dajax()
    
    list_object = get_list_session_object(request)
    
    count = 0
    current_object = None
    for obj in list_object:
        if obj.order == int(index):
            current_object = obj
            
    for obj in list_object:
        if obj.flight_data_fuel_station and current_object.flight_data_fuel_station:
            if obj.flight_data_fuel_station == current_object.flight_data_fuel_station:
                if str(obj.flight_data_fuel_station.location_name) in list_fuel_location:
                    count += 1
    if count == 1:
        dajax.alert(constant.announce_mess_fuel_location_change);
        return dajax.json()
    
    '''
        Change all session here
    '''
    temp_list = []
    i = 1
    for obj in list_object:
        if obj.order != int(index):
            obj.order = i
            temp_list.append(serializers.serialize(constant.json, [obj, ]))
            i += 1 
    
    '''
        Add all flight leg into session
    '''
    request.session[constant.list_flight_log] = temp_list
    ''' Remove old flight legs table at home page '''
    dajax.remove(constant.id_rs_flight_log_form)
    ''' Render data into new flight legs table '''
    render = render_to_string(constant.flight_log_table_page,
                              {constant.forms:get_list_session_object(request)})
    ''' Insert new flight legs table into home  page '''
    dajax.script(constant.prepend_flight_log_table 
                 %render.replace('\n', ""))
    
    '''
        Announce message in home page if passenger of model is out of range
    '''
    list_log_section = []
    try:
        list_log_section = get_list_session_object(request)
    except:
        pass
    msg = pax_error(max_pax, list_log_section)
    dajax.script(constant.append_error_mess % msg)
    if msg:
        dajax.script(constant.remove_save_succ_mess)
    
    ''' Modify data for hidden combobox and used for fuel expenses sessio '''
    dajax.remove("#hiddenff option")
    import operator
    sorted_list_fuel_station = sorted(fuel_station_list(request).items(), key=operator.itemgetter(1))
    for local_id, name in sorted_list_fuel_station:
        dajax.append('#hiddenff', 'innerHTML', "<option value="+str(local_id)+">"+str(name)+"</option>")

     
    return dajax.json()
Exemplo n.º 7
0
def load_copilot_sub(request, co_pilot, id_log, dajax):
    '''Create formset'''
    PilotFormSet = formset_factory( form = PilotForm, 
                                       max_num=10, extra = 0)
    '''Load data for table'''
    list = []
    '''Get list flight log in session and calculate sum value'''
    lst_flight_log = get_list_session_object(request)
    sic = pic = night = day = vfr = ifr = nvg = co_nvg = 0
    
    for flight in lst_flight_log:
        sic = sic + flight.flight_time
        pic = pic + flight.flight_time
        day = day + flight.day
        night = night + flight.night
        if flight.pilot_nvg:
            nvg = nvg + flight.pilot_nvg
        if flight.co_pilot_nvg:
            co_nvg = co_nvg + flight.co_pilot_nvg
        if flight.partial_nfr != -1 and type(flight.partial_nfr) != unicode:
            vfr = vfr + flight.partial_nfr
            ifr = ifr + flight.flight_time - flight.partial_nfr
        else:
            if flight.all_nfr:
                vfr = vfr + flight.flight_time
                ifr = ifr + 0
            if flight.all_ifr:
                ifr = ifr + flight.flight_time
                vfr = vfr + 0
    
    pilot = LogEmployee()
    pilot.pic = pic
    pilot.day = day
    pilot.night = night
    pilot.nvg = nvg
    pilot.vfr = vfr
    pilot.ifr = ifr
    try:
        log_temp = Log.objects.filter(id_log=id_log)
        if log_temp:
            pilot.log = log_temp[0]
    except:
        pass
    emp_temp = Employee.objects.filter(employee_number = request.session[constant.usernameParam])
    if emp_temp:
        pilot.employee = emp_temp[0]
    list.append(todict(pilot))

    if co_pilot != "Choose One" and request.session[constant.usernameParam] != co_pilot:
        co_pilot_object = LogEmployee()
        co_pilot_object.sic = sic
        co_pilot_object.day = day
        co_pilot_object.night = night
        co_pilot_object.nvg = co_nvg
        co_pilot_object.vfr = vfr
        co_pilot_object.ifr = ifr
        try:
            log_temp = Log.objects.filter(id_log=id_log)
            if log_temp:
                co_pilot_object.log = log_temp[0]
        except:
            pass
        emp_temp = Employee.objects.filter(employee_number = co_pilot)
        if emp_temp:
            co_pilot_object.employee = emp_temp[0]
        list.append(todict(co_pilot_object))
    
    '''Remove older table'''
    dajax.remove("#table_pilot")
    dajax.remove("#pi_content")
    
    '''Init data for formset'''
    formset_pilot = PilotFormSet(initial = list, prefix='pilots')
    
    '''Render form'''
    render = render_to_string(constant.pilot_section ,{"formset_pilot":formset_pilot})
    render1 = render_to_string(constant.pilot_form ,{"formset_pilot":formset_pilot})
    
    '''Append form'''
    dajax.script(constant.append_pilot_section %render.replace('\n', ""))
    dajax.script(constant.append_pilot_form %render1.replace('\n', ""))