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. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 6 months, 2 weeks ago
  2. Crispy Form by sourabhsinha396 7 months, 1 week ago
  3. ReadOnlySelect by mkoistinen 7 months, 3 weeks ago
  4. Verify events sent to your webhook endpoints by santos22 8 months, 3 weeks ago
  5. Django Language Middleware by agusmakmun 9 months ago

Comments

Please login first before commenting.