Files
product-slip/slips/views.py
2026-10-14 12:06:12 +03:30

62 lines
1.9 KiB
Python

from django.shortcuts import render, redirect, get_object_or_404
from django.views.decorators.cache import never_cache
from .calibration import css_vars, load_calibration
from .models import Product, Order
from .print_layout import build_print_pages
def index(request):
return redirect('entry')
def entry(request):
products = Product.objects.all()
orders = Order.objects.select_related('product').all()[:20]
return render(request, 'slips/entry.html', {
'products': products,
'orders': orders,
})
def products(request):
return render(request, 'slips/products.html', {
'products': Product.objects.all(),
})
def print_queue(request):
pending = Order.objects.select_related('product').filter(status='pending')
history = Order.objects.select_related('product').filter(status='done').order_by('-printed_at')[:20]
return render(request, 'slips/print.html', {
'pending_orders': pending,
'history_orders': history,
})
@never_cache
def print_page(request, order_id):
order = get_object_or_404(Order.objects.select_related('product'), id=order_id)
pages = build_print_pages(order)
cal = load_calibration()
show_dates = order.product.requires_dates
return render(request, 'slips/print_page.html', {
'order': order,
'pages': pages,
'show_dates': show_dates,
'date_formatted': order.production_date.strftime('%d/%m/%Y') if order.production_date else '',
'next_control_formatted': order.next_control_date.strftime('%d/%m/%Y') if order.next_control_date else '',
'calibration_css': css_vars(cal),
})
@never_cache
def calibrate(request):
cal = load_calibration()
return render(request, 'slips/calibrate.html', {
'calibration': cal,
'calibration_css': css_vars(cal),
'calibration_json': cal,
'quadrants': ['TL', 'TR', 'BL', 'BR'],
})