def edit(request, **kwargs): """ Edit a facility """ controller = infrastructure.facility_cntrl.FacilityController() facility = controller.getFacility(kwargs.get('facility_id')) existing = True save_error_name = None if request.method == "POST": form = FacilityForm(request.POST, existing_flag=existing) if form.is_valid(): try: form.save(facility) return redirect('/infrastructure/index/?msg=Successfully updated') except: save_error_name = "The name selected is an existing facility, please try again." else: if facility: form = FacilityForm(instance=facility) else: form = FacilityForm() return render_to_response( 'infrastructure/add.html', { 'existing':True, 'form':form, 'message':save_error_name, }, context_instance=RequestContext(request) )
def add(request): """ Add a facility """ if request.method == "POST": form = FacilityForm(request.POST) if form.is_valid(): form.save(False) return redirect('/infrastructure/index/?msg=Successfully created a new facility') else: form = FacilityForm() return render_to_response( 'infrastructure/add.html', { 'form':form, }, context_instance=RequestContext(request) )