добавил детальный вид итема, пока недопиленый
All checks were successful
Deploy MES Core / deploy (push) Successful in 8s

This commit is contained in:
tertelius
2026-03-29 02:49:28 +03:00
parent a4ba577206
commit b256bec04b
15 changed files with 539 additions and 226 deletions

View File

@@ -1,5 +1,6 @@
from django.shortcuts import redirect
from django.views.generic import TemplateView, ListView
from django.urls import reverse_lazy
from django.views.generic import TemplateView, ListView, UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Item # Проверь, как точно называется твоя модель деталей/заказов
@@ -17,16 +18,40 @@ class IndexView(TemplateView):
# Класс реестра деталей (защищен LoginRequiredMixin)
class RegistryView(LoginRequiredMixin, ListView):
model = Item
template_name = 'shiftflow/items_list.html'
template_name = 'shiftflow/registry.html'
context_object_name = 'items'
def get_queryset(self):
# Позже здесь добавим: .filter(machine__in=request.user.profile.machines.all())
return Item.objects.all().order_by('-id')
# Сортируем: сначала статус (по алфавиту или логике choices),
# затем по дате (свежие сверху), по станку и по номеру сделки
return Item.objects.all().order_by('status', '-date', 'machine__name', 'deal__number')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Передаем роль в шаблон, чтобы скрывать/показывать кнопки
if hasattr(self.request.user, 'profile'):
context['user_role'] = self.request.user.profile.role
return context
return context
# Вьюха детального вида и редактирования
class ItemUpdateView(LoginRequiredMixin, UpdateView):
model = Item
template_name = 'shiftflow/item_detail.html'
# Перечисляем поля, которые можно редактировать (укажи нужные)
fields = [
'drawing_name', 'machine', 'quantity_plan', 'quantity_fact',
'material', 'size_value', 'status', 'is_synced_1c', 'extra_drawing'
]
context_object_name = 'item'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Обязательно добавляем роль в контекст этого шаблона!
if hasattr(self.request.user, 'profile'):
context['user_role'] = self.request.user.profile.role
return context
def get_success_url(self):
# После сохранения возвращаемся в реестр
return reverse_lazy('registry')