diff options
author | luxagraf <sng@luxagraf.net> | 2012-09-22 22:27:04 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2012-09-22 22:27:04 -0400 |
commit | efb623af0bcb47d510501c282e1326b11343a29c (patch) | |
tree | 3a35fb19f5eba3b219c65277a5fb712cbe9604ac /apps/blog/models.py | |
parent | 0b481fd7931c2ae20ca21f89a87f2ba6a6c01e10 (diff) |
site reorg
Diffstat (limited to 'apps/blog/models.py')
-rw-r--r-- | apps/blog/models.py | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/apps/blog/models.py b/apps/blog/models.py deleted file mode 100644 index 37841fe..0000000 --- a/apps/blog/models.py +++ /dev/null @@ -1,180 +0,0 @@ -import datetime -from django.contrib.gis.db import models -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 - -from photos.models import PhotoGallery -from locations.models import Location,Region -#from locations.signals import create_location_item -from blog.signals import update_recent - -def get_upload_path(self, 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 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'), - (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"))) - - def __unicode__(self): - return self.title - - def output_tags(self): - return force_unicode('<img src="%s%s" alt="%s" class="postpic"/>' % \ - (settings.IMAGES_URL, self.image.url.split('images')[1].split('/',1)[1], self.title)) - - -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) - point = models.PointField(null=True, blank=True) - location = models.ForeignKey(Location, null=True) - region = models.ForeignKey(Region, null=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' - verbose_name_plural = 'entries' - - def __unicode__(self): - return self.title - - 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 - - def get_thumbnail_url(self): - image_dir, img = self.thumbnail.url.split('post-thumbnail/')[1].split('/') - return '%spost-thumbnail/%s/%s' %(settings.IMAGES_URL, image_dir, img) - - 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) - - 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.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 BlogSitemap(Sitemap): - changefreq = "never" - priority = 1.0 - - def items(self): - return Entry.objects.filter(status=1) - - def lastmod(self, obj): - return obj.pub_date - -class LatestFull(Feed): - title = "Luxagraf: Topographical Writings" - link = "/writing/" - description = "Latest postings to luxagraf.net" - description_template = 'feeds/blog_description.html' - - 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 - -signals.post_save.connect(update_recent, sender=Entry) - |