diff options
author | luxagraf <sng@luxagraf.net> | 2023-07-28 13:39:02 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-07-28 13:39:02 -0500 |
commit | 9a620cf42bf1fe6977e378bd834b41ff4a593dde (patch) | |
tree | cf41a0582681cecaf88a30bfe409f9c2be57972a /bak/unused_apps/figments | |
parent | 6e5897117124cd60ae81efb1574c6347f48e60e5 (diff) |
main: removed some apps I wasn't using and added bak to git to preserve
a copy of old apps
Diffstat (limited to 'bak/unused_apps/figments')
-rw-r--r-- | bak/unused_apps/figments/admin.py | 46 | ||||
-rw-r--r-- | bak/unused_apps/figments/build.py | 17 | ||||
-rw-r--r-- | bak/unused_apps/figments/ebook.py | 79 | ||||
-rw-r--r-- | bak/unused_apps/figments/models.py | 97 | ||||
-rw-r--r-- | bak/unused_apps/figments/urls.py | 38 | ||||
-rw-r--r-- | bak/unused_apps/figments/views.py | 42 |
6 files changed, 319 insertions, 0 deletions
diff --git a/bak/unused_apps/figments/admin.py b/bak/unused_apps/figments/admin.py new file mode 100644 index 0000000..34452bd --- /dev/null +++ b/bak/unused_apps/figments/admin.py @@ -0,0 +1,46 @@ +from django.contrib import admin +from .models import Figment, Series +from utils.widgets import LGEntryForm + + +class FigmentAdmin(admin.ModelAdmin): + form = LGEntryForm + list_display = ('title', 'pub_date', 'get_series') + prepopulated_fields = {"slug": ('title',)} + fieldsets = ( + ('Figment', { + 'fields': ( + 'title', + 'body_markdown', + ('slug', 'status'), + 'pub_date', + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ('Extra', { + 'fields': ( + 'dek', + 'prologue', + 'series', + 'published_link', + ), + 'classes': ( + 'collapse', + 'extrapretty', + 'wide' + ) + } + ), + ) + + +class SeriesAdmin(admin.ModelAdmin): + pass + +admin.site.register(Figment, FigmentAdmin) +admin.site.register(Series, SeriesAdmin) diff --git a/bak/unused_apps/figments/build.py b/bak/unused_apps/figments/build.py new file mode 100644 index 0000000..b656ab0 --- /dev/null +++ b/bak/unused_apps/figments/build.py @@ -0,0 +1,17 @@ +from django.urls import reverse +from builder.base import BuildNew + + +class BuildFigments(BuildNew): + def build(self): + self.build_list_view( + base_path=reverse('figments:list'), + paginate_by=99999 + ) + self.build_detail_view() + self.build_feed('figments:feed') + + +def builder(): + j = BuildFigments("figments", "figment") + j.build() diff --git a/bak/unused_apps/figments/ebook.py b/bak/unused_apps/figments/ebook.py new file mode 100644 index 0000000..81210a4 --- /dev/null +++ b/bak/unused_apps/figments/ebook.py @@ -0,0 +1,79 @@ +import os +from ebooklib import epub + +from django.conf import settings +from typogrify.filters import typogrify + + +def generate_epub_file(f): + book = epub.EpubBook() + + # add metadata + book.set_identifier('lux23') + book.set_title(f.title) + book.set_language('en') + + book.add_author('Scott Gilbertson') + + # intro chapter + c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en') + c1.content = u'<html><head></head><body><h1>Forward</h1><p>Thank you for downloading my story <em>%s</em>. I hope you enjoy it and please feel free to email me if you have any questions or comments.</p> <p>If you enjoy this story and would like to read more, head on over to <a href="https://luxagraf.net/figments/">luxagraf.net</a>.</p><p>– Scott Gilbertson <br/> sng@luxagraf.net</p></body></html>' % f.title + + # chapter + c2 = epub.EpubHtml(title=f.title, file_name='story.xhtml') + c2.content = '<h1>%s</h1>' % f.title + c2.content += typogrify(f.body_html) + + # add chapters to the book + book.add_item(c1) + book.add_item(c2) + # create table of contents + # - add section + # - add auto created links to chapters + + book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'), + epub.Link('story.xhtml', f.title, 'story'), + ) + + # add navigation files + book.add_item(epub.EpubNcx()) + book.add_item(epub.EpubNav()) + + # define css style + style = ''' +@namespace epub "http://www.idpf.org/2007/ops"; +body { + font-family: Georgia, Times, Times New Roman, serif; +} +h2 { + text-align: left; + text-transform: uppercase; + font-weight: 200; +} +ol { + list-style-type: none; +} +ol > li:first-child { + margin-top: 0.3em; +} +nav[epub|type~='toc'] > ol > li > ol { + list-style-type:square; +} +nav[epub|type~='toc'] > ol > li > ol > li { + margin-top: 0.3em; +} +''' + + # add css file + nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) + book.add_item(nav_css) + + # create spine + book.spine = ['nav', c1, c2] + path, filename = os.path.split(f.get_absolute_url()) + fpath = '%s%s/' % (settings.FLATFILES_ROOT, path) + if not os.path.isdir(fpath): + os.makedirs(fpath) + bk = '%s%s.epub' % (fpath, f.slug) + # create epub file + epub.write_epub(bk, book, {}) diff --git a/bak/unused_apps/figments/models.py b/bak/unused_apps/figments/models.py new file mode 100644 index 0000000..8b22049 --- /dev/null +++ b/bak/unused_apps/figments/models.py @@ -0,0 +1,97 @@ +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 diff --git a/bak/unused_apps/figments/urls.py b/bak/unused_apps/figments/urls.py new file mode 100644 index 0000000..4a37cf5 --- /dev/null +++ b/bak/unused_apps/figments/urls.py @@ -0,0 +1,38 @@ +from django.conf.urls import url + +from . import views + +app_name = "figments" + +urlpatterns = [ + url( + r'^feed.xml', + views.FigRSSFeedView(), + name="feed" + ), + url( + r'series/$', + views.SeriesListView.as_view(), + name='list_series' + ), + url( + r'(?P<slug>[-\w]+).txt$', + views.FigmentDetailViewTXT.as_view(), + name="detail-txt" + ), + url( + r'(?P<slug>[-\w]+).amp$', + views.FigmentDetailViewAMP.as_view(), + name="detail-amp" + ), + url( + r'(?P<slug>[-\w]+)$', + views.FigmentDetailView.as_view(), + name='detail' + ), + url( + r'^$', + views.FigmentListView.as_view(), + name='list' + ), +] diff --git a/bak/unused_apps/figments/views.py b/bak/unused_apps/figments/views.py new file mode 100644 index 0000000..6521c29 --- /dev/null +++ b/bak/unused_apps/figments/views.py @@ -0,0 +1,42 @@ +from django.views.generic import ListView, DetailView +from django.contrib.syndication.views import Feed + +from .models import Figment, Series + + +class FigmentListView(ListView): + model = Figment + template_name = "archives/figments.html" + context_object_name = 'object_list' + + def get_queryset(self): + return Figment.objects.filter(status__exact=1).order_by('-pub_date') + + +class SeriesListView(ListView): + model = Series + template_name = "archives/figments_series.html" + context_object_name = 'object_list' + + +class FigmentDetailView(DetailView): + model = Figment + template_name = "details/figments.html" + + +class FigmentDetailViewTXT(FigmentDetailView): + template_name = "details/entry.txt" + + +class FigmentDetailViewAMP(FigmentDetailView): + template_name = "details/entry.amp" + + +class FigRSSFeedView(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] |