diff options
Diffstat (limited to 'app/guide/models.py')
-rw-r--r-- | app/guide/models.py | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/app/guide/models.py b/app/guide/models.py index 90f63e1..9df83d3 100644 --- a/app/guide/models.py +++ b/app/guide/models.py @@ -3,59 +3,60 @@ from django.contrib.gis.db import models from django.conf import settings from django.contrib.sitemaps import Sitemap from django.contrib.syndication.views import Feed -from django.template.defaultfilters import truncatewords_html from PIL import Image import markdown -from taggit.managers import TaggableManager -from locations.models import Location,Region,Country +from taggit.managers import TaggableManager +from locations.models import Location 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) + 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) - + 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 -def markdown_processor(md): - return markdown.markdown(md, ['footnotes'],safe_mode = False) -PUB_STATUS = ( - (0, 'Draft'), - (1, 'Published'), - ) +def markdown_processor(md): + return markdown.markdown(md, ['footnotes'], safe_mode=False) + -TEMPLATES = ( - (0, 'single'), - (1, 'double'), - (2, 'single-dark'), - (3, 'double-dark'), - ) - class Guide(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') entry = models.ForeignKey(Entry, null=True, blank=True) body_html = models.TextField(blank=True) body_markdown = models.TextField() - dek = models.TextField(null=True,blank=True) + dek = models.TextField(null=True, blank=True) pub_date = models.DateTimeField('Date published') location = models.ForeignKey(Location, null=True, blank=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) status = models.IntegerField(choices=PUB_STATUS, default=0) photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') meta_description = models.CharField(max_length=256, null=True, blank=True) + TEMPLATES = ( + (0, 'single'), + (1, 'double'), + (2, 'single-dark'), + (3, 'double-dark'), + ) template_name = models.IntegerField(choices=TEMPLATES, default=0) tags = TaggableManager(blank=True) - image = models.FileField(upload_to=get_upload_path, null=True,blank=True) - thumbnail = models.FileField(upload_to=get_tn_path, null=True,blank=True) + image = models.FileField(upload_to=get_upload_path, null=True, blank=True) + thumbnail = models.FileField(upload_to=get_tn_path, null=True, blank=True) - @property def longitude(self): '''Get the site's longitude.''' @@ -64,8 +65,8 @@ class Guide(models.Model): @property def latitude(self): '''Get the site's latitude.''' - return self.point.y - + return self.point.y + class Meta: ordering = ('-pub_date',) get_latest_by = 'pub_date' @@ -79,29 +80,30 @@ class Guide(models.Model): return "/travel-guide/location/%s/%s/" % (self.location.slug, self.slug) else: 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) - + 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): + 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 + self.image_width, self.image_height = img.size #same for thumb img = Image.open(self.thumbnail) - self.thumb_width, self.thumb_height = img.size + self.thumb_width, self.thumb_height = img.size md = image_url_replace(self.body_markdown) #run markdown self.body_html = markdown_processor(md) - self.dek == markdown.markdown(self.dek, safe_mode = False) + self.dek = markdown.markdown(self.dek, safe_mode=False) super(Guide, self).save() + class GuideSitemap(Sitemap): changefreq = "never" priority = 1.0 @@ -112,6 +114,7 @@ class GuideSitemap(Sitemap): def lastmod(self, obj): return obj.pub_date + class GuideFull(Feed): title = "Luxagraf: Topographical Writings" link = "/writing/" |