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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.