diff options
author | luxagraf <sng@luxagraf.net> | 2015-11-01 21:35:29 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-11-01 21:35:29 -0500 |
commit | 535038e99462cf3738e48871ff69b0192ec62572 (patch) | |
tree | b313f9a7a798cf53f124fcee6a71d476e55ee7ec /app/figments | |
parent | 47ab118686d3216598b57188a67c81f9cf169c50 (diff) |
finished up rough draft of figments section
Diffstat (limited to 'app/figments')
-rw-r--r-- | app/figments/build.py | 12 | ||||
-rw-r--r-- | app/figments/models.py | 26 |
2 files changed, 26 insertions, 12 deletions
diff --git a/app/figments/build.py b/app/figments/build.py index 58835e5..349a399 100644 --- a/app/figments/build.py +++ b/app/figments/build.py @@ -22,18 +22,6 @@ class BuildFigments(Build): s = render_to_string('details/note.txt', c).encode('utf-8') self.write_file(path, s, 'txt', entry.slug) - def build_detail_epub(self): - ''' - Grab all the notes, render them to a template string and write that out to the filesystem - ''' - for entry in Figment.objects.filter(status__exact=1): - c = Context({'object': entry, 'MEDIA_URL': settings.BAKED_MEDIA_URL, 'IMAGES_URL': settings.BAKED_IMAGES_URL, 'SITE_URL':settings.SITE_URL}) - t = render_to_string('details/fignments.html', c).encode('utf-8') - path = 'figments/' - self.write_file(path, t, 'html', entry.slug) - s = render_to_string('details/note.txt', c).encode('utf-8') - self.write_file(path, s, 'txt', entry.slug) - def build_archive(self): path = 'figments/' c = Context({ diff --git a/app/figments/models.py b/app/figments/models.py index 510bd61..858c6ed 100644 --- a/app/figments/models.py +++ b/app/figments/models.py @@ -2,6 +2,8 @@ import datetime from django.db import models from django.contrib.sitemaps import Sitemap from django.contrib.syndication.views import Feed +from django.db.models.signals import post_save +from django.dispatch import receiver # http://freewisdom.org/projects/python-markdown/ @@ -53,6 +55,20 @@ class Figment(models.Model): def get_series(self): return "\n".join([s.title for s in self.series.all()]) + @classmethod + def from_db(cls, db, field_names, values): + # default implementation of from_db() (could be replaced + # with super()) + if cls._deferred: + instance = cls(**zip(field_names, values)) + else: + instance = cls(*values) + instance._state.adding = False + instance._state.db = db + # customization to store the original field values on the instance + instance._loaded_values = dict(zip(field_names, values)) + return instance + def save(self, *args, **kwargs): if not self.id and not self.pub_date: self.pub_date = datetime.datetime.now() @@ -60,6 +76,16 @@ class Figment(models.Model): super(Figment, self).save() +from .ebook import generate_epub_file + +@receiver(post_save, sender=Figment) +def post_save_events(sender, instance, **kwargs): + if instance.body_markdown != instance._loaded_values['body_markdown']: + print("you updated") + generate_epub_file(instance) + else: + print("no update found, not buidling") + class LatestFull(Feed): title = "luxagraf figments: stories less literally true." |