當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。