summaryrefslogtreecommitdiff
path: root/app/blog/models.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
committerluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
commit518b2d618bc10f93cfa44a83715593b8358eb9ce (patch)
treea07993c3ae31bed42f32c0e00788989568790716 /app/blog/models.py
parent4bae11bb25a8e3c43118891d17fd8e981ecf8dc6 (diff)
minor refactor to adoipt pep8 and pyflakes coding styles and clean up
some cruft that's been hangin round for years
Diffstat (limited to 'app/blog/models.py')
-rw-r--r--app/blog/models.py98
1 files changed, 50 insertions, 48 deletions
diff --git a/app/blog/models.py b/app/blog/models.py
index 1876460..e7f10ab 100644
--- a/app/blog/models.py
+++ b/app/blog/models.py
@@ -4,68 +4,70 @@ 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 django import forms
-
-#http://freewisdom.org/projects/python-markdown/
+# http://freewisdom.org/projects/python-markdown/
import markdown
-
from photos.models import PhotoGallery
-from locations.models import Location,Region
+from locations.models import Location
+
def get_upload_path(self, filename):
- return "images/post-images/%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)
+ 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
-PUB_STATUS = (
- (0, 'Draft'),
- (1, 'Published'),
- )
-
-TEMPLATES = (
- (0, 'single'),
- (1, 'double'),
- (2, 'single-dark'),
- (3, 'double-dark'),
- (4, 'bigimg'),
- (5, 'bigimg-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")))
+ image = models.ImageField(upload_to="%s/%s" % (settings.IMAGES_ROOT, datetime.datetime.today().strftime("%Y")))
def __unicode__(self):
return self.title
-
+
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))
+ 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 Entry(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique_for_date='pub_date')
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')
enable_comments = models.BooleanField(default=False)
point = models.PointField(null=True, blank=True)
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')
- 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)
meta_description = models.CharField(max_length=256, null=True, blank=True)
+ TEMPLATES = (
+ (0, 'single'),
+ (1, 'double'),
+ (2, 'single-dark'),
+ (3, 'double-dark'),
+ (4, 'bigimg'),
+ (5, 'bigimg-dark'),
+ )
template_name = models.IntegerField(choices=TEMPLATES, default=0)
class Meta:
@@ -73,35 +75,35 @@ class Entry(models.Model):
get_latest_by = 'pub_date'
verbose_name_plural = 'entries'
- def __unicode__(self):
+ def __str__(self):
return self.title
def get_absolute_url(self):
return "/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)
-
+
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)
-
+ 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)
+ return '%spost-images/%s/%s' % (settings.IMAGES_URL, image_dir, img)
@property
def state(self):
return self.location.state
-
+
@property
def country(self):
return self.location.state.country
-
+
@property
def region(self):
return self.location.state.country.lux_region
-
+
@property
def longitude(self):
'''Get the site's longitude.'''
@@ -110,34 +112,33 @@ class Entry(models.Model):
@property
def latitude(self):
'''Get the site's latitude.'''
- return self.point.y
-
+ return self.point.y
+
@property
def get_previous_published(self):
return self.get_previous_by_pub_date(status__exact=1)
-
- @property
+
+ @property
def get_next_published(self):
return self.get_next_by_pub_date(status__exact=1)
-
- def save(self):
+ def save(self):
md = image_url_replace(self.body_markdown)
- self.body_html = markdown.markdown(md, extensions=['extra',], safe_mode = False)
- self.dek == markdown.markdown(self.dek, safe_mode = False)
+ self.body_html = markdown.markdown(md, extensions=['extra'], safe_mode=False)
+ self.dek == markdown.markdown(self.dek, safe_mode=False)
try:
self.location = Location.objects.filter(geometry__contains=self.point).get()
except Location.DoesNotExist:
- raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" %(settings.BASE_URL))
+ raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
super(Entry, self).save()
+
class EntryAside(models.Model):
title = models.CharField(max_length=200)
- body = models.TextField(null=True,blank=True)
+ body = models.TextField(null=True, blank=True)
entry = models.ForeignKey(Entry)
-
class BlogSitemap(Sitemap):
changefreq = "never"
priority = 1.0
@@ -148,6 +149,7 @@ class BlogSitemap(Sitemap):
def lastmod(self, obj):
return obj.pub_date
+
class LatestFull(Feed):
title = "Luxagraf: Topographical Writings"
link = "/writing/"