test image insertion

This commit is contained in:
Sanj 2012-01-18 16:21:34 +05:30
parent 1794d95315
commit efd11240d0
3 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from app.models import ItfModel from app.models import ItfModel
from sorl.thumbnail import get_thumbnail
class EmailerIssue(ItfModel): class EmailerIssue(ItfModel):
title = models.CharField(max_length=512) title = models.CharField(max_length=512)
@ -53,6 +54,13 @@ class EmailerArticle(models.Model):
def get_images(self): def get_images(self):
return self.articleimage_set.all() 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): class ArticleImage(models.Model):
image = models.ImageField(upload_to='upload/images/emailer/') image = models.ImageField(upload_to='upload/images/emailer/')
caption = models.CharField(max_length=512, blank=True) caption = models.CharField(max_length=512, blank=True)
@ -62,6 +70,14 @@ class ArticleImage(models.Model):
def __unicode__(self): def __unicode__(self):
return self.caption 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 "<img title='%s' src='%s' />" % (caption, thumb,)
class Weblink(models.Model): class Weblink(models.Model):
url = models.URLField() url = models.URLField()

View File

@ -1,5 +1,6 @@
{% load markup %} {% load markup %}
{% load thumbnail %} {% load thumbnail %}
{% load emailer %}
<table width="600" border="0" cellspacing="0" cellpadding="0"> <table width="600" border="0" cellspacing="0" cellpadding="0">
<tr> <tr>
@ -80,7 +81,7 @@
<tr> <tr>
<td style="width:580px; padding:10px 16px; color:#888; font-family:Arial, Helvetica, sans-serif; font-size:12px;"> <td style="width:580px; padding:10px 16px; color:#888; font-family:Arial, Helvetica, sans-serif; font-size:12px;">
<p>{{ article.text|markdown }}</p></td> <p>{{ article.text|insert_images:article.id|markdown }}</p></td>
</tr> </tr>
<tr> <tr>
<td style="width:580px; padding: 10px 16px; color:#888; font-family: Arial, Helvetica, sans-serif; font-size:12px; font-style:italic;"> <td style="width:580px; padding: 10px 16px; color:#888; font-family: Arial, Helvetica, sans-serif; font-size:12px; font-style:italic;">

View File

@ -61,7 +61,7 @@
{% if article.main_image %} {% if article.main_image %}
<div class="articleImg"> <div class="articleImg">
{% thumbnail article.main_image "570" as im %} {% thumbnail article.main_image "x380" as im %}
<img class="itfInfoImg" src="{{ im.url }}" /> <img class="itfInfoImg" src="{{ im.url }}" />
{% endthumbnail %} {% endthumbnail %}
</div><!-- ARTICLE IMAGE CLOSING --> </div><!-- ARTICLE IMAGE CLOSING -->