diff options
author | luxagraf <sng@luxagraf.net> | 2013-05-15 13:02:24 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2013-05-15 13:02:24 -0400 |
commit | aa7bc766ac27c669162bf903711c54f74f3758b1 (patch) | |
tree | 80b6ef1b87f5005171fddda5349959226fd2b930 /app/blog/models.py | |
parent | ccc6f1af97e2630eb9b5a9b043f308030e61fdbc (diff) |
fixed image thumbnails, expanded body text entry field, switched map to OSM and added the ability to associate asides with an entry -- still need to add javascript to dynamically create asides.
Diffstat (limited to 'app/blog/models.py')
-rw-r--r-- | app/blog/models.py | 116 |
1 files changed, 41 insertions, 75 deletions
diff --git a/app/blog/models.py b/app/blog/models.py index a1025cc..bf319ce 100644 --- a/app/blog/models.py +++ b/app/blog/models.py @@ -1,12 +1,14 @@ import datetime from django.contrib.gis.db import models +from django.utils.html import format_html from django.conf import settings from django.contrib.syndication.views 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 +#http://freewisdom.org/projects/python-markdown/ +import markdown from photos.models import PhotoGallery from locations.models import Location,Region @@ -21,11 +23,6 @@ def image_url_replace(str): str = str.replace('[[base_url]]', settings.IMAGES_URL) return str -def markdown_processor(md): - 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'), @@ -47,60 +44,29 @@ class PostImage(models.Model): def __unicode__(self): return self.title - def output_tags(self): - return force_unicode('<img src="%s%s" alt="%s" class="postpic"/>' % \ + def post_image(self): + return format_html('<img src="%s%s" alt="%s" class="postpic"/>' % \ (settings.IMAGES_URL, self.image.url.split('images')[1].split('/',1)[1], self.title)) + post_image.allow_tags = True -class Topic(models.Model): - name = models.CharField(max_length=100) - slug = models.SlugField() - - def __unicode__(self): - return self.name - - def get_absolute_url(self): - return "/topics/%s/" % (self.slug) - class Entry(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') - lede = models.TextField(blank=True) body_html = models.TextField(blank=True) body_markdown = models.TextField() dek = models.TextField(null=True,blank=True) pub_date = models.DateTimeField('Date published') - enable_comments = models.BooleanField(default=True) + enable_comments = models.BooleanField(default=False) point = models.PointField(null=True, blank=True) - location = models.ForeignKey(Location, null=True) - region = models.ForeignKey(Region, null=True) + location = models.ForeignKey(Location, null=True, blank=True) 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) - location_name = models.CharField(max_length=200, null=True,blank=True) - state_name = models.CharField(max_length=200, null=True,blank=True) - country_name = models.CharField(max_length=200, null=True,blank=True) - state_iso = models.CharField(max_length=2, null=True,blank=True) - country_iso = models.CharField(max_length=2, null=True,blank=True) - - @property - def longitude(self): - '''Get the site's longitude.''' - return self.point.x - @property - def latitude(self): - '''Get the site's latitude.''' - return self.point.y - class Meta: ordering = ('-pub_date',) get_latest_by = 'pub_date' @@ -111,16 +77,7 @@ class Entry(models.Model): def get_absolute_url(self): return "/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug) - - @property - def get_previous_published(self): - return self.get_previous_by_pub_date(status__exact=1) - - @property - def get_next_published(self): - return self.get_next_by_pub_date(status__exact=1) - - + def comment_period_open(self): return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date @@ -131,28 +88,43 @@ class Entry(models.Model): def get_image_url(self): image_dir, img = self.image.url.split('post-images/')[1].split('/') return '%spost-images/%s/%s' %(settings.IMAGES_URL, image_dir, img) - + + @property + def region(self): + return self.location.state.country.lux_region + + @property + def longitude(self): + '''Get the site's longitude.''' + return self.point.x + + @property + def latitude(self): + '''Get the site's latitude.''' + return self.point.y + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @property + def get_next_published(self): + return self.get_next_by_pub_date(status__exact=1) + + def save(self): - #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.body_html = markdown.markdown(self.body_markdown, extensions=['extra',], safe_mode = False) self.dek == markdown.markdown(self.dek, safe_mode = False) - self.location_name = self.location.name - self.state_name = self.location.state.name - self.country_name = self.location.state.country.name - self.state_iso = self.location.state.code - self.country_iso = self.location.state.country.iso2 super(Entry, self).save() +class EntryAside(models.Model): + title = models.CharField(max_length=200) + body = models.TextField(null=True,blank=True) + entry = models.ForeignKey(Entry) + + + class BlogSitemap(Sitemap): changefreq = "never" priority = 1.0 @@ -171,9 +143,3 @@ class LatestFull(Feed): def items(self): return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10] - - -from django.dispatch import dispatcher -from django.db.models import signals - - |