Пример #1
0
def create_offline_message(user, 
                           message,
                           level=constants.INFO,
                           read=False,
                           content_object=None,
                           meta={}):

    if not isinstance(user, User):
        user = User.objects.get(username=user)

    level_tags = get_level_tags()
    label_tag = force_unicode(level_tags.get(level, ''), strings_only=True)

    kwargs = dict(
        user=user,
        level=level,
        tags=label_tag,
        read=read,
        message=message,
        meta=dict(meta)
    )

    if content_object:
        kwargs['content_object'] = content_object

    return OfflineMessage.objects.create(**kwargs)
Пример #2
0
def create_offline_message(user,
                           message,
                           level=constants.INFO,
                           read=False,
                           content_object=None,
                           meta={}):

    if not isinstance(user, get_user_model()):
        user = get_user_model().objects.get(username=user)

    level_tags = get_level_tags()
    label_tag = force_unicode(level_tags.get(level, ''), strings_only=True)

    kwargs = dict(
        user=user,
        level=level,
        tags=label_tag,
        read=read,
        message=message,
        meta=dict(meta)
    )

    if content_object:
        kwargs['content_object'] = content_object

    return OfflineMessage.objects.create(**kwargs)
Пример #3
0
 def enable(self):
     super(override_settings_tags, self).enable()
     # LEVEL_TAGS is a constant defined in the
     # django.contrib.messages.storage.base module, so after changing
     # settings.MESSAGE_TAGS, we need to update that constant too.
     self.old_level_tags = base.LEVEL_TAGS
     base.LEVEL_TAGS = utils.get_level_tags()
Пример #4
0
 def enable(self):
     super(override_settings_tags, self).enable()
     # LEVEL_TAGS is a constant defined in the
     # django.contrib.messages.storage.base module, so after changing
     # settings.MESSAGE_TAGS, we need to update that constant too.
     self.old_level_tags = base.LEVEL_TAGS
     base.LEVEL_TAGS = utils.get_level_tags()
Пример #5
0
def styleguide(request):
    now = timezone.now() + timedelta(-1)
    domain = mock.Mock(domain="example.com")

    # create a bunch of mocked inboxes
    inboxes = [
        mock.Mock(
            inbox="qwerty",
            domain=domain,
            get_bools_for_labels={"new": False},
            last_activity=now,
            form=InboxEditForm(request),
        ),
        mock.Mock(
            inbox="qwerty",
            domain=domain,
            get_bools_for_labels={"disabled": True},
            last_activity=now,
            form=False,
        ),
        mock.Mock(
            inbox="qwerty",
            domain=domain,
            get_bools_for_labels={"new": True, "pinned": True},
            last_activity=now,
            form=False,
        ),
    ]

    # emails
    emails = [
        mock.Mock(
            inbox=inboxes[0],
            get_bools_for_labels={"important": True},
            received_date=now,
        ),
        mock.Mock(
            inbox=inboxes[0],
            get_bools_for_labels={"important": False},
            received_date=now,
        ),
    ]

    # attachments
    attachments = [
        mock.Mock(id=0, filename=("a" * 100), content_type="blah/blah", get_children=[]),
        mock.Mock(id=0, filename="a", content_type=None, get_children=[]),
    ]

    context = {
        "inboxes": inboxes,
        "emails": emails,
        "attachments": attachments,
        "form": Form(),
        "message_types": [(k, get_level_tags()[v]) for k, v in DEFAULT_LEVELS.items() if k != 'DEBUG'],
    }
    return TemplateResponse(request, 'inboxen/styleguide.html', context)
Пример #6
0
def create_offline_message(user, message, level=constants.INFO):
    if not isinstance(user, User):
        user = User.objects.get(username=user)

    level_tags = get_level_tags()
    label_tag = force_unicode(level_tags.get(level, ''), strings_only=True)

    OfflineMessage.objects.create(user=user,
                                  level=level,
                                  tags=label_tag,
                                  message=message)
Пример #7
0
 def test_custom_tags(self):
     settings.MESSAGE_TAGS = {
         constants.INFO: "info",
         constants.DEBUG: "",
         constants.WARNING: "",
         constants.ERROR: "bad",
         29: "custom",
     }
     # LEVEL_TAGS is a constant defined in the
     # django.contrib.messages.storage.base module, so after changing
     # settings.MESSAGE_TAGS, we need to update that constant too.
     base.LEVEL_TAGS = utils.get_level_tags()
     try:
         storage = self.get_storage()
         storage.level = 0
         add_level_messages(storage)
         tags = [msg.tags for msg in storage]
         self.assertEqual(tags, ["info", "custom", "extra-tag", "", "bad", "success"])
     finally:
         # Ensure the level tags constant is put back like we found it.
         self.restore_setting("MESSAGE_TAGS")
         base.LEVEL_TAGS = utils.get_level_tags()
Пример #8
0
 def test_custom_tags(self):
     settings.MESSAGE_TAGS = {
         constants.INFO: 'info',
         constants.DEBUG: '',
         constants.WARNING: '',
         constants.ERROR: 'bad',
         29: 'custom',
     }
     # LEVEL_TAGS is a constant defined in the
     # django.contrib.messages.storage.base module, so after changing
     # settings.MESSAGE_TAGS, we need to update that constant too.
     base.LEVEL_TAGS = utils.get_level_tags()
     try:
         storage = self.get_storage()
         storage.level = 0
         add_level_messages(storage)
         tags = [msg.tags for msg in storage]
         self.assertEqual(
             tags, ['info', 'custom', 'extra-tag', '', 'bad', 'success'])
     finally:
         # Ensure the level tags constant is put back like we found it.
         self.restore_setting('MESSAGE_TAGS')
         base.LEVEL_TAGS = utils.get_level_tags()
Пример #9
0
 def test_custom_tags(self):
     settings.MESSAGE_TAGS = {
         constants.INFO: 'info',
         constants.DEBUG: '',
         constants.WARNING: '',
         constants.ERROR: 'bad',
         29: 'custom',
     }
     # LEVEL_TAGS is a constant defined in the
     # django_lettuce.contrib.messages.storage.base module, so after changing
     # settings.MESSAGE_TAGS, we need to update that constant too.
     base.LEVEL_TAGS = utils.get_level_tags()
     try:
         storage = self.get_storage()
         storage.level = 0
         add_level_messages(storage)
         tags = [msg.tags for msg in storage]
         self.assertEqual(tags,
                      ['info', 'custom', 'extra-tag', '', 'bad', 'success'])
     finally:
         # Ensure the level tags constant is put back like we found it.
         self.restore_setting('MESSAGE_TAGS')
         base.LEVEL_TAGS = utils.get_level_tags()
Пример #10
0
def create_offline_message(user, message, level=constants.INFO):

    if not isinstance(user, get_user_model()):
        user = get_user_model().objects.get(username=user)

    level_tags = get_level_tags()
    label_tag = force_unicode(level_tags.get(level, ''), strings_only=True)

    kwargs = dict(
        user=user,
        level=level,
        tags=label_tag,
        message=message,
    )

    return OfflineMessage.objects.create(**kwargs)
Пример #11
0
from django.contrib.auth import get_user_model
from django.db import models
from django.utils.encoding import force_unicode
from django.contrib import messages
from django.contrib.messages import utils
from django.utils.translation import ugettext_lazy as _

import monitio
from monitio import constants 


LEVEL_TAGS = utils.get_level_tags()
User = get_user_model()

class Monit(models.Model):
    user = models.ForeignKey(User, blank=True, null=True)
    from_user = models.ForeignKey(User, blank=True, null=True,
                                  related_name="from_user")
    subject = models.CharField(max_length=255, blank=True, default='')
    message = models.TextField()
    LEVEL_CHOICES = (
        (messages.DEBUG, 'DEBUG'),
        (messages.INFO, 'INFO'),
        (messages.SUCCESS, 'SUCCESS'),
        (messages.WARNING, 'WARNING'),
        (messages.ERROR, 'ERROR'),
        (constants.DEBUG, 'PERSISTENT DEBUG'),
        (constants.INFO, 'PERSISTENT INFO'),
        (constants.SUCCESS, 'PERSISTENT SUCCESS'),
        (constants.WARNING, 'PERSISTENT WARNING'),
        (constants.ERROR, 'PERSISTENT ERROR'),
Пример #12
0
from __future__ import unicode_literals
import re

from social.backends.oauth import OAuthAuth
from social.backends.utils import load_backends
from urlobject import URLObject

from django.conf import settings
from django.utils.six import text_type
from django.contrib.messages.utils import get_level_tags
from django.utils.encoding import force_text
from django import template


name_re = re.compile(r'([^O])Auth')
LEVEL_TAGS = get_level_tags()

register = template.Library()


@register.simple_tag()
def get_message_tags(message):
    """
    Returns the message's level_tag prefixed with Bootstrap's "alert-" prefix
    along with any tags included in message.extra_tags

    Messages in Django >= 1.7 have a message.level_tag attr
    """
    level_tag = force_text(LEVEL_TAGS.get(message.level, ''), strings_only=True)
    if level_tag == "error":
        # Alias the error tag as danger, since .alert-error no longer exists
Пример #13
0
	def __init__(self,*args,**kwargs):
		super(AnnouncementAdminForm,self).__init__(*args,**kwargs)
		level_tags = get_level_tags().values()
		choices = [(x,x) for x in level_tags]
		self.fields['message_level']  = forms.ChoiceField(choices=choices)
 def tags(self):
     level_tags = get_level_tags()
     return force_unicode(level_tags.get(self.level, ''), strings_only=True)
Пример #15
0
 def tags(self):
     level_tags = get_level_tags()
     return force_unicode(level_tags.get(self.level, ''), strings_only=True)
Пример #16
0
# -*- coding: utf-8 -*-
"""models.py: messages extends"""

from __future__ import unicode_literals

import messages_extends
from django.db import models
from django.utils.encoding import force_text
from django.contrib.messages import utils
from django.conf import settings

LEVEL_TAGS = utils.get_level_tags()


class Message(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
    message = models.TextField()
    LEVEL_CHOICES = (
        (messages_extends.DEBUG_PERSISTENT, 'PERSISTENT DEBUG'),
        (messages_extends.INFO_PERSISTENT, 'PERSISTENT INFO'),
        (messages_extends.SUCCESS_PERSISTENT, 'PERSISTENT SUCCESS'),
        (messages_extends.WARNING_PERSISTENT, 'PERSISTENT WARNING'),
        (messages_extends.ERROR_PERSISTENT, 'PERSISTENT ERROR'),
    )
    level = models.IntegerField(choices=LEVEL_CHOICES)
    extra_tags = models.CharField(max_length=128)
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    read = models.BooleanField(default=False)
    expires = models.DateTimeField(null=True, blank=True)
Пример #17
0
def update_level_tags(setting, **kwargs):
    if setting == 'MESSAGE_TAGS':
        base.LEVEL_TAGS = get_level_tags()
Пример #18
0
import json
from collections import namedtuple
import hashlib

from ..exceptions import MessageTypeNotSupported, MessageDoesNotExist
from ..base import StoredMessagesBackend
from .. import signals
from ...settings import stored_messages_settings

try:
    # Let django project bootstrap anyway when not using this backend
    import redis
except ImportError:
    pass

LEVEL_TAGS = get_level_tags()

#Message = namedtuple('Message', ['id', 'message', 'level', 'tags', 'date', 'url'])
Message = namedtuple(
    'Message', ['id', 'message', 'level', 'level_tag', 'tags', 'date', 'url'])


class RedisBackend(StoredMessagesBackend):
    """

    """
    def __init__(self):
        self.client = redis.StrictRedis.from_url(
            stored_messages_settings.REDIS_URL)

    def _flush(self):
Пример #19
0
from __future__ import unicode_literals
from django.conf import settings
from django.contrib.messages import constants, utils
from django.utils.encoding import force_text, python_2_unicode_compatible
LEVEL_TAGS = utils.get_level_tags()

@python_2_unicode_compatible
class Message(object):
    """
    Represents an actual message that can be stored in any of the supported
    storage classes (typically session- or cookie-based) and rendered in a view
    or template.
    """
    def __init__(self, level, message, extra_tags=None):
        self.level = int(level)
        self.message = message
        self.extra_tags = extra_tags
    def _prepare(self):
        """
        Prepares the message for serialization by forcing the ``message``
        and ``extra_tags`` to unicode in case they are lazy translations.
        Known "safe" types (None, int, etc.) are not converted (see Django's
        ``force_text`` implementation for details).
        """
        self.message = force_text(self.message, strings_only=True)
        self.extra_tags = force_text(self.extra_tags, strings_only=True)
    def __eq__(self, other):
        return isinstance(other, Message) and self.level == other.level and \
            self.message == other.message
    def __str__(self):