diff options
author | luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f> | 2009-01-05 04:07:10 +0000 |
---|---|---|
committer | luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f> | 2009-01-05 04:07:10 +0000 |
commit | 637d71d2c3a7c1c65a931e1eb094052a095cdf05 (patch) | |
tree | ca34a2fead939b133143ec7647a9437d52c89075 /apps/blog/models.py |
have at it
Diffstat (limited to 'apps/blog/models.py')
-rw-r--r-- | apps/blog/models.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/apps/blog/models.py b/apps/blog/models.py new file mode 100644 index 0000000..d9cea69 --- /dev/null +++ b/apps/blog/models.py @@ -0,0 +1,101 @@ +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 + + +import markdown2 as markdown +from tagging.fields import TagField +from tagging.models import Tag + +from photos.models import PhotoGallery +from locations.models import Location,Region +#from locations.signals import create_location_item + +def get_upload_path(self, filename): + return "%s/post-thumbs/%s/%s" %(settings.IMAGES_ROOT, datetime.datetime.today().strftime("%Y"), filename) + +def markdown_processor(md): + processed = markdown.markdown(md, safe_mode = False).split('<break>') + html = processed[0]+processed[1] + lede = processed[0] + return html, lede + +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 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') + tags = TagField() + enable_comments = models.BooleanField(default=True) + 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) + + 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) + + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + def get_next_published(self): + return self.get_next_by_pub_date(status__exact=1) + + def get_tags(self): + return Tag.objects.get_for_object(self) + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + + def get_thumbnail_url(self): + return '%s%s' %(settings.IMAGES_URL, self.thumbnail.url[33:]) + + def save(self): + html,lede = markdown_processor(self.body_markdown) + self.body_html = html + self.lede = lede + self.dek == markdown.markdown(self.dek, safe_mode = False) + 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 + +#signals.post_save.connect(create_location_item, sender=Entry)
\ No newline at end of file |