Filter for adding quote marks

 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
28
29
from django import template

register = template.Library()

import re

@register.filter
def addquotes(text):
    text = unicode(text)

    start_paragraph = re.compile(r"^\s*<\s*p\s*>\s*", re.UNICODE | re.IGNORECASE)
    end_paragraph = re.compile(r"\s*</\s*p\s*>\s*$", re.UNICODE | re.IGNORECASE)

    match = start_paragraph.search(text)
    if match:
        s = match.group()
    else:
        s = u""
    text = s + u"&#8220;" + text[len(s):]

    match = end_paragraph.search(text)
    if match:
        s = match.group()
    else:
        s = u""
    text = text[:len(text)-len(s)] + u"&#8221;" + s
    print match
        
    return text

More like this

  1. Truncate HTML without breaking tags by olau 4 years ago
  2. getattr template filter by joshua 6 years, 2 months ago
  3. order_by template filter by marinho 5 years ago
  4. filter for extracting a number of paragraphs from any HTML code by rafadev 1 year, 11 months ago
  5. Advanced Search in django admin by visik7 2 years, 4 months ago

Comments

(Forgotten your password?)