From 53d5a38f63a136df4bbec6011e594a5477ffee77 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 18 Jan 2012 16:23:35 +0530 Subject: [PATCH] add templatetags library --- itf/emailer/templatetags/__init__.py | 0 itf/emailer/templatetags/emailer.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 itf/emailer/templatetags/__init__.py create mode 100644 itf/emailer/templatetags/emailer.py diff --git a/itf/emailer/templatetags/__init__.py b/itf/emailer/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/itf/emailer/templatetags/emailer.py b/itf/emailer/templatetags/emailer.py new file mode 100644 index 0000000..ed8d982 --- /dev/null +++ b/itf/emailer/templatetags/emailer.py @@ -0,0 +1,16 @@ +from django import template +import re +from emailer.models import * + +register = template.Library() + +def insert_images(value, article_id): + regex = 'img\:(.*?)\r?\n' + article = EmailerArticle.objects.get(id=article_id) + matches = re.findall(regex, value) + for m in matches: + imgHTML = article.getImageHTML(m) + value = value.replace("img:" + m, imgHTML) + return value + +register.filter('insert_images', insert_images)