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(), } }
def vehicle_select_form(request): prefix = 'select_vehicle' form = DynamicVehicleSelectForm(request.POST) form_handler = FormHandler() form_handler.add_form(DynamicVehicleSelectForm, 'select_vehicle', params={ 'form': form, 'prefix': 'select_vehicle', 'submit_text': 'Search Vehicles', 'init_handler': form_handler.pass_init_handler, 'submit_classes': 'js_disabled_only', 'template': 'vehicle/include/vehicle_select_form.html' }) return {'form_handler': form_handler, 'extra_context': {}}
def garage_form_handler(request, username): if username == None: garage = request.user.garage else: try: garage = Garage.objects.get(user__username=username) except: raise Http404() form_handler = FormHandler() garage_vehicles = garage.garagevehicle_set.all() for garage_vehicle in garage_vehicles: form = GarageVehicleForm(instance=garage_vehicle, prefix=garage_vehicle.id) form_handler.add_form(GarageVehicleForm, garage_vehicle.id, params={ 'form': form, 'instance': garage_vehicle, 'prefix': garage_vehicle.id, 'template': 'garage/include/form_garagevehicle.html' }) show_what_next = False new_vehicle_id = -1 if request.GET: new_vehicle_id = int(request.GET.get('add_vehicle', -1)) try: show_what_next = request.GET['what_next'] show_what_next = True except: pass new_garage_vehicle = None add_new_in_progress = False if new_vehicle_id is not -1: try: new_vehicle = EPAVehicle.objects.get(id=new_vehicle_id) new_garage_vehicle = GarageVehicle(vehicle=new_vehicle, garage=garage) add_new_in_progress = True except: raise Http404() else: new_garage_vehicle = GarageVehicle(garage=garage) form = DynamicVehicleSelectForm(request.POST) form_handler.add_form(DynamicVehicleSelectForm, 'select_vehicle', params={ 'form': form, 'prefix': 'select_vehicle', 'submit_text': 'Search Vehicles', 'init_handler': form_handler.pass_init_handler, 'submit_classes': 'js_disabled_only', 'template': 'vehicle/include/vehicle_select_form.html' }) form = GarageVehicleForm(instance=new_garage_vehicle, prefix='new_form') form_handler.add_form(GarageVehicleForm, 'new_form', params={ 'form': form, 'instance': new_garage_vehicle, 'prefix': 'new_form', 'submit_text': 'Add To Garage', 'template': 'garage/include/form_garagevehicle.html' }) return { 'form_handler': form_handler, 'extra_context': { 'garage': garage, 'add_new_in_progress': add_new_in_progress, 'show_edit_ui': True, 'show_what_next': show_what_next, } } return view_garage(request, request.user.username)