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


Python constants.INFO属性代码示例

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


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

示例1: test_json_encoder_decoder

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def test_json_encoder_decoder(self):
        """
        A complex nested data structure containing Message
        instances is properly encoded/decoded by the custom JSON
        encoder/decoder classes.
        """
        messages = [
            {
                'message': Message(constants.INFO, 'Test message'),
                'message_list': [
                    Message(constants.INFO, 'message %s') for x in range(5)
                ] + [{'another-message': Message(constants.ERROR, 'error')}],
            },
            Message(constants.INFO, 'message %s'),
        ]
        encoder = MessageEncoder(separators=(',', ':'))
        value = encoder.encode(messages)
        decoded_messages = json.loads(value, cls=MessageDecoder)
        self.assertEqual(messages, decoded_messages) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_cookie.py

示例2: test_pre_1_5_message_format

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def test_pre_1_5_message_format(self):
        """
        Messages that were set in the cookie before the addition of is_safedata
        are decoded correctly (#22426).
        """
        # Encode the messages using the current encoder.
        messages = [Message(constants.INFO, 'message %s') for x in range(5)]
        encoder = MessageEncoder(separators=(',', ':'))
        encoded_messages = encoder.encode(messages)

        # Remove the is_safedata flag from the messages in order to imitate
        # the behavior of before 1.5 (monkey patching).
        encoded_messages = json.loads(encoded_messages)
        for obj in encoded_messages:
            obj.pop(1)
        encoded_messages = json.dumps(encoded_messages, separators=(',', ':'))

        # Decode the messages in the old format (without is_safedata)
        decoded_messages = json.loads(encoded_messages, cls=MessageDecoder)
        self.assertEqual(messages, decoded_messages) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_cookie.py

示例3: test_no_fallback

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def test_no_fallback(self):
        """
        (1) A short number of messages whose data size doesn't exceed what is
        allowed in a cookie will all be stored in the CookieBackend.

        (2) If the CookieBackend can store all messages, the SessionBackend
        won't be written to at all.
        """
        storage = self.get_storage()
        response = self.get_response()
        # Overwrite the _store method of the fallback storage to prove it isn't
        # used (it would cause a TypeError: 'NoneType' object is not callable).
        self.get_session_storage(storage)._store = None
        for i in range(5):
            storage.add(constants.INFO, str(i) * 100)
        storage.update(response)
        cookie_storing = self.stored_cookie_messages_count(storage, response)
        self.assertEqual(cookie_storing, 5)
        session_storing = self.stored_session_messages_count(storage, response)
        self.assertEqual(session_storing, 0) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:test_fallback.py

示例4: test_session_fallback

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def test_session_fallback(self):
        """
        If the data exceeds what is allowed in a cookie, messages which did
        not fit are stored in the SessionBackend.
        """
        storage = self.get_storage()
        response = self.get_response()
        # see comment in CookieTests.test_cookie_max_length()
        msg_size = int((CookieStorage.max_cookie_size - 54) / 4.5 - 37)
        for i in range(5):
            storage.add(constants.INFO, str(i) * msg_size)
        storage.update(response)
        cookie_storing = self.stored_cookie_messages_count(storage, response)
        self.assertEqual(cookie_storing, 4)
        session_storing = self.stored_session_messages_count(storage, response)
        self.assertEqual(session_storing, 1) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_fallback.py

示例5: test_max_cookie_length

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def test_max_cookie_length(self):
        """
        If the data exceeds what is allowed in a cookie, older messages are
        removed before saving (and returned by the ``update`` method).
        """
        storage = self.get_storage()
        response = self.get_response()

        # When storing as a cookie, the cookie has constant overhead of approx
        # 54 chars, and each message has a constant overhead of about 37 chars
        # and a variable overhead of zero in the best case. We aim for a message
        # size which will fit 4 messages into the cookie, but not 5.
        # See also FallbackTest.test_session_fallback
        msg_size = int((CookieStorage.max_cookie_size - 54) / 4.5 - 37)
        for i in range(5):
            storage.add(constants.INFO, str(i) * msg_size)
        unstored_messages = storage.update(response)

        cookie_storing = self.stored_messages_count(storage, response)
        self.assertEqual(cookie_storing, 4)

        self.assertEqual(len(unstored_messages), 1)
        self.assertEqual(unstored_messages[0].message, '0' * msg_size) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:test_cookie.py

示例6: post

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def post(self, request, *args, **kwargs):
        form = self.get_form()
        fieldsets = self.generate_fieldsets()

        is_valid = form.is_valid()
        is_changed = self.is_changed(form)

        if is_valid and is_changed:
            return self.form_valid(form)
        else:
            if is_valid and not is_changed:
                return self.form_invalid(
                    form, msg=_('No changes have been submitted.'), msg_level=constants.INFO,
                    fieldsets=fieldsets
                )
            return self.form_invalid(form, fieldsets=fieldsets) 
开发者ID:matllubos,项目名称:django-is-core,代码行数:18,代码来源:form_views.py

示例7: message_user

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def message_user(user, message, level=constants.INFO):
    """Send a message to a particular user.

    A list of messages is stored in the cache to allow having multiple messages
    queued up for a user. This non-atomic read-modify-write makes it possible
    to lose messages under concurrency.

    :param user: User instance
    :param message: Message to show
    :param level: Message level
    """
    if user.id is None:
        raise ValueError('Anonymous users cannot send messages')

    user_key = _user_key(user)
    messages = cache.get(user_key) or []
    messages.append((message, level))
    cache.set(user_key, messages) 
开发者ID:NicolasLM,项目名称:feedsubs,代码行数:20,代码来源:background_messages.py

示例8: get_level

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def get_level(request):
    """
    Returns the minimum level of messages to be recorded.

    The default level is the ``MESSAGE_LEVEL`` setting. If this is not found,
    the ``INFO`` level is used.
    """
    if hasattr(request, '_messages'):
        storage = request._messages
    else:
        storage = default_storage(request)
    return storage.level 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:14,代码来源:api.py

示例9: info

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def info(request, message, extra_tags='', fail_silently=False):
    """
    Adds a message with the ``INFO`` level.
    """
    add_message(request, constants.INFO, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:api.py

示例10: _get_level

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def _get_level(self):
        """
        Returns the minimum recorded level.

        The default level is the ``MESSAGE_LEVEL`` setting. If this is
        not found, the ``INFO`` level is used.
        """
        if not hasattr(self, '_level'):
            self._level = getattr(settings, 'MESSAGE_LEVEL', constants.INFO)
        return self._level 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:base.py

示例11: get_level

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def get_level(request):
    """
    Return the minimum level of messages to be recorded.

    The default level is the ``MESSAGE_LEVEL`` setting. If this is not found,
    use the ``INFO`` level.
    """
    storage = getattr(request, '_messages', default_storage(request))
    return storage.level 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:11,代码来源:api.py

示例12: info

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def info(request, message, extra_tags='', fail_silently=False):
    """Add a message with the ``INFO`` level."""
    add_message(request, constants.INFO, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:api.py

示例13: _get_level

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def _get_level(self):
        """
        Return the minimum recorded level.

        The default level is the ``MESSAGE_LEVEL`` setting. If this is
        not found, the ``INFO`` level is used.
        """
        if not hasattr(self, '_level'):
            self._level = getattr(settings, 'MESSAGE_LEVEL', constants.INFO)
        return self._level 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:base.py

示例14: add_message

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def add_message(user, level, message, extra_tags="", deliver_once=True, meta=None):
    from user_messages.models import Message

    Message.objects.create(
        level=level or 20,  # INFO
        message=message,
        extra_tags=extra_tags,
        _metadata=json.dumps(meta or {}),
        deliver_once=deliver_once,
        **{"user" if isinstance(user, models.Model) else "user_id": user}
    ) 
开发者ID:matthiask,项目名称:django-user-messages,代码行数:13,代码来源:api.py

示例15: get_level

# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import INFO [as 别名]
def get_level(request):
    """
    Returns the minimum level of messages to be recorded.

    The default level is the ``MESSAGE_LEVEL`` setting. If this is not found,
    the ``INFO`` level is used.
    """
    storage = getattr(request, '_messages', default_storage(request))
    return storage.level 
开发者ID:bpgc-cte,项目名称:python2017,代码行数:11,代码来源:api.py


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