mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: websocket part1 (estudo)
This commit is contained in:
Binary file not shown.
@@ -40,27 +40,28 @@
|
||||
|
||||
<div id="Fila" class="tabcontent">
|
||||
{% for order in orders %}
|
||||
{% if order.preparing == None and order.productComanda != Null %}
|
||||
<div class="m-card"
|
||||
{% if order.productComanda == Null %}
|
||||
style="background-color: rgb(253, 69, 69);"
|
||||
{% elif order.obs != '' %}
|
||||
style="background-color: rgb(243, 165, 75);"
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4>{{order.obs}} </h4>
|
||||
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
|
||||
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
|
||||
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
|
||||
{% if user|groupUser:"Cozinha" %}
|
||||
<button class="btn-primary" onclick="delayTab('Fila')"
|
||||
hx-get="{% url 'preparing' order.id %} " hx-trigger="click" hx-target="#etapas"
|
||||
>Preparar</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if order.preparing == None and order.productComanda != Null %}
|
||||
<div class="m-card"
|
||||
{% if order.productComanda == Null %}
|
||||
style="background-color: rgb(253, 69, 69);"
|
||||
{% elif order.obs != '' %}
|
||||
style="background-color: rgb(243, 165, 75);"
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </h4>
|
||||
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
|
||||
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
|
||||
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
|
||||
{% if user|groupUser:"Cozinha" %}
|
||||
<button class="btn-primary" onclick="delayTab('Fila')"
|
||||
hx-get="{% url 'preparing' order.id %} " hx-trigger="click" hx-target="#etapas"
|
||||
>Preparar</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<!-- <output id="fila"></output> -->
|
||||
</div>
|
||||
|
||||
|
||||
@@ -75,7 +76,7 @@
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4>{{order.obs}} </h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </h4>
|
||||
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
|
||||
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
|
||||
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
|
||||
@@ -100,7 +101,7 @@
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4>{{order.obs}} </h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </h4>
|
||||
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
|
||||
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
|
||||
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
|
||||
@@ -125,7 +126,7 @@
|
||||
{% endif %}
|
||||
>
|
||||
<h4>{{order.id_product.name}}</h4>
|
||||
<h4>{{order.obs}} </h4>
|
||||
<h4 id="obs-{{order.id}}">{{order.obs}} </h4>
|
||||
<h4>{{order.id_comanda.name}} - {{order.id_comanda.mesa.name}} </h4>
|
||||
<h4> Atendente: {{order.id_comanda.user.first_name}} </h4>
|
||||
<h4>{{order.queue|date:"D"}} {{order.queue|date:"d/m/Y - H:i"}}</h4>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import render
|
||||
from django.http import JsonResponse, HttpResponse
|
||||
import asyncio
|
||||
import websockets
|
||||
|
||||
|
||||
from orders.models import Order
|
||||
@@ -9,6 +11,18 @@ from django.db.models import Q
|
||||
from gestaoRaul.decorators import group_required
|
||||
|
||||
|
||||
async def enviar_mensagem(message):
|
||||
uri = "ws://localhost:8765" # Substitua pela URI do seu servidor WebSocket
|
||||
async with websockets.connect(uri) as websocket:
|
||||
await websocket.send(message)
|
||||
print(f"> Enviado: {message}")
|
||||
|
||||
resposta = await websocket.recv()
|
||||
print(f"< Recebido: {resposta}")
|
||||
|
||||
|
||||
|
||||
|
||||
def viewsOrders(request):
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
orders = Order.objects.filter(queue__gte=fifteen_hours_ago )
|
||||
@@ -31,6 +45,7 @@ def finished(request, order_id):
|
||||
order.save()
|
||||
fifteen_hours_ago = timezone.now() - timezone.timedelta(hours=15)
|
||||
orders = Order.objects.filter(queue__gte=fifteen_hours_ago )
|
||||
asyncio.run(enviar_mensagem())
|
||||
return render(request, 'htmx_components/orders/htmx_list_orders_fila.html',{'orders': orders})
|
||||
|
||||
@group_required(groupName='Garçom')
|
||||
|
||||
Reference in New Issue
Block a user