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
return str(self.value)
def __unicode__(self):
- return unicode(self.value)
+ return smart_unicode(self.value)
@property
def value(self):
{% 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 %}
{% 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
{% 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 }}">
{% 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 %}
{% 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
{% 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 %}
{% 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 %}
{% 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 %}
{% 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 %}
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
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