from django.shortcuts import render

# Create your views here.
from order.models import Order_DesignData
from schedule.models import Knit_Process, Warp_Process, Knit_Machine_Realtime, Warp_Machine_Realtime



def production(request):

    title = 'Production'

    designOrderList = Order_DesignData.objects.all().order_by('-id')

    return render(request, 'production.html', {'title':title, 'designOrderList':designOrderList})



def productionDetail(request, pk):

    designOrder = Order_DesignData.objects.get(id=pk)

    try:
        wProcess = Warp_Process.objects.get(order_designdata=pk)
        wSchedule = True
        wRealTime = Warp_Machine_Realtime.objects.get(knit_process=wProcess)
    except:
        wSchedule = False

    try:
        kProcess = Knit_Process.objects.get(order_designdata=pk)
        kSchedule = True
        kRealTime = Knit_Machine_Realtime.objects.get(knit_process=kProcess)
    except:
        kSchedule = False


    variables = {'title':'Production', 'designOrder':designOrder, 'kSchedule':kSchedule, 'wSchedule':wSchedule }


    return render(request, 'productionDetail.html', variables)
