from django.shortcuts import render
from django.views.generic import TemplateView

from containers.models import Container


class BarrierDashboardView(TemplateView):
    template_name = 'barrier/barrier-dashboard.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        recent_containers = Container.objects.select_related('line', 'booking').order_by('-expedited_on', '-received_on')[:10]
        context['recent_containers'] = recent_containers
        return context

    def get(self, request, *args, **kwargs):
        return render(request, self.template_name, self.get_context_data())