import logging
from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import cache_page

logger = logging.getLogger(__name__)


class CacheMixin(object):
    """
    Caches class based views.
    """
    cache_timeout = 60

    def get_cache_timeout(self):
        return self.cache_timeout

    def dispatch(self, *args, **kwargs):
        return cache_page(self.get_cache_timeout())(super(CacheMixin, self).dispatch)(*args, **kwargs)


class LoginRequiredMixin(object):
    """
    Requires users to be logged in before rendering a view.
    """

    @classmethod
    def as_view(cls, **initkwargs):
        view = super(LoginRequiredMixin, cls).as_view(**initkwargs)
        return login_required(view)
import logging
from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import cache_page

logger = logging.getLogger(__name__)


class CacheMixin(object):
    """
    Caches class based views.
    """
    cache_timeout = 60

    def get_cache_timeout(self):
        return self.cache_timeout

    def dispatch(self, *args, **kwargs):
        return cache_page(self.get_cache_timeout())(super(CacheMixin, self).dispatch)(*args, **kwargs)


class LoginRequiredMixin(object):
    """
    Requires users to be logged in before rendering a view.
    """

    @classmethod
    def as_view(cls, **initkwargs):
        view = super(LoginRequiredMixin, cls).as_view(**initkwargs)
        return login_required(view)
Caches class based views. Requires users to be logged in before rendering a view.