Commit d241bc3e authored by “Mikkelando”'s avatar “Mikkelando”
Browse files

added cancelation of order on wait_confiramation stage

Showing with 45 additions and 5 deletions
+45 -5
......@@ -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>
......
......@@ -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')
......
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment