Exemplo n.º 1
0
 def average_fuel_economy_string(self):
     # TODO: this can be made more efficient.
     fillups = FillupAction.objects.filter(log__garagevehicle__garage=self)
     total_economy = 0
     average_economy = 0
     for fillup in fillups:
         total_economy = total_economy + fillup.get_economy()
     if len(fillups) is not 0:
         average_economy = total_economy / len(fillups)
     return '%s %s' % (average_economy, current_fuel_economy_units())
Exemplo n.º 2
0
 def average_fuel_economy_string(self):
     # TODO: this can be made more efficient.
     fillups = FillupAction.objects.filter(log__garagevehicle__garage=self)
     total_economy = 0
     average_economy = 0
     for fillup in fillups:
         total_economy = total_economy + fillup.get_economy()
     if len(fillups) is not 0:
         average_economy = total_economy / len(fillups)
     return '%s %s' % (average_economy, current_fuel_economy_units())
Exemplo n.º 3
0
def edit(request, log_id):
    
    try:
        log = MaintenanceLog.objects.get(id=log_id)
    except MaintenanceLog.DoesNotExist:
        raise Http404()
    
    # Verify that the current user owns this log
    if request.user.id is not log.user.id:
        raise Http404()
    
    form_handler = FormHandler()
    
    add_action_form = None
    init_handler = form_handler.pass_init_handler
    if request.POST and request.POST['form_class_name'] == 'AddNewActionForm':
        add_action_form = AddNewActionForm(log, request.POST, prefix='new_action')
    else:
        add_action_form = AddNewActionForm(log, prefix='new_action')
    
    form_handler.add_form(AddNewActionForm, 'new_action', params={'form': add_action_form,
        'prefix': 'new_action',
        'submit_text': 'Add',
        'init_handler': init_handler,
        'template': add_action_form.get_template(),
        #'clear_form_on_save': True,
    })
    
    #for action in MaintenanceAction.objects.filter(log=log):
    for action in FillupAction.objects.filter(log=log).order_by('mileage').order_by('date'):
        form = FillupActionForm(instance=action, prefix=action.id)
        form_handler.add_form(FillupActionForm, action.id, params={'form': form,
            'instance': action,
            'prefix': action.id,
            'template': form.get_template(),
        })
    
    action = FillupAction()
    action.log = log
    form = FillupActionForm(instance=action, prefix='new_form')
    form_handler.add_form(FillupActionForm, 'new_form', params={'form': form, 'instance': action,
        'prefix': 'new_form',
        'template': form.get_template(),
        'clear_form_on_save': True,
    })
    
    return { 'form_handler': form_handler, 'extra_context': { 'log': log,
                                                              'fuel_economy_units': current_fuel_economy_units(),
                                                            } }