예제 #1
0
def ajax_tab_counters(request,proveedor_id):
  current_user = request.user
  print current_user.id
  username = str(current_user.username)
  def_tabs = settings.DEF_TABS
  grouped_by = settings.GROUPED_BY
  proveedor = current_user.groups.all().exclude(name=PROVEEDOR_ATTRIBUTE)[0]
  html = ''
  if request.is_ajax():
    if str(proveedor.id) == proveedor_id:
      list_pedidos = Pedidos.objects.filter(proveedor_id = proveedor.id)
      #is ugly, but should make jinja easier
      lista_pedidos , tabs = list_grouper(list_pedidos)
      #counter_pedidos = Pedidos.objects.filter(proveedor_id = proveedor.id).values('pedidostate').annotate(total=Count('pedidostate'))
      print "lista_pedidos"
      print lista_pedidos
      print "tabs"
      print tabs
      for i in lista_pedidos:
        html += '<li class="{0}"><a href="#" onclick="gettab(\'{1}\')">'.format(i.replace(' ','-'), i.replace(' ','_') )
        html += i
        html += '<span class="badge">{0}</span>'.format(len(lista_pedidos[i]))
        html += ' </a></li>'
  print html 
  return HttpResponse(html)
예제 #2
0
def pedidos_proveedor(request):
  current_user = request.user
  print current_user.id
  username = str(current_user.username)
  current_page = "Clientes"
  proveedor = current_user.groups.all().exclude(name=PROVEEDOR_ATTRIBUTE)[0]
  client_list = User.objects.filter(groups__id=proveedor.id).exclude(groups__name=PROVEEDOR_ATTRIBUTE).exclude(cliente__baja=True).order_by('-id')
  #Count all of them, TODO:check how expensive if this query and think about options, fix the format, kills me :/
  #even better, think in cache the numbers in other place.. is not so accurate, but woudl work
  list_pedidos = Pedidos.objects.filter(proveedor_id = proveedor.id)
  #is ugly, but should make jinja easier
  search_parameters = request.POST.copy()
  lista_pedidos , tabs = list_grouper(list_pedidos)
  print "lista_pedidos"
  print lista_pedidos
  #if search_parameters:
  context= { 'username': username,
             'current_page': current_page,
             'proveedor': proveedor,
             'tabs': tabs,
             'lista_pedidos' : lista_pedidos,
              }
  return render(request, 'proveedor/pedidos_clientes_bootstrap_proveedor.html', context)