diff --git a/movere_local/mainapp/templates/mainapp/view_orders.html b/movere_local/mainapp/templates/mainapp/view_orders.html index 4478bb31985cc6b75c1c164901205de098b564b5..3e255f65e34d2f85773e48bdf37c96958b1c90aa 100644 --- a/movere_local/mainapp/templates/mainapp/view_orders.html +++ b/movere_local/mainapp/templates/mainapp/view_orders.html @@ -21,18 +21,36 @@ width: 20%; } </style> + <script> + function confirmCancel(orderId) { + if (confirm('Вы уверены, что хотите отменить этот заказ?')) { + document.getElementById('cancel-form-' + orderId).submit(); + } + } + </script> </head> <body> <h1>Список заказов</h1> <a href="{% url 'create_order' %}" style="display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: white; text-decoration: none; border-radius: 5px;">Создать новый заказ</a> <button onclick="location.href='{% url 'home' %}'">Домой</button> + <table> <thead> <tr> {% for status, _ in orders_status_list %} <th class="status-column"> - {% if status == 'wait_confirmation' %}Ожидает подтверждения{% elif status == 'in_work' %}Отправлен на печать{% elif status == 'ready' %}Готов{% elif status == 'done' %}Выполнен{% elif status == 'canceled' %}Отменен{% endif %} + {% if status == 'wait_confirmation' %} + Ожидает подтверждения + {% elif status == 'in_work' %} + Отправлен на печать + {% elif status == 'ready' %} + Готов + {% elif status == 'done' %} + Выполнен + {% elif status == 'canceled' %} + Отменен + {% endif %} </th> {% endfor %} </tr> @@ -48,9 +66,15 @@ Заказ ID: {{ order.id }} <br> Дата: {{ order.order_datetime }} <br> Параметры: {{ order.order_parameters }} <br> - Файл: {% if order.file_basename %}{{ order.file_basename }}{% else %}Нет файла{% endif %} + Файл: {% if order.file_basename %}{{ order.file_basename }}{% else %}Нет файла{% endif %} <br> - {% if order.order_state == 'done' or order.order_state == 'canceled' %} + {% if order.order_state == 'wait_confirmation' %} + <!-- Кнопка для отмены заказа с подтверждением --> + <button onclick="confirmCancel({{ order.id }})">Отменить заказ</button> + <form id="cancel-form-{{ order.id }}" method="post" action="{% url 'cancel_order' order.id %}" style="display: none;"> + {% csrf_token %} + </form> + {% elif order.order_state == 'done' or order.order_state == 'canceled' %} <form method="post" action="{% url 'archive_order' order.id %}"> {% csrf_token %} <button type="submit">В архив</button> diff --git a/movere_local/mainapp/urls.py b/movere_local/mainapp/urls.py index 61666899a9aeec9cbfc664e9184d98e2f29f0a30..26f30ed7a4fe30a24ec404f90466382e3c6a69d1 100644 --- a/movere_local/mainapp/urls.py +++ b/movere_local/mainapp/urls.py @@ -22,7 +22,7 @@ urlpatterns = [ path('api/orders/', views.order_list_api, name='order_list_api'), path('download-file/<path:file_name>/', views.download_file, name='download_file'), path('api/mark-order-processed/<int:order_id>/', views.mark_order_as_processed, name='mark_order_as_processed'), - + path('cancel_order/<int:order_id>/', views.cancel_order, name='cancel_order'), # path('serve-file/<str:file_name>/', views.serve_file, name='serve_file'), # re_path(r'^download-file/(?P<path>.*)$', views.download_file, name='download_file'), # re_path(r'^serve-file/(?P<path>.*)$', views.download_file, name='download_file') diff --git a/movere_local/mainapp/views.py b/movere_local/mainapp/views.py index 6514ac220130919f44fa85878d0fed5c66d6fa91..aeefa511486025b20ec2254df0676d187ee6b63e 100644 --- a/movere_local/mainapp/views.py +++ b/movere_local/mainapp/views.py @@ -374,4 +374,20 @@ def serve_file(request, file_name): print(file_path) if not os.path.exists(file_path): raise Http404("File not found") - return FileResponse(open(file_path, 'rb')) \ No newline at end of file + return FileResponse(open(file_path, 'rb')) + + +@login_required +# @require_POST +def cancel_order(request, order_id): + # Получаем заказ или возвращаем 404, если не найден + order = get_object_or_404(Order, id=order_id, user=request.user) + + # Проверяем, что заказ находится в состоянии "ожидания подтверждения" + if order.order_state == 'wait_confirmation': + # Меняем статус на "отменен" + order.order_state = 'canceled' + order.save() + + # Возвращаем пользователя на страницу заказов + return redirect('view_orders') \ No newline at end of file