Beispiel #1
0
def add_supplier(request):
  context_vars = dict()
  context_vars['header'] = capfirst(_('add new supplier'))
  form = SupplierForm()
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = SupplierForm(request.POST, request.FILES)
    if form.is_valid():
      supplier = Supplier()
      supplier.name = form.cleaned_data['name']
      supplier.address = form.cleaned_data['address']
      supplier.postal_address = form.cleaned_data['postal_address']
      supplier.phone = form.cleaned_data['phone']
      supplier.fax = form.cleaned_data['fax']
      supplier.website = form.cleaned_data['website']
      supplier.referral_source = form.cleaned_data['referral_source']
      supplier = supplier.save()
      return HttpResponseRedirect(reverse('workflowmax-supplier', args=[supplier.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
Beispiel #2
0
def edit_supplier(request, object_id):
  try:
    object_id = int(object_id)
  except ValueError:
    return HttpResponseRedirect(reverse('workflowmax-supplier-list'))
  context_vars = dict()
  context_vars['header'] = '%s %d' % (capfirst(_('supplier')), object_id)
  supplier = Supplier.objects.get(id=object_id)
  form = SupplierForm(supplier.to_dict())
  helper = FormHelper()
  helper.form_class = 'uniform'
  submit = Submit('save',_('save'))
  helper.add_input(submit)
  if request.method == "POST":
    form = SupplierForm(request.POST, request.FILES)
    if form.is_valid():
      supplier.name = form.cleaned_data['name']
      supplier.address = form.cleaned_data['address']
      supplier.postal_address = form.cleaned_data['postal_address']
      supplier.phone = form.cleaned_data['phone']
      supplier.fax = form.cleaned_data['fax']
      supplier.website = form.cleaned_data['website']
      supplier.referral_source = form.cleaned_data['referral_source']
      supplier.save()
      return HttpResponseRedirect(reverse('workflowmax-supplier', args=[supplier.id]))
  
  context_vars['form'] = form
  context_vars['helper'] = helper
  return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)