from django.http import HttpResponse
from django.http import FileResponse
from django.shortcuts import render
from django.views import generic
from django.template import loader
from django.views.decorators.clickjacking import xframe_options_exempt

from vehicles.models import *
from rest_framework import viewsets
from Reskreen.rest_permission import CustomPermission_DjangoModel_based

from .serializers import cl_Vehicles_Serializer, cl_Vehicles_infos_Serializer

class VehicleViewset(viewsets.ModelViewSet):
    queryset = Vehicles.objects.all()
    serializer_class = cl_Vehicles_Serializer
    permission_classes = [CustomPermission_DjangoModel_based]

class VehicleViewset(viewsets.ModelViewSet):
    queryset = Vehicles.objects.all()
    serializer_class = cl_Vehicles_Serializer
    permission_classes = [CustomPermission_DjangoModel_based]

@xframe_options_exempt
def view_vhc(request):
    if not "target" in request.GET.keys():
        target = "_self"
    else:
        target = "_blank"

    template = loader.get_template("vhc/vhc.html")
    a_vhc = Vehicles.objects.all().order_by("nStatus","nOrder")
    context = {'list_vhc': a_vhc,'target':target}
    print("passs 1 ligne 12")


    return HttpResponse(template.render(context,request))

@xframe_options_exempt
def view_peremptions(request):
    if not "target" in request.GET.keys():
        target = "_self"
    else:
        target = "_blank"
    template = loader.get_template("vhc/peremptions.html")
    a_vhc = Vehicles.objects.all().order_by("nOrder")
    context = {'list_vhc': a_vhc,'target':target}
    print("passs 1 ligne 12")


    return HttpResponse(template.render(context,request))
