Permalink
Browse files

Using the messages framework to show when things have happened better…

… than they are now
  • Loading branch information...
1 parent 3db415c commit 7706c536d4e54e7a86f1ce210bf8d68f9ab8f984 @rossbruniges rossbruniges committed Dec 4, 2012
View
@@ -31,6 +31,7 @@
INSTALLED_APPS = list(INSTALLED_APPS) + [
# Django admin
'django.contrib.admin',
+ 'django.contrib.messages',
# Application base, containing global templates.
'%s.base' % PROJECT_MODULE,
# Static website base, containing global templates.
@@ -68,10 +69,12 @@
TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS) + [
'django_browserid.context_processors.browserid_form',
+ 'django.contrib.messages.context_processors.messages',
'gameon.base.context_processors.app_stage',
]
MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) + [
+ 'django.contrib.messages.middleware.MessageMiddleware',
'gameon.users.middleware.ProfileMiddleware',
'gameon.submissions.middleware.ChallengeStatusMiddleware',
]
@@ -12,6 +12,13 @@ <h1 class="busta shout">{{ entry.title }}</h1>
<div class="busta">
<div class="cf">
<div class="main-col">
+ {% if messages %}
+ <div class="shout-box">
+ {% for m in messages %}
+ {{ m|safe }}
+ {% endfor %}
+ </div>
+ {% endif %}
{% if entry.has_entry_feature %}
<div class="frame">{{ entry.get_entry_feature()|safe }}</div>
{% endif %}
@@ -1,10 +1,13 @@
from django.shortcuts import render
+from django.contrib import messages
from django.core.urlresolvers import reverse
from django.conf import settings
from django.http import HttpResponseRedirect
from django.template.defaultfilters import slugify
from django.contrib.auth.decorators import login_required
+from tower import ugettext as _
+
from gameon.base.views import action_unavailable_response
from gameon.base.utils import get_page, get_paginator
from gameon.submissions.models import Entry, Category
@@ -25,8 +28,9 @@ def create(request, template='submissions/create.html'):
if entry.to_market == True:
return HttpResponseRedirect(settings.MARKETPLACE_URL)
else:
- return HttpResponseRedirect(reverse('submissions.entry_list',
- kwargs={'category': 'all'}))
+ messages.success(request, _('<strong>Game submitted!</strong>'))
+ return HttpResponseRedirect(reverse('submissions.entry_single',
+ kwargs={'slug': entry.slug}))
else:
data = {
'categories': Category.objects.all(),
@@ -50,13 +54,15 @@ def edit_entry(request, slug, template='submissions/edit.html'):
form = EntryForm(request.POST, instance=entry)
if form.is_valid():
entry = form.save(commit=False)
- entry.slug = slugify(entry.title)
+ new_slug = slugify(entry.title)
+ entry.slug = new_slug
form.save()
if entry.to_market == True:
return HttpResponseRedirect(settings.MARKETPLACE_URL)
else:
- return HttpResponseRedirect(reverse('submissions.entry_list',
- kwargs={'category': 'all'}))
+ messages.success(request, _('<strong>Game edited!</strong>'))
+ return HttpResponseRedirect(reverse('submissions.entry_single',
+ kwargs={'slug': new_slug}))
else:
data = {
'categories': Category.objects.all(),
@@ -21,6 +21,13 @@ <h1 class="busta shout">{{ profile.display_name }}</h1>
{% endif %}
</aside>
<div class="main-col">
+ {% if messages %}
+ <div class="shout-box">
+ {% for m in messages %}
+ {{ m|safe }}
+ {% endfor %}
+ </div>
+ {% endif %}
{% if entries %}
<ol class="entries cf">
{% for sub in entries %}
View
@@ -1,8 +1,11 @@
from django.contrib import auth
+from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render, get_object_or_404
from django.core.urlresolvers import reverse
+from tower import ugettext as _
+
from gameon.users.forms import ProfileForm, ProfileCreateForm
from gameon.users.models import Profile
from gameon.submissions.models import Entry
@@ -43,6 +46,7 @@ def edit(request, template='users/profile_edit.html'):
profile.user = request.user
profile.save()
if mode == 'edit':
+ messages.success(request, _('<strong>Profile edited!</strong>'))
return redirect(profile)
else:
"""

0 comments on commit 7706c53

Please sign in to comment.