Ttemplates and filters for quoting e-mails in templates.
The quoted_email
tag takes a template, renders it and quotes the result.
The quote_text
filter puts one or more levels of quotes around the passed text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | class QuotedEmail(template.Node):
def __init__(self, template_name):
self.template_name = template_name
def render(self, context):
return quote_text(render_to_string(self.template_name, context))
@register.tag
def quoted_email(parser, token):
try:
tag_name, template_name = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires a template name"
return QuotedEmail(template_name)
@register.filter
def quote_text(text, level=1):
lines = text.split("\n")
quoted = ""
for line in lines:
quoted += "%s%s\n" % ("> " * level, line)
return quoted.rstrip()
|
More like this
- FileField having auto upload_to path by junaidmgithub 14 hours, 26 minutes ago
- LazyPrimaryKeyRelatedField by LLyaudet 1 week, 1 day ago
- CacheInDictManager by LLyaudet 1 week, 1 day ago
- MYSQL Full Text Expression by Bidaya0 1 week, 2 days ago
- Custom model manager chaining (Python 3 re-write) by Spotted1270 2 weeks, 1 day ago
Comments
Please login first before commenting.