From efd11240d0ba1915913a51c6b3c52f2af5641b5d Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 18 Jan 2012 16:21:34 +0530 Subject: [PATCH] test image insertion --- itf/emailer/models.py | 16 ++++++++++++++++ itf/templates/emailer/email.html | 3 ++- itf/templates/modules/emailer/emailerissue.html | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/itf/emailer/models.py b/itf/emailer/models.py index 952484f..3a863c0 100755 --- a/itf/emailer/models.py +++ b/itf/emailer/models.py @@ -1,5 +1,6 @@ from django.db import models from app.models import ItfModel +from sorl.thumbnail import get_thumbnail class EmailerIssue(ItfModel): title = models.CharField(max_length=512) @@ -53,6 +54,13 @@ class EmailerArticle(models.Model): def get_images(self): return self.articleimage_set.all() + def getImgageHTML(self, short_name): + img = ArticleImage.objects.filter(article=self).filter(short_name=short_name) + if len(img) > 0: + return img.getHTML() + else: + return '' + class ArticleImage(models.Model): image = models.ImageField(upload_to='upload/images/emailer/') caption = models.CharField(max_length=512, blank=True) @@ -62,6 +70,14 @@ class ArticleImage(models.Model): def __unicode__(self): return self.caption + def getThumbPath(self, size): + return get_thumbnail(self.image, size).url + + def getHTML(self): + thumb = self.getThumbPath("x380") + caption = self.caption + return "" % (caption, thumb,) + class Weblink(models.Model): url = models.URLField() diff --git a/itf/templates/emailer/email.html b/itf/templates/emailer/email.html index 26fdb0d..2caae36 100755 --- a/itf/templates/emailer/email.html +++ b/itf/templates/emailer/email.html @@ -1,5 +1,6 @@ {% load markup %} {% load thumbnail %} +{% load emailer %} @@ -80,7 +81,7 @@ +

{{ article.text|insert_images:article.id|markdown }}

-

{{ article.text|markdown }}

diff --git a/itf/templates/modules/emailer/emailerissue.html b/itf/templates/modules/emailer/emailerissue.html index 7ec4fb9..8df5757 100755 --- a/itf/templates/modules/emailer/emailerissue.html +++ b/itf/templates/modules/emailer/emailerissue.html @@ -61,7 +61,7 @@ {% if article.main_image %}
- {% thumbnail article.main_image "570" as im %} + {% thumbnail article.main_image "x380" as im %} {% endthumbnail %}