Ticket #13652: add_message_flag_to_message_model.patch

File add_message_flag_to_message_model.patch, 3.3 KB (added by Sebastian Noack, 14 years ago)
  • django/django/contrib/admin/media/css/base.css

    diff --git a/django/django/contrib/admin/media/css/base.css b/django/django/contrib/admin/media/css/base.css
    index 7299c95..069f303 100644
    a b ul.messagelist li {  
    442442    margin: 0 0 3px 0;
    443443    border-bottom: 1px solid #ddd;
    444444    color: #666;
     445}
     446
     447ul.messagelist li.info {
    445448    background: #ffc url(../img/admin/icon_success.gif) 5px .3em no-repeat;
    446449}
    447450
     451ul.messagelist li.error {
     452    background: #ffc url(../img/admin/icon_error.gif) 5px .3em no-repeat;
     453}
     454
    448455.errornote {
    449456    font-size: 12px !important;
    450457    display: block;
  • django/django/contrib/admin/options.py

    diff --git a/django/django/contrib/admin/options.py b/django/django/contrib/admin/options.py
    index 20f3ed4..d83b4aa 100644
    a b class ModelAdmin(BaseModelAdmin):  
    535535        change_message = ' '.join(change_message)
    536536        return change_message or _('No fields changed.')
    537537
    538     def message_user(self, request, message):
     538    def message_user(self, request, message, message_flag=None):
    539539        """
    540540        Send a message to the user. The default implementation
    541541        posts a message using the auth Message object.
    542542        """
    543         request.user.message_set.create(message=message)
     543        if message_flag is None:
     544            request.user.message_set.create(message=message)
     545        else:
     546            request.user.message_set.create(message=message, message_flag=message_flag)
    544547
    545548    def save_form(self, request, form, change):
    546549        """
  • django/django/contrib/admin/templates/admin/base.html

    diff --git a/django/django/contrib/admin/templates/admin/base.html b/django/django/contrib/admin/templates/admin/base.html
    index 9525728..d8e23b0 100644
    a b  
    5555    {% endif %}
    5656
    5757        {% if messages %}
    58         <ul class="messagelist">{% for message in messages %}<li>{{ message }}</li>{% endfor %}</ul>
     58        <ul class="messagelist">{% for m in messages %}<li{% if m.is_info %} class="info"{% else %}{% if m.is_error %} class="error"{% endif %}{% endif %}>{{ m }}</li>{% endfor %}</ul>
    5959        {% endif %}
    6060
    6161    <!-- Content -->
  • django/django/contrib/auth/models.py

    diff --git a/django/django/contrib/auth/models.py b/django/django/contrib/auth/models.py
    index e337bec..b3bf613 100644
    a b from django.utils.translation import ugettext_lazy as _  
    1212
    1313UNUSABLE_PASSWORD = '!' # This will never be a valid hash
    1414
     15INFO = 1
     16ERROR = 2
     17
    1518try:
    1619    set
    1720except NameError:
    class User(models.Model):  
    261264    def get_and_delete_messages(self):
    262265        messages = []
    263266        for m in self.message_set.all():
    264             messages.append(m.message)
     267            messages.append(m)
    265268            m.delete()
    266269        return messages
    267270
    class Message(models.Model):  
    299302    """
    300303    user = models.ForeignKey(User)
    301304    message = models.TextField(_('message'))
     305    message_flag = models.PositiveSmallIntegerField(default=INFO)
     306
     307    def is_info(self):
     308        return self.message_flag == INFO
     309
     310    def is_error(self):
     311        return self.message_flag == ERROR
    302312
    303313    def __unicode__(self):
    304314        return self.message
Back to Top