def add_vendor(request): info = {} context_instance = RequestContext(request) form = VendorForm() if request.method == "POST": print request.POST form = VendorForm(request.POST) res = save_vendor(request.POST) if res: messages.success(request,'New vendor added.') else: messages.warning(request,'Error adding new vendor.') return redirect('add_vendor') info['form'] = form info['heading'] = 'New Vendor' return render_to_response('interface/vendor_add.html', info, context_instance)
def edit_vendor(request, vid=None): if not vid: return redirect('vendors') info = {} context_instance = RequestContext(request) vendor = Vendor.objects.get(id=vid) form = VendorForm(initial={ 'company':vendor.company, 'nature_of_business':vendor.business_nature.id, 'address1':vendor.address1, 'address2':vendor.address2, 'city_municipality':vendor.city_municipality, 'state_region_province':vendor.state_region_province, 'country':vendor.country.id, 'telephone':vendor.telephone, 'fax':vendor.fax, 'date_accredited':vendor.date_accredited}) if request.method == "POST": form = VendorForm(request.POST) if form.is_valid(): data = {} data = form.cleaned_data data['id'] = vid res = save_vendor(data) if res: messages.success(request,'Edit vendor success.') else: messages.warning(request,'Error editing vendor.') return redirect('add_vendor') info['form'] = form info['heading'] = 'Edit Vendor' return render_to_response('interface/vendor_add.html', info, context_instance)