"""Cloud browser views."""
from django.http import HttpResponse, Http404
from django.shortcuts import render

try:
    # pylint: disable=no-name-in-module, import-error
    from django.utils.importlib import import_module
except ImportError:
    from importlib import import_module

from cloud_browser.app_settings import settings
from cloud_browser.cloud import get_connection, get_connection_cls, errors
from cloud_browser.common import get_int, \
    path_parts, path_join, path_yield, relpath

MAX_LIMIT = get_connection_cls().cont_cls.max_list


def settings_view_decorator(function):
    """Insert decorator from settings, if any.

    .. note:: Decorator in ``CLOUD_BROWSER_VIEW_DECORATOR`` can be either a
        callable or a fully-qualified string path (the latter, which we'll
        lazy import).
    """

    dec = settings.CLOUD_BROWSER_VIEW_DECORATOR

    # Trade-up string to real decorator.
    if isinstance(dec, str):
        # Split into module and decorator strings.
Esempio n. 2
0
"""Cloud browser views."""
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response
from django.template import RequestContext

from cloud_browser.app_settings import settings
from cloud_browser.cloud import get_connection, get_connection_cls, errors
from cloud_browser.common import get_int, \
    path_parts, path_join, path_yield, relpath


MAX_LIMIT = get_connection_cls().cont_cls.max_list


def settings_view_decorator(function):
    """Insert decorator from settings, if any."""

    dec = settings.CLOUD_BROWSER_VIEW_DECORATOR
    if dec:
        if callable(dec):
            # An actual callable was supplied.
            # CLOUD_BROWSER_VIEW_DECORATOR = staff_member_required
            return dec(function)

        elif isinstance(dec, basestring):
            # A dot path to a callable was supplied.
            # CLOUD_BROWSER_VIEW_DECORATOR = 'django.contrib.admin.views.decorators.staff_member_required'
            dec_path = dec.split('.')
            module_str = '.'.join(dec_path[0:-1])
            dec_str = dec_path[-1]