# Imports
from django.template.response import TemplateResponse
from django.views import View
import logging
from superdjango.exceptions import IMustBeMissingSomething
from .base import UIBaseMixin
log = logging.getLogger(__name__)
# Exports
__all__ = (
"UITemplateView",
)
# Classes
# noinspection PyAbstractClass
[docs]class UITemplateView(UIBaseMixin, View):
verb = None
"""Set this to the action represented by your view. Returned by ``get_verb()``, but will raise an error if left as
``None``.
"""
# noinspection PyUnusedLocal
def get(self, request, *args, **kwargs):
# noinspection PyAttributeOutsideInit
self.request = request
context = self.get_context_data()
return self.render_to_response(context)
[docs] def get_verb(self):
"""Return the verb attribute.
:rtype: str
:raise: IMustBeMissingSomething
"""
if self.verb is not None:
return self.verb
raise IMustBeMissingSomething(self.__class__.__name__, "verb")
[docs] def render_to_response(self, context):
"""Render the current context.
:param context: The context variables to use for rendering.
:rtype: TemplateResponse
"""
return TemplateResponse(self.request, self.get_template_names(), context=context)