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 utils import markdown2 as markdown from taggit.managers import TaggableManager from locations.models import Location,Region,Country from blog.models import Entry from photos.models import PhotoGallery def image_url_replace(str): str = str.replace('[[base_url]]', settings.IMAGES_URL) return str def markdown_processor(md): return markdown.markdown(md, ['footnotes'],safe_mode = False) PUB_STATUS = ( (0, 'Draft'), (1, 'Published'), ) TEMPLATES = ( (0, 'single'), (1, 'double'), (2, 'single-dark'), (3, 'double-dark'), ) class Guide(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') entry = models.ForeignKey(Entry, null=True, 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') location = models.ForeignKey(Location, null=True, blank=True) country = models.ForeignKey(Country, null=True, blank=True) region = models.ForeignKey(Region, 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') meta_description = models.CharField(max_length=256, null=True, blank=True) template_name = models.IntegerField(choices=TEMPLATES, default=0) tags = TaggableManager(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): if self.location: return "/guide/location/%s/%s/" % (self.location.slug, self.slug) else: return "/guide/%s/" % (self.slug) def save(self): md = image_url_replace(self.body_markdown) #run markdown self.body_html = markdown_processor(md) self.dek == markdown.markdown(self.dek, safe_mode = False) super(Guide, self).save() class GuideSitemap(Sitemap): changefreq = "never" priority = 1.0 def items(self): return Entry.objects.filter(status=1) def lastmod(self, obj): return obj.pub_date class GuideFull(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)