Ejemplo n.º 1
0
def edit_flight(request, page):

    url = logbook_url(request.display_user, page)

    if not request.POST:
        return HttpResponseNotAllowed("method not allowed")

    profile, c = Profile.objects.get_or_create(user=request.display_user)
    plane_widget = proper_plane_widget(profile)

    flight_id = request.POST['id']
    flight = Flight(pk=flight_id, user=request.display_user)

    form = forms.PopupFlightForm(request.POST,
                                 plane_widget=plane_widget,
                                 user=request.display_user,
                                 instance=flight,
                                 prefix="new")

    if form.is_valid() and request.display_user.username != 'ALL':
        form.save()

        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user, page=page)

        return HttpResponseRedirect(url)

    return logbook(request, form=form, fail="edit")
Ejemplo n.º 2
0
def edit_flight(request, page):
    
    url = logbook_url(request.display_user, page)
        
    if not request.POST:
        return HttpResponseNotAllowed("method not allowed")
    
    profile,c = Profile.objects.get_or_create(user=request.display_user)
    plane_widget = proper_plane_widget(profile)
    
    flight_id = request.POST['id']
    flight = Flight(pk=flight_id, user=request.display_user)

    form = forms.PopupFlightForm(request.POST,
                           plane_widget=plane_widget,
                           user=request.display_user,
                           instance=flight,
                           prefix="new")

    if form.is_valid() and request.display_user.username != 'ALL':
        form.save()
        
        from backup.models import edit_logbook
        edit_logbook.send(sender=request.display_user, page=page)
        
        return HttpResponseRedirect(url)
        
    return logbook(request, form=form, fail="edit")
Ejemplo n.º 3
0
def logbook(request, page=0, form=None, fail=None):
    """
    Prepare the Logbook page
    """
    if page == "0":
        url = reverse("logbook", kwargs={"username": request.display_user})
        return HttpResponseRedirect(url)

    auto_button, c = AutoButton.objects.get_or_create(
        user=request.display_user)
    cols, c = Columns.objects.get_or_create(user=request.display_user)
    profile, c = Profile.objects.get_or_create(user=request.display_user)

    ################## custom filter form ########################

    from custom_filter import make_filter_form
    ## filter form is created dynamically because each user has different planes
    ## so those dropdowns will be different
    FilterForm = make_filter_form(request.display_user)
    ff = FilterForm()

    ##############################################################

    all_flights = Flight.objects\
                        .user(request.display_user, disable_future=True)\
                        .order_by('date', 'id')

    filtered_flights = all_flights.select_related()
    total_sign = "Overall"

    if request.GET:
        ff = FilterForm(request.GET)
        filtered_flights = filtered_flights.custom_logbook_view(ff)
        ## split it to get just the part after the '?', ignore the part before
        get = "?" + request.get_full_path().split("?")[1]
        total_sign = "Filter"

    ############## google maps and google earth filter below ################

    earth = request.GET.get('earth')
    maps = request.GET.get('maps')

    if earth == 'true':
        routes = Route.objects.filter(flight__in=filtered_flights)
        response = qs_to_time_kmz(routes)
        response['Content-Disposition'] = 'attachment; filename=filter.kmz'
        return response

    if maps == 'true':
        url = "http://maps.google.com/?q=http://flightlogg.in/%s/logbook.html%s"
        get = get.replace('maps=true', "earth=true").replace('&', '%26')
        return HttpResponseRedirect(url % (request.display_user.username, get))

    ############### pagination stuff below ############################

    before_block, after_block, page_of_flights = \
                   Flight.make_pagination(filtered_flights, profile, int(page))

    #only make the page table if there are more than one pages overall
    do_pagination = page_of_flights.paginator.num_pages > 1

    if not form:
        plane_widget = proper_plane_widget(profile)
        form = forms.PopupFlightForm(plane_widget=plane_widget,
                                     prefix="new",
                                     user=request.display_user)
    else:
        ## set this variable so we know which popup to prepare to enter the
        ## failed form data
        edit_or_new = fail

    return locals()
Ejemplo n.º 4
0
def logbook(request, page=0, form=None, fail=None):
    """
    Prepare the Logbook page
    """
    if page == "0":
        url = reverse("logbook", kwargs={"username": request.display_user})
        return HttpResponseRedirect(url)
    
    auto_button,c = AutoButton.objects.get_or_create(user=request.display_user)
    cols, c = Columns.objects.get_or_create(user=request.display_user)
    profile,c = Profile.objects.get_or_create(user=request.display_user)
    
    ################## custom filter form ########################
    
    from custom_filter import make_filter_form
    ## filter form is created dynamically because each user has different planes
    ## so those dropdowns will be different
    FilterForm = make_filter_form(request.display_user)
    ff = FilterForm()
    
    ##############################################################
    
    all_flights = Flight.objects\
                        .user(request.display_user, disable_future=True)\
                        .order_by('date', 'id')
                        
    filtered_flights = all_flights.select_related()
    total_sign = "Overall"
    
    if request.GET:
        ff = FilterForm(request.GET)
        filtered_flights = filtered_flights.custom_logbook_view(ff)
        ## split it to get just the part after the '?', ignore the part before
        get = "?" + request.get_full_path().split("?")[1]
        total_sign = "Filter"
            
    ############## google maps and google earth filter below ################
    
    earth = request.GET.get('earth')
    maps = request.GET.get('maps')
    
    if earth == 'true':
        routes = Route.objects.filter(flight__in=filtered_flights)
        response = qs_to_time_kmz(routes)
        response['Content-Disposition'] = 'attachment; filename=filter.kmz'
        return response
    
    if maps == 'true':
        url = "http://maps.google.com/?q=http://flightlogg.in/%s/logbook.html%s"
        get = get.replace('maps=true', "earth=true").replace('&', '%26')
        return HttpResponseRedirect(url % (request.display_user.username, get))

    
    ############### pagination stuff below ############################
    
    before_block, after_block, page_of_flights = \
                   Flight.make_pagination(filtered_flights, profile, int(page))
    
    #only make the page table if there are more than one pages overall
    do_pagination = page_of_flights.paginator.num_pages > 1
    
    if not form:
        plane_widget = proper_plane_widget(profile)
        form = forms.PopupFlightForm(plane_widget=plane_widget, prefix="new", user=request.display_user)
    else:
        ## set this variable so we know which popup to prepare to enter the
        ## failed form data
        edit_or_new = fail
        
    return locals()