@treeio_login_required
@handle_response_format
@module_admin_required('treeio.sales')
def product_add(request, parent_id=None, response_format='html'):
 all_products = Object.filter_by_request(request, Product.objects.filter(parent__isnull=True))
 if request.POST:
  if ('cancel' not in request.POST):
   product = Product()
   form = ProductForm(request.user.profile, None, request.POST, instance=product)
   if form.is_valid():
    product = form.save()
    product.set_user_from_request(request)
    return HttpResponseRedirect(reverse('sales_product_view', args=[product.id]))
  else:
   return HttpResponseRedirect(reverse('sales_product_index'))
 else:
  form = ProductForm(request.user.profile, parent_id)
 return render_to_response('sales/product_add', {'form': form, 'products': all_products}, context_instance=RequestContext(request), response_format=response_format)

@ treeio_login_required @ handle_response_format @ module_admin_required ( 'treeio.sales' ) def product_add ( request , parent_id = None , response_format = 'html' ) : all_products = Object . filter_by_request ( request , Product . objects . filter ( parent__isnull = True ) ) if request . POST : if ( 'cancel' not in request . POST ) : product = Product ( ) form = ProductForm ( request . user . profile , None , request . POST , instance = product ) if form . is_valid ( ) : product = form . save ( ) product . set_user_from_request ( request ) return HttpResponseRedirect ( reverse ( 'sales_product_view' , args = [ product . id ] ) ) else : return HttpResponseRedirect ( reverse ( 'sales_product_index' ) ) else : form = ProductForm ( request . user . profile , parent_id ) return render_to_response ( 'sales/product_add' , { 'form' : form , 'products' : all_products } , context_instance = RequestContext ( request ) , response_format = response_format )
product add .