from django.shortcuts import render, redirect, get_object_or_404 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 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, }) 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() return render(request, 'slips/print_page.html', { 'order': order, 'pages': pages, 'date_formatted': order.production_date.strftime('%d/%m/%Y'), 'next_control_formatted': order.next_control_date.strftime('%d/%m/%Y'), 'calibration_css': css_vars(cal), }) 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'], })