Beispiel #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', ""))

    '''
        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()
Beispiel #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', ""))
    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()
Beispiel #3
0
def send_email(request, arr):    
    render = render_to_string(constant.email_popup_page)
    dajax = Dajax()
    html = render.replace('\n', "")
    dajax.script(constant.append_flight_email_popup %html)
    emails = UserTemp.objects.filter(employee_number=request.session[constant.usernameParam])
    html = ''
    val = ''
    j = 0
    for i in arr:
        html = html + "<div class=\"attack_file\"><input class=\"attack_file\" readonly=\"true\" name=\"attack_file_" + i + "\" value=\"flight_log_" + i + ".pdf\" type=\"text\" /><div class=\"close-attack\">x</div></div>"
        if(j == 0):
            val = val + i
            j = 1
        else:
            val = val + ',' + i
            pdf_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + '/../helicopters/static/media/pdf_export/flight_log_' + i + '.pdf'
            from PyPDF2 import PdfFileWriter
            op = PdfFileWriter() 
            op.addBlankPage(793, 1122)
            ops = file(pdf_path, "wb") 
            op.write(ops)
            ops.close()
             
    html = html + '<input class="hiden_attack" name="hiden_attack" val="'+ val + '" type="input" />'
    dajax.script("var e_html = '" + html +"';\
        jQuery('.attack_files').html(e_html);")
    for email in emails:
        dajax.script("jQuery('.email_from').val('" + email.email + "');")
    return dajax.json()
Beispiel #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()
Beispiel #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()
Beispiel #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()
Beispiel #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', ""))
Beispiel #8
0
def send_email(request, arr):
    render = render_to_string(constant.email_popup_page)
    dajax = Dajax() 
    html = render.replace('\n', "")
    dajax.script(constant.append_flight_email_popup %html)
    emails = UserTemp.objects.filter(employee_number=request.session[constant.usernameParam])
    html = ''
    val = ''
    j = 0
    from flight_log.views import log_pdf
    from flight_log.utility import convertHtmlToPdf
    pdf_files = []
    dirname = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +'/../helicopters/static/media/pdf_export/'
    for i in arr:
        log = Log.objects.get(id_log=i) or None
        if not log:
            continue
        num_formated = format6(log.log_number)
        if(j == 0):
            val = val + num_formated
            j = 1
        else:
            val = val + ',' + num_formated
        pdf_path = dirname + num_formated
        pdf_files.append(num_formated)
        pdf = render_to_string("flights/pdf.html", log_pdf(i))
        convertHtmlToPdf(pdf, pdf_path)
        
    if len(arr) > 1:
        from datetime import datetime
        today_str= datetime.now().strftime('%m_%d_%Y')
        i = today_str
        files_today = 'Daily_Flight_Log_' + today_str + '.zip'
        
        # read stream zip
        buffer = StringIO.StringIO()
        zf = zipfile.ZipFile(buffer, mode='w')
        for pdf_file in pdf_files:
            try:
                zf.write(dirname + pdf_file, pdf_file)
            finally:
                pass
        zf.close()
        # save file to local
        buffer.seek(0)
        f = file(dirname + files_today, "w")
        f.write(buffer.read())
        f.close()
        
        
    else:
        i = arr[0]
        files_today = pdf_files[0]
    
    

    #print "files_today on dajaxice_register send_email", files_today
   
    html = html + "<div class=\"attack_file\"><input id=\"attack_file_1\" onclick=\"download(this)\" class=\"attack_file\" readonly=\"true\" name=\"attack_file_" + i + "\" value=\"" + files_today +"\" type=\"text\" /><div class=\"close-attack\">x</div></div>"
    
        
    # POST lost dot, so we remove it and add on recived
    html = html + '<input class="hiden_attack" name="hiden_attack" val="'+ files_today + '" type="input" />'
    dajax.script("var e_html = '" + html +"';\
        jQuery('.attack_files').html(e_html);")
    for email in emails:
        dajax.script("jQuery('.email_from').val('" + email.email + "');")
    return dajax.json()