diff options
Diffstat (limited to 'apps/blog/models.py')
-rw-r--r-- | apps/blog/models.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/apps/blog/models.py b/apps/blog/models.py index fb0dac6..c3b5a3a 100644 --- a/apps/blog/models.py +++ b/apps/blog/models.py @@ -16,14 +16,29 @@ from locations.models import Location,Region from blog.signals import update_recent def get_upload_path(self, filename): - return "images/post-thumbs/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + return "images/post-images/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + +def get_tn_path(self, filename): + return "images/post-thumbnail/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + def markdown_processor(md): - processed = markdown.markdown(md, safe_mode = False).split('<break>') + processed = markdown.markdown(md, ['footnotes'],safe_mode = False).split('<break>') html = processed[0]+processed[1] lede = processed[0] return html, lede +PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + +TEMPLATES = ( + (0, 'single'), + (1, 'double'), + (2, 'single-dark'), + (3, 'double-dark'), + ) class PostImage(models.Model): title = models.CharField(max_length=100) image = models.ImageField(upload_to="%s%s" %(settings.IMAGES_ROOT, datetime.datetime.today().strftime("%Y"))) @@ -59,15 +74,13 @@ class Entry(models.Model): point = models.PointField(null=True) location = models.ForeignKey(Location, null=True) region = models.ForeignKey(Region, null=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') - thumbnail = models.FileField(upload_to=get_upload_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) 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) @property def longitude(self): @@ -108,6 +121,12 @@ class Entry(models.Model): else: return '%s%s' %(settings.IMAGES_URL, self.thumbnail.url[33:]) + def get_image_url(self): + if settings.DEVELOPMENT == True: + return '%s%s' %(settings.IMAGES_URL, self.image.url[35:]) + else: + return '%s%s' %(settings.IMAGES_URL, self.image.url[33:]) + def save(self): html,lede = markdown_processor(self.body_markdown) self.body_html = html |