diff options
Diffstat (limited to 'app/unused_apps/figments/models.py')
-rw-r--r-- | app/unused_apps/figments/models.py | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/app/unused_apps/figments/models.py b/app/unused_apps/figments/models.py deleted file mode 100644 index 8b22049..0000000 --- a/app/unused_apps/figments/models.py +++ /dev/null @@ -1,97 +0,0 @@ -import datetime -from itertools import chain -from django.db import models -from django.urls import reverse -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 - -from utils.util import markdown_to_html - -from .ebook import generate_epub_file - - -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, related_name="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 reverse("figments:detail", kwargs={"slug": 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_to_html(self.body_markdown) - super(Figment, self).save() - - -@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." - 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] - - -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 |