# HG changeset patch # User Brian Neal # Date 1268795525 0 # Node ID d51743322bb240ee54e0b50422ba0c71ec5c18bf # Parent 9b63ad1f2ad2bc231db60efc06f8f3519cef3a21 #56 - Cut over to Django 1.2 messaging system. diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/bio/views.py --- 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() diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/messages/views.py --- 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: diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/settings.py --- 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: diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/templates/bio/view_profile.html --- 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 %}

User Profile for {{ subject.username }}

+ {% if messages %} + + {% endif %}

{% avatar subject %}

diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/templates/messages/inbox.html --- 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 %} {% endif %} diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/templates/messages/options.html --- 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 %} {% endif %} diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/templates/messages/outbox.html --- 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 %} {% endif %} diff -r 9b63ad1f2ad2 -r d51743322bb2 gpp/templates/messages/trash.html --- 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 %} {% endif %}
Full Name{{ subject.get_full_name }}