from django.views.generic import TemplateView


class StyleGuidePageView(TemplateView):
    """
    This class allows us to display templates by simply passing their name
    in the URL, so a non-Python developer can create arbitrary pages.
    """

    def get_template_names(self):
        """
        Return the list of appropriate templates to render this view.
        That means, in fact, a list of ONE template, deduced from the
        ``page_name`` kwarg extracted from the URL.
        """

        # We get the page name in the URL...
        page_name = self.kwargs.get('page_name') or 'index'

        # ... we deduce the matching template name...
        template_name = 'style/%s.html' % page_name

        # ... and we return it as a single-element list.
        return [template_name]
