Skip to content
This repository
Browse code

Marked messages as 'safe' in view instead of in template.

This is much more preferable, as it provides compatibility with the Django
admin (and probably other apps) that do it this way i.e.  do not use 'safe'
in the template that outputs the message.
  • Loading branch information...
commit 18fd1054e8b030f40036b8ec46aa1bf9f4baaf6c 1 parent c0d4392
Luke Plant authored August 09, 2011
9  djiki/views.py
@@ -6,6 +6,7 @@
6 6
 from django.shortcuts import get_object_or_404
7 7
 from django.template import RequestContext, loader
8 8
 from django.utils.translation import ugettext as _
  9
+from django.utils.safestring import mark_safe
9 10
 from django.views.generic.simple import direct_to_template
10 11
 from urllib import urlencode, quote
11 12
 from . import models, forms, utils
@@ -33,11 +34,11 @@ def view(request, title, revision_pk=None):
33 34
 			revision = page.revisions.get(pk=revision_pk)
34 35
 		except models.PageRevision.DoesNotExist:
35 36
 			return HttpResponseNotFound()
36  
-		messages.info(request, _("The version you are viewing is not the latest one, "
  37
+		messages.info(request, mark_safe(_("The version you are viewing is not the latest one, "
37 38
 				"but represents an older revision of this page, which may have been "
38 39
 				"significantly modified. If it is not what you intended to view, "
39 40
 				"<a href=\"%(url)s\">proceed to the latest version</a>.") % {
40  
-					'url': reverse('djiki-page-view', kwargs={'title': url_title})})
  41
+					'url': reverse('djiki-page-view', kwargs={'title': url_title})}))
41 42
 	else:
42 43
 		revision = page.last_revision()
43 44
 	if request.REQUEST.get('raw', ''):
@@ -72,10 +73,10 @@ def edit(request, title):
72 73
 		if form.is_valid():
73 74
 			if is_preview:
74 75
 				preview_content = form.cleaned_data.get('content', form.data['content'])
75  
-				messages.info(request, _("The content you see on this page is shown only as "
  76
+				messages.info(request, mark_safe(_("The content you see on this page is shown only as "
76 77
 						"a preview. <strong>No changes have been saved yet.</strong> Please "
77 78
 						"review the modifications and use the <em>Save</em> button to store "
78  
-						"them permanently."))
  79
+						"them permanently.")))
79 80
 			else:
80 81
 				form.save()
81 82
 				return HttpResponseRedirect(
2  templates/base.html
@@ -30,7 +30,7 @@
30 30
 		<div class="grid_12">
31 31
 			<ul>
32 32
 				{% for msg in messages %}
33  
-				<li class="{{ msg.tags }}">{{ msg|safe }}</li>
  33
+				<li class="{{ msg.tags }}">{{ msg }}</li>
34 34
 				{% endfor %}
35 35
 			</ul>
36 36
 		</div>

0 notes on commit 18fd105

Please sign in to comment.
Something went wrong with that request. Please try again.