]> git.openstreetmap.org Git - osqa.git/commitdiff
OSQA-600, notification templates unicode fixes.
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 13 Apr 2011 22:14:14 +0000 (22:14 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 13 Apr 2011 22:14:14 +0000 (22:14 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@978 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/settings/base.py
forum/skins/default/templates/notifications/answeraccepted.html
forum/skins/default/templates/notifications/base.html
forum/skins/default/templates/notifications/digest.html
forum/skins/default/templates/notifications/feedback.html
forum/skins/default/templates/notifications/newanswer.html
forum/skins/default/templates/notifications/newcomment.html
forum/skins/default/templates/notifications/newmember.html
forum/skins/default/templates/notifications/newquestion.html
forum/templatetags/extra_tags.py

index 7436f46593b4e2813f292b91662ed21323a15a9b..0e085e56933e1a245b87a669bbd2b7773c650ae0 100644 (file)
@@ -1,5 +1,5 @@
 import django.dispatch
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_unicode, smart_unicode
 from datetime import datetime, timedelta
 import logging
 
@@ -42,7 +42,7 @@ class BaseSetting(object):
         return str(self.value)
 
     def __unicode__(self):
-        return unicode(self.value)
+        return smart_unicode(self.value)
 
     @property
     def value(self):
index 7658087f9fc2e0eca44aa5589bdf995a134a7a25..6d9c041cf557d9811172f083955806a6a8fc02ea 100644 (file)
@@ -1,14 +1,14 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
-    answer_author = html.mark_safe(answer.author.username)
-    question = answer.question
-    question_title = html.mark_safe(question.title)
-    accepted_by = html.mark_safe(answer.nstate.accepted.by.username)
-    accepted_by_link = html.objlink(answer.nstate.accepted.by, style=settings.EMAIL_ANCHOR_STYLE)
-    answer_author_link = html.objlink(answer.author, style=settings.EMAIL_ANCHOR_STYLE)
-    question_link = html.objlink(question, style=settings.EMAIL_ANCHOR_STYLE)
+    prefix = html.mark_safe(smart_str(settings.EMAIL_SUBJECT_PREFIX))
+    answer_author = html.mark_safe(smart_str(answer.author.username))
+    question = smart_str(answer.question)
+    question_title = html.mark_safe(smart_str(question.title))
+    accepted_by = html.mark_safe(smart_str(answer.nstate.accepted.by.username))
+    accepted_by_link = html.objlink(smart_str(answer.nstate.accepted.by), style=settings.EMAIL_ANCHOR_STYLE)
+    answer_author_link = html.objlink(smart_str(answer.author), style=settings.EMAIL_ANCHOR_STYLE)
+    question_link = html.objlink(smart_str(question), style=settings.EMAIL_ANCHOR_STYLE)
 {% enddeclare %}
 
 {% email %}
index ca1f5f64cf4a09704e4b8dbf62f9001fde812f10..18ac9db273633cf12e2321ec8de644d366ca76ac 100644 (file)
@@ -1,8 +1,8 @@
 {% load extra_filters extra_tags i18n email_tags %}
 
 {% declare %}
-    p_style = settings.EMAIL_PARAGRAPH_STYLE
-    a_style = settings.EMAIL_ANCHOR_STYLE
+    p_style = smart_str(settings.EMAIL_PARAGRAPH_STYLE)
+    a_style = smart_str(settings.EMAIL_ANCHOR_STYLE)
     hr_style = "color:#ccc;border:0;height:1px;background-color:#ccc;margin-bottom:20px;"
     small_style = "color:#333333;font-family:'Lucida Grande', Trebuchet, Helvetica, sans-serif;font-size:12px;"
     table_style = "border:20px %s solid;margin:10px auto 10px auto;width:750px;text-align:left;" % settings.EMAIL_BORDER_COLOR
index e986d4b5907948bcd7fabef80c1c36a63c1e13ac..91757b86f4fe22af07b3fa4386bbbac6e03f7ebb 100644 (file)
@@ -1,11 +1,11 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
-    app_name = settings.APP_SHORT_NAME
+    prefix = html.mark_safe(smart_str(settings.EMAIL_SUBJECT_PREFIX))
+    app_name = smart_unicode(settings.APP_SHORT_NAME)
     app_url = settings.APP_URL
 
-    new_member_links = html.mark_safe(", ".join([html.objlink(u, style=settings.EMAIL_ANCHOR_STYLE) for u in new_members]))
+    new_member_links = html.mark_safe(smart_unicode(", ".join([html.objlink(u, style=settings.EMAIL_ANCHOR_STYLE) for u in new_members])))
     new_question_count = digest.count
 
 {% enddeclare %}
 
     {% htmlcontent notifications/base.html %}
         {% declare %}
-            new_questions_link = html.hyperlink(app_url + reverse('questions') + '?sort=' + _('latest'), _('new questions'), style=a_style)
+            new_questions_link = html.hyperlink(smart_unicode(app_url) + reverse('questions') + '?sort=' + _('latest'), smart_unicode(_('new questions')), style=a_style)
             user_questions = digest.get_for_user(recipient)
-            subscriptions_link = html.hyperlink(app_url + recipient.get_subscribed_url(), _('subscriptions'), style=a_style)
+            subscribed_url = '%s%s' % (app_url, recipient.get_subscribed_url())
+            subscriptions_link = html.hyperlink(subscribed_url, _('subscriptions'), style=a_style)
         {% enddeclare %}
 
         <p style="{{ p_style }}">
@@ -92,7 +93,7 @@
 
         {% if recipient.is_superuser %}
         {% declare %}
-            flagged_url = html.hyperlink(app_url + reverse('admin_flagged_posts'), str(flagged_count) + ' ' + _('posts'), style=a_style)
+            flagged_url = html.hyperlink(smart_unicode(app_url + reverse('admin_flagged_posts')), smart_unicode(str(flagged_count) + ' ' + _('posts')), style=a_style)
         {% enddeclare %}
         <p style="{{ p_style }}">
             {% blocktrans %}
index 52aa6adace5b593420d3fb95d5460846b53ac336..bb70300e3973d15a0c472bbe0c28dde82500a322 100644 (file)
@@ -1,8 +1,8 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
-    app_name = html.mark_safe(settings.APP_SHORT_NAME)
+    prefix = smart_str(settings.EMAIL_SUBJECT_PREFIX)
+    app_name = smart_str(settings.APP_SHORT_NAME)
 
     exclude_greeting = True
     exclude_finetune = True
index e9bbaaa1b8ca8bb61332a161ce08176a1405aaea..5936d5230f9ef1a7ab1c7eb5f0488cf8d581f4f7 100644 (file)
@@ -1,15 +1,15 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
-    app_name = settings.APP_SHORT_NAME
-    safe_app_name = html.mark_safe(settings.APP_SHORT_NAME)
-    answer_author = html.mark_safe(answer.author.username)
-    question = answer.question
-    question_title = html.mark_safe(question.title)
-    safe_body = html.html2text(answer.html)
-    author_link = html.objlink(answer.author, style=settings.EMAIL_ANCHOR_STYLE)
-    question_link = html.objlink(question, style=settings.EMAIL_ANCHOR_STYLE)
+    prefix = smart_str(html.mark_safe(settings.EMAIL_SUBJECT_PREFIX))
+    app_name = smart_str(settings.APP_SHORT_NAME)
+    safe_app_name = smart_str(html.mark_safe(settings.APP_SHORT_NAME))
+    answer_author = smart_str(html.mark_safe(answer.author.username))
+    question = smart_str(answer.question)
+    question_title = smart_str(html.mark_safe(question.title))
+    safe_body = smart_str(html.html2text(answer.html))
+    author_link = smart_str(html.objlink(answer.author, style=settings.EMAIL_ANCHOR_STYLE))
+    question_link = smart_str(html.objlink(question, style=settings.EMAIL_ANCHOR_STYLE))
 {% enddeclare %}
 
 {% email %}
index 9963a4678804f6a8e7712056f4f69e8bea3c57c8..d629f64790ac57e165297e6c49d078b7e4bcbc92 100644 (file)
@@ -1,16 +1,16 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
+    prefix = html.mark_safe(smart_str(settings.EMAIL_SUBJECT_PREFIX))
     post = comment.parent
     question = post.question and post.question or post
-    post_author = post.author.username
-    safe_post_author = html.mark_safe(post.author.username)
-    comment_author = html.mark_safe(comment.author)
-    question_title = html.mark_safe(question.title)
-    safe_body = html.html2text(comment.comment)
-    author_link = html.objlink(comment.author, style=settings.EMAIL_ANCHOR_STYLE)
-    question_link = html.objlink(question, style=settings.EMAIL_ANCHOR_STYLE)
+    post_author = smart_str(post.author.username)
+    safe_post_author = html.mark_safe(smart_str(post.author.username))
+    comment_author = html.mark_safe(smart_str(comment.author))
+    question_title = html.mark_safe(smart_str(question.title))
+    safe_body = html.html2text(smart_str(comment.comment))
+    author_link = html.objlink(smart_str(comment.author), style=settings.EMAIL_ANCHOR_STYLE)
+    question_link = html.objlink(smart_str(question), style=settings.EMAIL_ANCHOR_STYLE)
 {% enddeclare %}
 
 {% email %}
index 8efbe7281e960a2d408b3cf22821b7a9df4c5a9a..5de2f294319bc744e452c8229ea88e7c03e271f5 100644 (file)
@@ -1,14 +1,14 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
-    app_name = settings.APP_SHORT_NAME
-    safe_app_name = html.mark_safe(settings.APP_SHORT_NAME)
-    app_url = settings.APP_URL
-    newmember_name = newmember.username
-    safe_newmember_name = html.mark_safe(newmember.username)
-    newmember_url = newmember.get_profile_url()
-    newmember_link = html.objlink(newmember, style=settings.EMAIL_ANCHOR_STYLE)
+    prefix = html.mark_safe(smart_str(settings.EMAIL_SUBJECT_PREFIX))
+    app_name = smart_str(settings.APP_SHORT_NAME)
+    safe_app_name = html.mark_safe(smart_str(settings.APP_SHORT_NAME))
+    app_url = smart_str(settings.APP_URL)
+    newmember_name = smart_str(newmember.username)
+    safe_newmember_name = html.mark_safe(smart_str(newmember.username))
+    newmember_url = smart_str(newmember.get_profile_url())
+    newmember_link = html.objlink(smart_str(newmember), style=settings.EMAIL_ANCHOR_STYLE)
 {% enddeclare %}
 
 {% email %}
index 7068bbbc2e7aaa5abd1ec06c735ac6922544a00b..ae4101758765aca4d571a6bb42cbd94d53fc7554 100644 (file)
@@ -1,17 +1,17 @@
 {% load i18n extra_tags email_tags %}
 
 {% declare %}
-    prefix = html.mark_safe(settings.EMAIL_SUBJECT_PREFIX)
-    app_name = settings.APP_SHORT_NAME
-    safe_app_name = html.mark_safe(settings.APP_SHORT_NAME)
-    question_author = html.mark_safe(question.author.username)
-    question_url = settings.APP_URL + question.get_absolute_url()
-    question_title = html.mark_safe(question.title)
-    question_tags = html.mark_safe(question.tagnames)
-    safe_body = html.html2text(question.html)
-    author_link = html.objlink(question.author, style=settings.EMAIL_ANCHOR_STYLE)
-    question_link = html.objlink(question, style=settings.EMAIL_ANCHOR_STYLE)
-    tag_links = html.mark_safe(" ".join([html.objlink(t, style=settings.EMAIL_ANCHOR_STYLE) for t in question.tags.all()]))
+    prefix = html.mark_safe(smart_str(settings.EMAIL_SUBJECT_PREFIX))
+    app_name = smart_str(settings.APP_SHORT_NAME)
+    safe_app_name = html.mark_safe(smart_str(settings.APP_SHORT_NAME))
+    question_author = html.mark_safe(smart_str(question.author.username))
+    question_url = smart_str(settings.APP_URL + question.get_absolute_url())
+    question_title = html.mark_safe(smart_str(question.title))
+    question_tags = html.mark_safe(smart_str(question.tagnames))
+    safe_body = html.html2text(smart_str(question.html))
+    author_link = html.objlink(smart_str(question.author), style=settings.EMAIL_ANCHOR_STYLE)
+    question_link = html.objlink(smart_str(question), style=settings.EMAIL_ANCHOR_STYLE)
+    tag_links = html.mark_safe(smart_str(" ".join([html.objlink(t, style=settings.EMAIL_ANCHOR_STYLE) for t in question.tags.all()])))
 {% enddeclare %}
 
 {% email %}
index b9e95eb004dc8f61457d3aa9a13e6de39cdc7b5c..d5533b6c9d936b4cbeac5045b4c9b8689e37b7af 100644 (file)
@@ -7,7 +7,7 @@ import re
 import logging
 import random
 from django import template
-from django.utils.encoding import smart_unicode
+from django.utils.encoding import smart_unicode, force_unicode, smart_str
 from django.utils.safestring import mark_safe
 from django.utils import dateformat
 from forum.models import Question, Answer, QuestionRevision, AnswerRevision, NodeRevision
@@ -278,10 +278,15 @@ class DeclareNode(template.Node):
                 d['os'] = os
                 d['html'] = html
                 d['reverse'] = reverse
+                d['smart_str'] = smart_str
+                d['smart_unicode'] = smart_unicode
+                d['force_unicode'] = force_unicode
                 for c in clist:
                     d.update(c)
                 try:
-                    context[m.group(1).strip()] = eval(m.group(3).strip(), d)
+                    command = m.group(3).strip()
+                    logging.error(command)
+                    context[m.group(1).strip()] = eval(command, d)
                 except Exception, e:
                     logging.error("Error in declare tag, when evaluating: %s" % m.group(3).strip())
                     raise