2011-12-01 21:12:20 +00:00
|
|
|
from django.db import models
|
|
|
|
from app.models import ItfModel
|
2012-01-18 10:51:34 +00:00
|
|
|
from sorl.thumbnail import get_thumbnail
|
2011-12-01 21:12:20 +00:00
|
|
|
|
|
|
|
class EmailerIssue(ItfModel):
|
|
|
|
title = models.CharField(max_length=512)
|
|
|
|
date = models.DateField()
|
|
|
|
issue_no = models.IntegerField()
|
|
|
|
published = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['-issue_no']
|
|
|
|
|
2011-12-06 12:45:46 +00:00
|
|
|
def info_dict(self):
|
|
|
|
return {
|
|
|
|
'issue': self,
|
|
|
|
'weblinks': Weblink.objects.filter(issue=self),
|
|
|
|
'articles': EmailerArticle.objects.filter(issue=self),
|
|
|
|
'bbitems': BulletinBoardItem.objects.filter(issue=self)
|
|
|
|
}
|
|
|
|
|
|
|
|
def list_dict(self):
|
|
|
|
return {
|
|
|
|
'id': self.id,
|
|
|
|
'title': self.title
|
|
|
|
}
|
|
|
|
|
2011-12-27 09:18:37 +00:00
|
|
|
def main_image(self):
|
|
|
|
for article in self.emailerarticle_set.all():
|
|
|
|
if article.main_image:
|
|
|
|
return article.main_image
|
|
|
|
return None
|
2011-12-01 21:12:20 +00:00
|
|
|
|
2012-01-13 09:19:19 +00:00
|
|
|
@classmethod
|
|
|
|
def get_qset(kls):
|
|
|
|
return kls.objects.filter(published=True)
|
|
|
|
|
2011-12-01 21:12:20 +00:00
|
|
|
class EmailerArticle(models.Model):
|
|
|
|
issue = models.ForeignKey(EmailerIssue)
|
|
|
|
title = models.CharField(max_length=512)
|
|
|
|
subtitle = models.TextField(blank=True)
|
|
|
|
author = models.CharField(max_length=512, blank=True)
|
|
|
|
author_bio = models.TextField(blank=True)
|
|
|
|
main_image = models.ImageField(upload_to='upload/images/emailer/', blank=True)
|
|
|
|
text = models.TextField()
|
|
|
|
position = models.IntegerField(null=True)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|
|
|
|
|
2011-12-27 09:18:37 +00:00
|
|
|
def get_images(self):
|
|
|
|
return self.articleimage_set.all()
|
2011-12-01 21:12:20 +00:00
|
|
|
|
2012-02-12 22:23:18 +00:00
|
|
|
def getImageHTML(self, short_name, typ):
|
2012-01-18 10:51:34 +00:00
|
|
|
img = ArticleImage.objects.filter(article=self).filter(short_name=short_name)
|
|
|
|
if len(img) > 0:
|
2012-02-12 22:23:18 +00:00
|
|
|
return img[0].getHTML(typ)
|
2012-01-18 10:51:34 +00:00
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
2011-12-01 21:12:20 +00:00
|
|
|
class ArticleImage(models.Model):
|
|
|
|
image = models.ImageField(upload_to='upload/images/emailer/')
|
|
|
|
caption = models.CharField(max_length=512, blank=True)
|
|
|
|
article = models.ForeignKey(EmailerArticle)
|
2011-12-05 13:34:24 +00:00
|
|
|
short_name = models.CharField(max_length=64, blank=True, help_text='Short name to insert images into article')
|
2011-12-01 21:12:20 +00:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.caption
|
|
|
|
|
2012-01-18 10:51:34 +00:00
|
|
|
def getThumbPath(self, size):
|
|
|
|
return get_thumbnail(self.image, size).url
|
|
|
|
|
2012-02-12 22:23:18 +00:00
|
|
|
def getHTML(self, typ):
|
2012-01-18 10:51:34 +00:00
|
|
|
thumb = self.getThumbPath("x380")
|
|
|
|
caption = self.caption
|
2012-01-18 11:22:28 +00:00
|
|
|
return "<img title='%s' src='%s' style='display:block;margin:0 auto;border:1px solid #f7c00c;' />" % (caption, thumb,)
|
2012-01-18 10:51:34 +00:00
|
|
|
|
2011-12-01 21:12:20 +00:00
|
|
|
|
|
|
|
class Weblink(models.Model):
|
|
|
|
url = models.URLField()
|
2011-12-05 13:34:24 +00:00
|
|
|
title = models.CharField(max_length=512)
|
2012-02-12 22:23:18 +00:00
|
|
|
box_title = models.CharField(max_length=512, blank=True)
|
2011-12-01 21:12:20 +00:00
|
|
|
text = models.TextField(blank=True)
|
|
|
|
issue = models.ForeignKey(EmailerIssue)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.url
|
|
|
|
|
|
|
|
|
|
|
|
class BulletinBoardItem(models.Model):
|
|
|
|
issue = models.ForeignKey(EmailerIssue)
|
|
|
|
title = models.CharField(max_length=512)
|
2012-02-12 22:23:18 +00:00
|
|
|
box_title = models.CharField(max_length=512, blank=True)
|
2011-12-01 21:12:20 +00:00
|
|
|
text = models.TextField()
|
|
|
|
position = models.IntegerField(default=1)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.title
|