From: jordan Date: Wed, 13 Apr 2011 22:14:14 +0000 (+0000) Subject: OSQA-600, notification templates unicode fixes. X-Git-Tag: live~335 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/2dd371482b63066c3c8c828977efe2014c5dc13e OSQA-600, notification templates unicode fixes. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@978 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/settings/base.py b/forum/settings/base.py index 7436f46..0e085e5 100644 --- a/forum/settings/base.py +++ b/forum/settings/base.py @@ -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): diff --git a/forum/skins/default/templates/notifications/answeraccepted.html b/forum/skins/default/templates/notifications/answeraccepted.html index 7658087..6d9c041 100644 --- a/forum/skins/default/templates/notifications/answeraccepted.html +++ b/forum/skins/default/templates/notifications/answeraccepted.html @@ -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 %} diff --git a/forum/skins/default/templates/notifications/base.html b/forum/skins/default/templates/notifications/base.html index ca1f5f6..18ac9db 100644 --- a/forum/skins/default/templates/notifications/base.html +++ b/forum/skins/default/templates/notifications/base.html @@ -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 diff --git a/forum/skins/default/templates/notifications/digest.html b/forum/skins/default/templates/notifications/digest.html index e986d4b..91757b8 100644 --- a/forum/skins/default/templates/notifications/digest.html +++ b/forum/skins/default/templates/notifications/digest.html @@ -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 %} @@ -15,9 +15,10 @@ {% 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 %}

@@ -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 %}

{% blocktrans %} diff --git a/forum/skins/default/templates/notifications/feedback.html b/forum/skins/default/templates/notifications/feedback.html index 52aa6ad..bb70300 100644 --- a/forum/skins/default/templates/notifications/feedback.html +++ b/forum/skins/default/templates/notifications/feedback.html @@ -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 diff --git a/forum/skins/default/templates/notifications/newanswer.html b/forum/skins/default/templates/notifications/newanswer.html index e9bbaaa..5936d52 100644 --- a/forum/skins/default/templates/notifications/newanswer.html +++ b/forum/skins/default/templates/notifications/newanswer.html @@ -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 %} diff --git a/forum/skins/default/templates/notifications/newcomment.html b/forum/skins/default/templates/notifications/newcomment.html index 9963a46..d629f64 100644 --- a/forum/skins/default/templates/notifications/newcomment.html +++ b/forum/skins/default/templates/notifications/newcomment.html @@ -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 %} diff --git a/forum/skins/default/templates/notifications/newmember.html b/forum/skins/default/templates/notifications/newmember.html index 8efbe72..5de2f29 100644 --- a/forum/skins/default/templates/notifications/newmember.html +++ b/forum/skins/default/templates/notifications/newmember.html @@ -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 %} diff --git a/forum/skins/default/templates/notifications/newquestion.html b/forum/skins/default/templates/notifications/newquestion.html index 7068bbb..ae41017 100644 --- a/forum/skins/default/templates/notifications/newquestion.html +++ b/forum/skins/default/templates/notifications/newquestion.html @@ -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 %} diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index b9e95eb..d5533b6 100644 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -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