diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/blog/models.py | 27 | ||||
-rw-r--r-- | apps/projects/models/natparks.py | 9 |
2 files changed, 28 insertions, 8 deletions
diff --git a/apps/blog/models.py b/apps/blog/models.py index ff510f7..0c6d93e 100644 --- a/apps/blog/models.py +++ b/apps/blog/models.py @@ -4,7 +4,7 @@ from django.conf import settings from django.contrib.syndication.feeds import Feed from django.contrib.sitemaps import Sitemap from django.template.defaultfilters import truncatewords_html - +from PIL import Image from utils import markdown2 as markdown @@ -21,7 +21,6 @@ def get_tn_path(self, filename): def image_url_replace(str): str = str.replace('[[base_url]]', settings.IMAGES_URL) - print str return str def markdown_processor(md): @@ -78,7 +77,11 @@ class Entry(models.Model): status = models.IntegerField(choices=PUB_STATUS, default=0) photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') image = models.FileField(upload_to=get_upload_path, null=True,blank=True) + image_height = models.CharField(max_length=20, null=True,blank=True) + image_width = models.CharField(max_length=20, null=True,blank=True) thumbnail = models.FileField(upload_to=get_tn_path, null=True,blank=True) + thumb_height = models.CharField(max_length=20, null=True,blank=True) + thumb_width = models.CharField(max_length=20, null=True,blank=True) meta_description = models.CharField(max_length=256, null=True, blank=True) topics = models.ManyToManyField(Topic, blank=True) template_name = models.IntegerField(choices=TEMPLATES, default=0) @@ -123,12 +126,20 @@ class Entry(models.Model): return '%spost-images/%s/%s' %(settings.IMAGES_URL, image_dir, img) def save(self): - md = image_url_replace(self.body_markdown) - html,lede = markdown_processor(md) - self.body_html = html - self.lede = lede - self.dek == markdown.markdown(self.dek, safe_mode = False) - super(Entry, self).save() + #get image dimensions + img = Image.open(self.image) + self.image_width, self.image_height = img.size + #same for thumb + img = Image.open(self.thumbnail) + self.thumb_width, self.thumb_height = img.size + #find and replace image urls + md = image_url_replace(self.body_markdown) + #run markdown + html,lede = markdown_processor(md) + self.body_html = html + self.lede = lede + self.dek == markdown.markdown(self.dek, safe_mode = False) + super(Entry, self).save() class BlogSitemap(Sitemap): changefreq = "never" diff --git a/apps/projects/models/natparks.py b/apps/projects/models/natparks.py index fa0c84b..f4a739d 100644 --- a/apps/projects/models/natparks.py +++ b/apps/projects/models/natparks.py @@ -1,8 +1,10 @@ from django.contrib.gis.db import models +from PIL import Image from blog.models import Entry from photos.models import PhotoGallery from locations.models import State + PUB_STATUS = ( (0, 'Draft'), (1, 'Published'), @@ -35,6 +37,8 @@ class NationalParks(models.Model): post = models.ForeignKey(Entry, null=True) gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') image = models.FileField(upload_to=get_upload_path, null=True,blank=True,help_text="width: 980px, height: > 450px") + image_height = models.CharField(max_length=20, null=True,blank=True) + image_width = models.CharField(max_length=20, null=True,blank=True) objects = models.GeoManager() class Meta: @@ -45,3 +49,8 @@ class NationalParks(models.Model): def __unicode__(self): return self.unit_name + def save(self): + #get image dimensions + img = Image.open(self.image) + self.image_width, self.image_height = img.size + super(NationalParks, self).save()
\ No newline at end of file |