Login

E-mail quoting filters and tags

Author:
ChipX86
Posted:
June 10, 2007
Language:
Python
Version:
.96
Tags:
filter tag filters email tags quoting
Score:
0 (after 0 ratings)

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

  1. email_links by sansmojo 7 years, 10 months ago
  2. Template Tag to protect the E-mail address by nitinhayaran 5 years, 2 months ago
  3. WordWrap template tag by Daeg 8 years ago
  4. Simple e-mail template tag by dchandek 6 years, 12 months ago
  5. Days Since Filter by joe4444 8 years, 1 month ago

Comments

Please login first before commenting.