"""This module contains the views of the ``cms`` app"""

from django.conf import settings
from django.http import HttpResponse
from django.views.generic import TemplateView, View

from mtp.apps.common.views_utils import LoginRequiredMixin


class Index(LoginRequiredMixin, TemplateView):
    """Index page for the cms"""

    template_name = 'cms/index.html'


class LastIpaVersion(View):
    """View to redirect the user to the last available IPA version"""

    def get(self, request, *args, **kwargs):  # pylint: disable=unused-argument
        """Build the last IPA url and issue a redirect to it

        For the parameters, see ``django.views.generic.View``

        Returns
        -------
        HttpResponse

        """

        url = settings.LAST_IPA_VERSION_DETAIL_URL

        response = HttpResponse('', status=302)
        response['Location'] = url

        return response
