当前位置: 首页>>代码示例>>Python>>正文


Python functional.lazy方法代码示例

本文整理汇总了Python中django.utils.functional.lazy方法的典型用法代码示例。如果您正苦于以下问题:Python functional.lazy方法的具体用法?Python functional.lazy怎么用?Python functional.lazy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.functional的用法示例。


在下文中一共展示了functional.lazy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: csrf

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def csrf(request):
    """
    Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
    it has not been provided by either a view decorator or the middleware
    """
    def _get_val():
        token = get_token(request)
        if token is None:
            # In order to be able to provide debugging info in the
            # case of misconfiguration, we use a sentinel value
            # instead of returning an empty dict.
            return 'NOTPROVIDED'
        else:
            return smart_text(token)
    _get_val = lazy(_get_val, six.text_type)

    return {'csrf_token': _get_val()} 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:context_processors.py

示例2: csrf

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def csrf(request):
    """
    Context processor that provides a CSRF token, or the string 'NOTPROVIDED' if
    it has not been provided by either a view decorator or the middleware
    """
    def _get_val():
        token = get_token(request)
        if token is None:
            # In order to be able to provide debugging info in the
            # case of misconfiguration, we use a sentinel value
            # instead of returning an empty dict.
            return 'NOTPROVIDED'
        else:
            return smart_text(token)
    _get_val = lazy(_get_val, six.text_type)

    return {'csrf_token': _get_val() } 
开发者ID:blackye,项目名称:luscan-devel,代码行数:19,代码来源:context_processors.py

示例3: __init__

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def __init__(self, **kwargs):
        self.allow_blank = kwargs.pop('allow_blank', False)
        self.trim_whitespace = kwargs.pop('trim_whitespace', True)
        self.max_length = kwargs.pop('max_length', None)
        self.min_length = kwargs.pop('min_length', None)
        super(CharField, self).__init__(**kwargs)
        if self.max_length is not None:
            message = lazy(
                self.error_messages['max_length'].format,
                six.text_type)(max_length=self.max_length)
            self.validators.append(
                MaxLengthValidator(self.max_length, message=message))
        if self.min_length is not None:
            message = lazy(
                self.error_messages['min_length'].format,
                six.text_type)(min_length=self.min_length)
            self.validators.append(
                MinLengthValidator(self.min_length, message=message)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:20,代码来源:fields.py

示例4: lazy_number

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def lazy_number(func, resultclass, number=None, **kwargs):
    if isinstance(number, six.integer_types):
        kwargs['number'] = number
        proxy = lazy(func, resultclass)(**kwargs)
    else:
        class NumberAwareString(resultclass):
            def __mod__(self, rhs):
                if isinstance(rhs, dict) and number:
                    try:
                        number_value = rhs[number]
                    except KeyError:
                        raise KeyError('Your dictionary lacks key \'%s\'. '
                            'Please provide it, because it is required to '
                            'determine whether string is singular or plural.'
                            % number)
                else:
                    number_value = rhs
                kwargs['number'] = number_value
                translated = func(**kwargs)
                try:
                    translated = translated % rhs
                except TypeError:
                    # String doesn't contain a placeholder for the number
                    pass
                return translated

        proxy = lazy(lambda **kwargs: NumberAwareString(), NumberAwareString)(**kwargs)
    return proxy 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:__init__.py

示例5: debug

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def debug(request):
    """
    Returns context variables helpful for debugging.
    """
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connection
        # Return a lazy reference that computes connection.queries on access,
        # to ensure it contains queries triggered after this function runs.
        context_extras['sql_queries'] = lazy(lambda: connection.queries, list)
    return context_extras 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:context_processors.py

示例6: lazy_number

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def lazy_number(func, resultclass, number=None, **kwargs):
    if isinstance(number, int):
        kwargs['number'] = number
        proxy = lazy(func, resultclass)(**kwargs)
    else:
        original_kwargs = kwargs.copy()

        class NumberAwareString(resultclass):
            def __bool__(self):
                return bool(kwargs['singular'])

            def __mod__(self, rhs):
                if isinstance(rhs, dict) and number:
                    try:
                        number_value = rhs[number]
                    except KeyError:
                        raise KeyError(
                            "Your dictionary lacks key '%s\'. Please provide "
                            "it, because it is required to determine whether "
                            "string is singular or plural." % number
                        )
                else:
                    number_value = rhs
                kwargs['number'] = number_value
                translated = func(**kwargs)
                try:
                    translated = translated % rhs
                except TypeError:
                    # String doesn't contain a placeholder for the number.
                    pass
                return translated

        proxy = lazy(lambda **kwargs: NumberAwareString(), NumberAwareString)(**kwargs)
        proxy.__reduce__ = lambda: (_lazy_number_unpickle, (func, resultclass, number, original_kwargs))
    return proxy 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:37,代码来源:__init__.py

示例7: debug

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def debug(request):
    """
    Return context variables helpful for debugging.
    """
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connections
        # Return a lazy reference that computes connection.queries on access,
        # to ensure it contains queries triggered after this function runs.
        context_extras['sql_queries'] = lazy(
            lambda: list(itertools.chain.from_iterable(connections[x].queries for x in connections)),
            list
        )
    return context_extras 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:17,代码来源:context_processors.py

示例8: get_seo_content_types

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def get_seo_content_types(seo_models):
    return lazy(_get_seo_content_types, list)(seo_models) 
开发者ID:whyflyru,项目名称:django-seo,代码行数:4,代码来源:utils.py

示例9: lazy_number

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def lazy_number(func, resultclass, number=None, **kwargs):
    if isinstance(number, six.integer_types):
        kwargs['number'] = number
        proxy = lazy(func, resultclass)(**kwargs)
    else:
        original_kwargs = kwargs.copy()

        class NumberAwareString(resultclass):
            def __bool__(self):
                return bool(kwargs['singular'])

            def __nonzero__(self):  # Python 2 compatibility
                return type(self).__bool__(self)

            def __mod__(self, rhs):
                if isinstance(rhs, dict) and number:
                    try:
                        number_value = rhs[number]
                    except KeyError:
                        raise KeyError(
                            "Your dictionary lacks key '%s\'. Please provide "
                            "it, because it is required to determine whether "
                            "string is singular or plural." % number
                        )
                else:
                    number_value = rhs
                kwargs['number'] = number_value
                translated = func(**kwargs)
                try:
                    translated = translated % rhs
                except TypeError:
                    # String doesn't contain a placeholder for the number
                    pass
                return translated

        proxy = lazy(lambda **kwargs: NumberAwareString(), NumberAwareString)(**kwargs)
        proxy.__reduce__ = lambda: (_lazy_number_unpickle, (func, resultclass, number, original_kwargs))
    return proxy 
开发者ID:Yeah-Kun,项目名称:python,代码行数:40,代码来源:__init__.py

示例10: debug

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def debug(request):
    """
    Returns context variables helpful for debugging.
    """
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connections
        # Return a lazy reference that computes connection.queries on access,
        # to ensure it contains queries triggered after this function runs.
        context_extras['sql_queries'] = lazy(
            lambda: list(itertools.chain(*[connections[x].queries for x in connections])),
            list
        )
    return context_extras 
开发者ID:Yeah-Kun,项目名称:python,代码行数:17,代码来源:context_processors.py

示例11: __call__

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def __call__(self, request):
        request.user_permissions = SimpleLazyObject(lambda: self.get_user_permissions(request))
        request.user_space_accesses = lazy(self.get_user_space_accesses, dict)(request)
        return self.get_response(request) 
开发者ID:c3nav,项目名称:c3nav,代码行数:6,代码来源:middleware.py

示例12: test_slugify_lazy_string

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def test_slugify_lazy_string(self):
        lazy_str = lazy(lambda string: string, str)
        self.assertEqual(
            slugify(
                lazy_str(
                    " Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/"
                )
            ),
            "Jack-Jill-like-numbers-123-and-4-and-silly-characters-",
        ) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:12,代码来源:test_slugs.py

示例13: __init__

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def __init__(self, target_model, filter_name=None, **kwargs):
        super(ModelChooserBlock, self).__init__(**kwargs)
        self._target_model = target_model

        self.filter_name = filter_name

        if self.meta.icon == 'placeholder':
            # Get the icon from the chooser.
            # The chooser may not have been registered yet, depending upon
            # import orders and things, so get the icon lazily
            self.meta.icon = lazy(lambda: self.chooser.icon, str)() 
开发者ID:neon-jungle,项目名称:wagtailmodelchooser,代码行数:13,代码来源:blocks.py

示例14: _format_proxy

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def _format_proxy(proxy, *args, **kwargs):
    """
    Helper function to enable string formatting of lazy translation objects.
    This appears to work alright, but I'm not quite sure.
    """
    return str(proxy).format(*args, **kwargs) 
开发者ID:fausecteam,项目名称:ctf-gameserver,代码行数:8,代码来源:util.py

示例15: __init__

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import lazy [as 别名]
def __init__(self, *args, **kwargs):
        super(Notification, self).__init__(*args, **kwargs)
        self._meta.get_field_by_name('notification_type')[0]._choices = lazy(
            get_notification_types, list)() 
开发者ID:brack3t,项目名称:django-heythere,代码行数:6,代码来源:models.py


注:本文中的django.utils.functional.lazy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。