"""
Define the views for the Django MVC
"""

from django import template
from django.views import generic

from three_d_viewer.models import Sample, Category
register = template.Library()


class HomeView(generic.ListView):
    """
    Show the home page
    """

    template_name = 'three_d_viewer/home.html'
    model = Sample

    def get_context_data(self, **kwargs):
        context = super(HomeView, self).get_context_data(**kwargs)
        context['active_samples'] = Sample.objects.filter(active=True)
        context['parent_categories'] = Category.objects.filter(parent=None). \
            filter(active=True)
        return context


class DetailView(generic.DetailView):
    """
    Define the view to view the 3D model of a sample
    """

    model = Sample
    template_name = 'three_d_viewer/detail.html'
    parent_categories = Category.objects.filter(parent=None). \
        filter(active=True)

    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        context['active_samples'] = Sample.objects.filter(active=True)
        context['parent_categories'] = Category.objects.filter(parent=None). \
            filter(active=True)
        return context
