начал работать с интерфейсом
All checks were successful
Deploy MES Core / deploy (push) Successful in 9s
All checks were successful
Deploy MES Core / deploy (push) Successful in 9s
This commit is contained in:
72
shiftflow/views copy.py
Normal file
72
shiftflow/views copy.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from django.shortcuts import render
|
||||
from .models import Item, Machine
|
||||
from django.utils import timezone
|
||||
from datetime import datetime
|
||||
|
||||
def items_list_view(request):
|
||||
# Если не авторизован, просто отдаем пустой контекст для страницы входа
|
||||
if not request.user.is_authenticated:
|
||||
return render(request, 'shiftflow/items_list.html', {})
|
||||
|
||||
# ОПРЕДЕЛЕНИЕ РОЛИ (Ищем в группах Джанго или ставим суперюзера)
|
||||
user_role = 'guest'
|
||||
if request.user.is_superuser:
|
||||
user_role = 'admin'
|
||||
elif request.user.groups.filter(name='Технолог').exists():
|
||||
user_role = 'technologist'
|
||||
elif request.user.groups.filter(name='Мастер').exists():
|
||||
user_role = 'master'
|
||||
elif request.user.groups.filter(name='Оператор').exists():
|
||||
user_role = 'operator'
|
||||
elif request.user.groups.filter(name='Учетчик').exists():
|
||||
user_role = 'clerk'
|
||||
|
||||
# ФИЛЬТРЫ
|
||||
all_machines = Machine.objects.all()
|
||||
all_machine_ids = list(all_machines.values_list('id', flat=True))
|
||||
|
||||
# Проверяем, был ли нажат фильтр (есть ли параметр 'filtered' в URL)
|
||||
is_filtered = 'filtered' in request.GET
|
||||
|
||||
if is_filtered:
|
||||
selected_machines = [int(x) for x in request.GET.getlist('m_ids')]
|
||||
selected_statuses = request.GET.getlist('statuses')
|
||||
start_date = request.GET.get('start_date')
|
||||
end_date = request.GET.get('end_date')
|
||||
else:
|
||||
# Значения по умолчанию (при первом заходе или сбросе)
|
||||
selected_machines = all_machine_ids
|
||||
selected_statuses = ['work', 'partial'] # В работе и недоделы
|
||||
start_date = timezone.now().strftime('%Y-%m-%d')
|
||||
end_date = timezone.now().strftime('%Y-%m-%d')
|
||||
|
||||
# ВЫБОРКА ДАННЫХ
|
||||
items = Item.objects.select_related('deal', 'material', 'machine')
|
||||
|
||||
# Защита логики: если станки не выбраны — список пуст
|
||||
if not selected_machines:
|
||||
items = Item.objects.none()
|
||||
else:
|
||||
items = items.filter(
|
||||
machine_id__in=selected_machines,
|
||||
status__in=selected_statuses,
|
||||
date__range=[start_date, end_date]
|
||||
)
|
||||
|
||||
# Разбиваем по статусам для вывода в разные таблицы (если они выбраны в фильтре)
|
||||
in_work = items.filter(status='work') if 'work' in selected_statuses else None
|
||||
backlog = items.filter(status='partial') if 'partial' in selected_statuses else None
|
||||
done_items = items.filter(status='done') if 'done' in selected_statuses else None
|
||||
|
||||
context = {
|
||||
'user_role': user_role,
|
||||
'machines': all_machines,
|
||||
'selected_machines': selected_machines,
|
||||
'selected_statuses': selected_statuses,
|
||||
'start_date': start_date,
|
||||
'end_date': end_date,
|
||||
'in_work': in_work,
|
||||
'backlog': backlog,
|
||||
'done_items': done_items,
|
||||
}
|
||||
return render(request, 'shiftflow/items_list.html', context)
|
||||
Reference in New Issue
Block a user