changeset 178:d51743322bb2

#56 - Cut over to Django 1.2 messaging system.
author Brian Neal <bgneal@gmail.com>
date Wed, 17 Mar 2010 03:12:05 +0000
parents 9b63ad1f2ad2
children 70b2e307c866
files gpp/bio/views.py gpp/messages/views.py gpp/settings.py gpp/templates/bio/view_profile.html gpp/templates/messages/inbox.html gpp/templates/messages/options.html gpp/templates/messages/outbox.html gpp/templates/messages/trash.html
diffstat 8 files changed, 36 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/bio/views.py	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/bio/views.py	Wed Mar 17 03:12:05 2010 +0000
@@ -6,6 +6,7 @@
 from django.shortcuts import get_object_or_404
 from django.template import RequestContext
 from django.contrib import auth
+from django.contrib import messages
 from django.http import HttpResponse
 from django.http import HttpResponseBadRequest
 from django.http import HttpResponseRedirect
@@ -142,7 +143,7 @@
                 profile.avatar.save(form.get_filename(), file, save=False)
             profile.save()
 
-            request.user.message_set.create(message='Avatar updated.')
+            messages.success(request, 'Avatar updated')
             return HttpResponseRedirect(reverse('bio-me'))
     else:
         form = UploadAvatarForm()
--- a/gpp/messages/views.py	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/messages/views.py	Wed Mar 17 03:12:05 2010 +0000
@@ -5,6 +5,7 @@
 from django.template import RequestContext
 from django.http import HttpResponseRedirect
 from django.contrib.auth.decorators import login_required
+from django.contrib import messages
 from django.shortcuts import get_object_or_404
 from django.core.urlresolvers import reverse
 from django.http import Http404
@@ -109,7 +110,7 @@
         compose_form = ComposeForm(request.user, request.POST)
         if compose_form.is_valid():
             compose_form.save(sender=request.user, parent_msg=msg)
-            request.user.message_set.create(message='Reply sent.')
+            messages.success(request, 'Reply sent.')
             return box_redirect(request)
     else:
         if msg.receiver == request.user:
@@ -145,7 +146,7 @@
         compose_form = ComposeForm(request.user, request.POST)
         if compose_form.is_valid():
             compose_form.save(sender=request.user)
-            request.user.message_set.create(message='Message sent.')
+            messages.success(request, 'Message sent.')
             return HttpResponseRedirect(reverse('messages-inbox'))
     else:
         if receiver is not None:
@@ -177,7 +178,7 @@
     else:
         raise Http404
     msg.save()
-    request.user.message_set.create(message='Message sent to trash.')
+    messages.success(request, 'Message sent to trash.')
 
     return box_redirect(request)
 
@@ -204,7 +205,7 @@
             elif msg.receiver == request.user:
                 msg.receiver_delete_date = now
                 msg.save()
-        request.user.message_set.create(message='Messages sent to the trash.')
+        messages.success(request, 'Messages sent to the trash.')
 
     return box_redirect(request)
 
@@ -224,7 +225,7 @@
     else:
         raise Http404
     msg.save()
-    request.user.message_set.create(message='Message retrieved from the trash.')
+    messages.success(request, 'Message retrieved from the trash.')
 
     return box_redirect(request)
 
@@ -250,7 +251,7 @@
             elif msg.receiver == request.user:
                 msg.receiver_delete_date = None
                 msg.save()
-        request.user.message_set.create(message='Messages retrieved from the trash.')
+        messages.success(request, 'Messages retrieved from the trash.')
 
     return box_redirect(request)
 
@@ -267,7 +268,7 @@
         form = OptionsForm(request.POST, instance=options)
         if form.is_valid():
             form.save()
-            request.user.message_set.create(message='Options saved.')
+            messages.success(request, 'Options saved.')
             return HttpResponseRedirect(reverse('messages-inbox'))
     else:
         try:
--- a/gpp/settings.py	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/settings.py	Wed Mar 17 03:12:05 2010 +0000
@@ -62,12 +62,14 @@
 TEMPLATE_LOADERS = (
     ('django.template.loaders.cached.Loader', (
         'django.template.loaders.filesystem.Loader',
+        'django.template.loaders.app_directories.Loader',
     )),
 )
 
 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
     'gpp.forums.middleware.WhosOnline',
@@ -84,10 +86,11 @@
 )
 
 TEMPLATE_CONTEXT_PROCESSORS = (
-   "django.contrib.auth.context_processors.auth",
-   "django.core.context_processors.debug",
-   "django.core.context_processors.request",
-   "django.core.context_processors.media"
+    "django.contrib.auth.context_processors.auth",
+    "django.core.context_processors.debug",
+    "django.core.context_processors.request",
+    "django.core.context_processors.media",
+    "django.contrib.messages.context_processors.messages",
 )
 
 INSTALLED_APPS = (
@@ -95,11 +98,12 @@
     'django.contrib.admindocs',
     'django.contrib.auth',
     'django.contrib.contenttypes',
+    'django.contrib.flatpages',
     'django.contrib.humanize',
+    'django.contrib.markup',
+    'django.contrib.messages',
     'django.contrib.sessions',
     'django.contrib.sites',
-    'django.contrib.markup',
-    'django.contrib.flatpages',
     'elsewhere',
     'tagging',
     'accounts',
@@ -132,6 +136,11 @@
 DEFAULT_FROM_EMAIL = ADMINS[0][1]
 
 #######################################################################
+# Messages
+#######################################################################
+MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
+
+#######################################################################
 # Caching
 #######################################################################
 if local_settings.USE_CACHE:
--- a/gpp/templates/bio/view_profile.html	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/templates/bio/view_profile.html	Wed Mar 17 03:12:05 2010 +0000
@@ -15,6 +15,13 @@
 {% block content %}
 <div class="user_profile">
    <h2>User Profile for {{ subject.username }}</h2>
+   {% if messages %}
+   <ul class="user-messages">
+    {% for message in messages %}
+       <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
+    {% endfor %}
+   </ul>
+   {% endif %}
    <p>{% avatar subject %}</p>
 <table id="bio_profile">
    <tr><th>Full Name</th><td>{{ subject.get_full_name }}</td></tr>
--- a/gpp/templates/messages/inbox.html	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/templates/messages/inbox.html	Wed Mar 17 03:12:05 2010 +0000
@@ -9,7 +9,7 @@
 {% if messages %}
 <ul class="user-messages">
    {% for msg in messages %}
-      <li>{{ msg }}</li>
+      <li{% if msg.tags %} class="{{ msg.tags }}"{% endif %}>{{ msg }}</li>
    {% endfor %}
 </ul>
 {% endif %}
--- a/gpp/templates/messages/options.html	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/templates/messages/options.html	Wed Mar 17 03:12:05 2010 +0000
@@ -6,7 +6,7 @@
 {% if messages %}
 <ul class="user-messages">
    {% for msg in messages %}
-      <li>{{ msg }}</li>
+      <li{% if msg.tags %} class="{{ msg.tags }}"{% endif %}>{{ msg }}</li>
    {% endfor %}
 </ul>
 {% endif %}
--- a/gpp/templates/messages/outbox.html	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/templates/messages/outbox.html	Wed Mar 17 03:12:05 2010 +0000
@@ -9,7 +9,7 @@
 {% if messages %}
 <ul class="user-messages">
    {% for msg in messages %}
-      <li>{{ msg }}</li>
+      <li{% if msg.tags %} class="{{ msg.tags }}"{% endif %}>{{ msg }}</li>
    {% endfor %}
 </ul>
 {% endif %}
--- a/gpp/templates/messages/trash.html	Mon Mar 15 03:26:38 2010 +0000
+++ b/gpp/templates/messages/trash.html	Wed Mar 17 03:12:05 2010 +0000
@@ -9,7 +9,7 @@
 {% if messages %}
 <ul class="user-messages">
    {% for msg in messages %}
-      <li>{{ msg }}</li>
+      <li{% if msg.tags %} class="{{ msg.tags }}"{% endif %}>{{ msg }}</li>
    {% endfor %}
 </ul>
 {% endif %}