diff options
Diffstat (limited to 'app/figments/models.py')
-rw-r--r-- | app/figments/models.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/app/figments/models.py b/app/figments/models.py new file mode 100644 index 0000000..510bd61 --- /dev/null +++ b/app/figments/models.py @@ -0,0 +1,87 @@ +import datetime +from django.db import models +from django.contrib.sitemaps import Sitemap +from django.contrib.syndication.views import Feed + + +# http://freewisdom.org/projects/python-markdown/ +import markdown + +class Series(models.Model): + title = models.CharField(max_length=200) + slug = models.CharField(max_length=50) + is_book = models.BooleanField(default=False) + body_markdown = models.TextField(null=True, blank=True) + body_html = models.TextField(null=True, blank=True) + pub_date = models.DateTimeField(auto_now_add=True) + + class Meta: + verbose_name_plural = 'Series' + + def __str__(self): + return self.title + +class Figment(models.Model): + title = models.CharField(max_length=200) + slug = models.CharField(max_length=50) + pub_date = models.DateTimeField(blank=True) + body_markdown = models.TextField(null=True, blank=True) + prologue = models.TextField(null=True, blank=True) + dek = models.TextField(null=True, blank=True) + body_html = models.TextField(null=True, blank=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + series = models.ManyToManyField(Series, blank=True) + TEMPLATES = ( + (0, 'default'), + ) + template_name = models.IntegerField(choices=TEMPLATES, default=0) + published_link = models.CharField(max_length=300, help_text="link to online pub", blank=True, null=True) + + class Meta: + ordering = ('-pub_date',) + + def __str__(self): + return self.title + + def get_absolute_url(self): + return "/figments/%s" % self.slug + + def get_series(self): + return "\n".join([s.title for s in self.series.all()]) + + def save(self, *args, **kwargs): + if not self.id and not self.pub_date: + self.pub_date = datetime.datetime.now() + self.body_html = markdown.markdown(self.body_markdown, extensions=['extra'], safe_mode=False) + super(Figment, self).save() + + + +class LatestFull(Feed): + title = "luxagraf figments: stories less literally true." + link = "/figments/" + description = "Latest postings to luxagraf.net/figments" + description_template = 'feeds/blog_description.html' + + def items(self): + return Figment.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + + +from itertools import chain + +class FigmentSitemap(Sitemap): + changefreq = "never" + priority = 0.7 + protocol = "https" + + def items(self): + return list(chain(Figment.objects.filter(status__exact=1), Series.objects.all())) + + def lastmod(self, obj): + return obj.pub_date + |