Python django.utils.decorators 模块,method_decorator() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用django.utils.decorators.method_decorator()

项目:mendelmd    作者:raonyguimaraes    | 项目源码 | 文件源码
def get_queryset(self, **kwargs):
        name = self.request.GET.get('name', '')    
        return Disease.objects.filter(Q(name__icontains=name)|Q(gene_names__icontains=name))

    # @method_decorator(login_required)
    # def dispatch(self, *args, **kwargs):
    #     return super(DiseaseListView, self).dispatch(*args, **kwargs)
项目:Server    作者:malaonline    | 项目源码 | 文件源码
def dispatch(self, request, *args, **kwargs):
        return super(Sms, self).dispatch(request, *args, **kwargs)

    # @method_decorator(csrf_exempt) # here it doesn't work
项目:Server    作者:malaonline    | 项目源码 | 文件源码
def setSidebarContent(self, teacher, context):
        side_bar_content = SideBarContent(teacher)
        side_bar_content(context)

    # @method_decorator(user_passes_test(is_teacher_logined, login_url=LOGIN_URL))
项目:Server    作者:malaonline    | 项目源码 | 文件源码
def handle_get(self, request, user, teacher, *args, **kwargs):
        raise Exception("get not implement")

    # @method_decorator(user_passes_test(is_teacher_logined, login_url=LOGIN_URL))
项目:litchi    作者:enfancemill    | 项目源码 | 文件源码
def get(self, request):
        captcha_key = CaptchaStore.generate_key()
        captcha_url = captcha_image_url(captcha_key)
        context = {
            'captcha_key': captcha_key,
            'captcha_url': captcha_url,
        }
        return render(request, 'login.html', context)

    #@method_decorator(nonlogin_required)
项目:python-panopticon    作者:mobify    | 项目源码 | 文件源码
def track_time(cls, metric_name=None):
        """
        A decorator that tracks execution time for any wrapped function.

        The `metric_name` is optional and will default to the function name. In
        both cases, they full metric name will include the
        `DATADOG_STATS_PREFIX`.

        To apply this decorator to a class' method, use the Django utility
        decorator `method_decorator`::

            from django.utils.decorators import method_decorator
            from brain.monitoring.datadog import DataDog

            class SomeClass(object):

                @method_decorator(DataDog.track_time)
                def method_to_wrap(self, *args, **kwargs):
                    pass

        """

        def track_time_decorator(func):
            name = metric_name or func.__name__

            @wraps(func)
            def wrapped_func(*args, **kwargs):
                start = time.time()
                result = func(*args, **kwargs)
                request_time = time.time() - start

                metric_name = cls.get_metric_name(name)
                cls.stats().histogram(metric_name, request_time)

                return result

            return wrapped_func

        return track_time_decorator
项目:hydra    作者:Our-Revolution    | 项目源码 | 文件源码
def class_view_decorator(function_decorator):
    """Convert a function based decorator into a class based decorator usable
    on class based Views.

    Can't subclass the `View` as it breaks inheritance (super in particular),
    so we monkey-patch instead.
    """

    def simple_decorator(View):
        View.dispatch = method_decorator(function_decorator)(View.dispatch)
        return View

    return simple_decorator
项目:django-chartwerk    作者:DallasMorningNews    | 项目源码 | 文件源码
def secure(view):
    """Set an auth decorator applied for views.

    If DEBUG is on, we serve the view without authenticating.

    Default is 'django.contrib.auth.decorators.login_required'.
    Can also be 'django.contrib.admin.views.decorators.staff_member_required'
    or a custom decorator.
    """
    auth_decorator = import_class(app_settings.AUTH_DECORATOR)
    return (
        view if settings.DEBUG
        else method_decorator(auth_decorator, name='dispatch')(view)
    )
项目:Sermul    作者:CHOQUERC    | 项目源码 | 文件源码
def get_success_url(self):
        return reverse('home:listar_usuarios')

    # @method_decorator(login_required)
    # def dispatch(self, *args, **kwargs):
    #     return super(EditUser, self).dispatch(*args, **kwargs)
项目:Sermul    作者:CHOQUERC    | 项目源码 | 文件源码
def get_context_data(self, **kwargs):
        context = super(ListUsers, self).get_context_data(**kwargs)
        context['clientes'] = Cliente.objects.all()
        return context
    # @method_decorator(login_required)
    # def dispatch(self, *args, **kwargs):
    #     return super(ListUsers, self).dispatch(*args, **kwargs)