summaryrefslogtreecommitdiff
path: root/apps/guide/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/guide/models.py')
-rw-r--r--apps/guide/models.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/apps/guide/models.py b/apps/guide/models.py
index 16c44fe..793b9f4 100644
--- a/apps/guide/models.py
+++ b/apps/guide/models.py
@@ -4,6 +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
@@ -12,6 +13,12 @@ from locations.models import Location,Region,Country
from blog.models import Entry
from photos.models import PhotoGallery
+def get_upload_path(self, filename):
+ return "images/guide-images/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename)
+
+def get_tn_path(self, filename):
+ return "images/guide-thumbnail/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename)
+
def image_url_replace(str):
str = str.replace('[[base_url]]', settings.IMAGES_URL)
return str
@@ -47,6 +54,12 @@ class Guide(models.Model):
meta_description = models.CharField(max_length=256, null=True, blank=True)
template_name = models.IntegerField(choices=TEMPLATES, default=0)
tags = TaggableManager(blank=True)
+ 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)
@property
@@ -69,12 +82,26 @@ class Guide(models.Model):
def get_absolute_url(self):
if self.location:
- return "/guide/location/%s/%s/" % (self.location.slug, self.slug)
+ return "/travel-guide/location/%s/%s/" % (self.location.slug, self.slug)
else:
- return "/guide/%s/" % (self.slug)
+ return "/travel-guide/%s/" % (self.slug)
+ def get_thumbnail_url(self):
+ image_dir, img = self.thumbnail.url.split('guide-thumbnail/')[1].split('/')
+ return '%sguide-thumbnail/%s/%s' %(settings.IMAGES_URL, image_dir, img)
+
+ def get_image_url(self):
+ image_dir, img = self.image.url.split('guide-images/')[1].split('/')
+ return '%sguide-images/%s/%s' %(settings.IMAGES_URL, image_dir, img)
def save(self):
+ #get image dimensions
+ if self.image:
+ 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
md = image_url_replace(self.body_markdown)
#run markdown
self.body_html = markdown_processor(md)