Login

Photologue wiki-syntax templatetag

Author:
yeago
Posted:
September 27, 2008
Language:
Python
Version:
1.0
Score:
2 (after 2 ratings)

updated 12/16/08

I run several blogs by visual-artists and web-designers who want a quick way to insert images into their blog without the awkwardness of WSYIWYG and without the technicality of code (eww...).

Thanks in advance for your input.

#Syntax in a blog goes:
[[thumb:the-image-slug]] # Gives you a thumbnail
[[image:the-image-slug]] # Presents full-size-image

Then of course:

{% blog.post|yeagowiki %}

You will also need to create some templates (see snippet). Here's a sample:

<!-- /templates/photologue/image_snippet.html -->
<div class="photologue-image">
    <a href="{% if url %}{{ url }}{% else %}/media/{{ image.image }}{% endif %}">
         <img src="{{ image.get_display_url }}" />
    </a>
    <p class="photologue-image-caption">{{ image.caption }}</p>
</div>
 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. Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 5 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 months ago

Comments

Please login first before commenting.