Photologue wiki-syntax templatetag

 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
30
import re

from trac.wiki.formatter import *

from django.template import Library, Node, Template, Context
from django.template.defaultfilters import stringfilter
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe

from photologue.models import Photo

def get_photologue_html(size,image):
        image = get_image(image)
        if not image:
                return "Bad image name"
        if size.lower() == "thumb":
                template = "photologue/thumb_snippet.html"
        else:
                template = "photologue/image_snippet.html"

        return render_to_string(template,{'image': image })

pattern = re.compile(r'\[\[([^:]+):(.+)\]\]')

@register.filter
@stringfilter

def yeagowiki(content):
        content = pattern.sub(lambda match: get_photologue_html(match.group(1),match.group(2)),content)
        return mark_safe(content)

More like this

  1. load m2m fields objects by dirol 1 year, 11 months ago
  2. Parse custom template tag's args or kwargs by t_rybik 1 year, 8 months ago
  3. Media RSS generation for Photologue by ltvolks 2 years, 10 months ago
  4. Pagination Alphabetically compatible with paginator_class by vascop 1 month ago
  5. Paginator TemplateTag by trbs 4 years, 1 month ago

Comments

jdriscoll (on September 27, 2008):

The Photologue project can be found here.

#

(Forgotten your password?)