fellipeh

Untitled

Aug 22nd, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. @login_required(login_url='/login/')
  2. def EditaPedido(request, pedido_id=None):
  3.     profile = request.user.get_profile()
  4.  
  5.     if pedido_id:
  6.         vPedido = Pedido.objects.using(profile.dbname).get(idpedido=pedido_id)
  7.     else:
  8.         vPedido = None
  9.  
  10.     ItensInlineFormSet = inlineformset_factory(Pedido, ItensPedido, form=PedidoItensForm,
  11.                                                extra=1, fk_name='idpedido')
  12.  
  13.     if request.method == "POST":
  14.         formPedido = PedidoForm(request.POST, vUserProfile=profile)
  15.     else:
  16.         formPedido = PedidoForm(vUserProfile=profile, instance=vPedido)
  17.         formsetItens = ItensInlineFormSet(instance=vPedido)
  18.  
  19.     vMercadoria = Mercadoria.objects.using(profile.dbname).filter(status='A')
  20.                     # .filter(idsys_point_cliente=profile.idsys_point_cliente)\
  21.                     # .filter(idempresa=profile.idempresa)\
  22.  
  23.  
  24.     vProduto = Produto.objects.using(profile.dbname).all()
  25.     # vitens = ItensPedido.objects.using(profile.dbname).filter(idpedido=pedido_id).select_related()
  26.  
  27.     return render_to_response("edit_pedido.html", {
  28.         "formPedido": formPedido,  "formsetItens": formsetItens,
  29.         "vMercadoria": vMercadoria, "vProduto": vProduto
  30.     }, context_instance=RequestContext(request), )
  31.  
  32.  
  33.  
  34. HTML:
  35.  
  36.       <fieldset>
  37.         <legend>Itens do pedido</legend>
  38.         <a href="#" class="tiny button" onclick="abreModal()">Novo Item</a>
  39.           <table id="grid_itens" class="dataTable">
  40.             <thead>
  41.                 <tr>
  42.                     <th>Referência</th>
  43.                     <th>Produto</th>
  44.                     <th>Cor</th>
  45.                     <th>Qtde</th>
  46.                     <th>Preço Unit.</th>
  47.                     <th>Preço Total</th>
  48.                     <th>Excluir</th>
  49.                 </tr>
  50.             </thead>
  51.             <tbody>
  52.             {% for itens in formsetItens.forms %}
  53.               <tr>
  54.                 <td> </td>
  55.                 <td>{{ itens.idproduto.value }}</td>
  56.                 <td>{{ itens.idproduto__idcor__descricao.value }}</td>
  57.                 <td>{{ itens.quantidade.value }}</td>
  58.                 <td>xxxx</td>
  59.                 <td>xxxxx</td>
  60.                 <td>Excluir</td>
  61.               </tr>
  62.             {% endfor %}
  63.  
  64.             </tbody>
  65.             <tfoot>
  66.                 <tr>
  67.                     <th></th>
  68.                     <th></th>
  69.                     <th></th>
  70.                     <th>9999</th>
  71.                     <th></th>
  72.                     <th>9999,00</th>
  73.                     <th></th>
  74.                 </tr>
  75.             </tfoot>
  76.         </table>
  77.       </fieldset>
  78.       {{ formsetItens.management_form }}
Advertisement
Add Comment
Please, Sign In to add comment