diff options
author | luxagraf <sng@luxagraf.net> | 2015-10-31 21:39:17 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-10-31 21:39:17 -0400 |
commit | e8d1fa3f47f8520618bd83dd917c569c83f2de86 (patch) | |
tree | 4ceeb0e0fb540e4161315b8cc114be5897f3f643 | |
parent | c6a87562e6bd9b745dceb09b8c0b076137f46ba6 (diff) |
added figments app for publishing fiction
-rw-r--r-- | app/figments/TODO | 1 | ||||
-rw-r--r-- | app/figments/admin.py | 45 | ||||
-rw-r--r-- | app/figments/build.py | 51 | ||||
-rw-r--r-- | app/figments/models.py | 87 | ||||
-rw-r--r-- | app/figments/urls.py | 15 | ||||
-rw-r--r-- | config/base_urls.py | 1 | ||||
-rw-r--r-- | design/sass/_figments.scss | 4 | ||||
-rw-r--r-- | design/templates/archives/figments.html | 18 | ||||
-rw-r--r-- | design/templates/details/figments.html | 30 |
9 files changed, 252 insertions, 0 deletions
diff --git a/app/figments/TODO b/app/figments/TODO new file mode 100644 index 0000000..510ee94 --- /dev/null +++ b/app/figments/TODO @@ -0,0 +1 @@ +iron out templates and push first piece live. diff --git a/app/figments/admin.py b/app/figments/admin.py new file mode 100644 index 0000000..f5e47a6 --- /dev/null +++ b/app/figments/admin.py @@ -0,0 +1,45 @@ +from django.contrib import admin +from .models import Figment, Series +from blog.admin import BlogEntryForm + + +class FigmentAdmin(admin.ModelAdmin): + form = BlogEntryForm + 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/app/figments/build.py b/app/figments/build.py new file mode 100644 index 0000000..b0890fd --- /dev/null +++ b/app/figments/build.py @@ -0,0 +1,51 @@ +from builder.base import * +from .models import Figment, Series + + +class BuildSrc(Build): + def build(self): + self.build_archive() + self.build_topic_archive() + self.build_detail_pages() + self.build_feed() + + def build_detail_pages(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({ + 'object_list': Figment.objects.filter(status__exact=1), + 'MEDIA_URL': settings.BAKED_MEDIA_URL, + 'IMAGES_URL': settings.BAKED_IMAGES_URL + }) + t = render_to_string('archives/figments.html', c).encode('utf-8') + self.write_file(path, t) + + def build_topic_archive(self): + for series in Series.objects.all(): + path = 'figments/series/' + c = Context({ + 'object_list': Figment.objects.filter(series__slug=series.slug), + 'series': series, + 'MEDIA_URL': settings.BAKED_MEDIA_URL, + 'IMAGES_URL': settings.BAKED_IMAGES_URL + }) + t = render_to_string('archives/figments.html', c).encode('utf-8') + self.write_file(path, t, 'html', topic.slug) + + def build_feed(self): + qs = Figments.objects.filter(status__exact=1) + c = Context({'object_list': qs, 'SITE_URL': settings.SITE_URL}) + t = render_to_string('feed.xml', c).encode('utf-8') + fpath = '%s' % ('/figments/rss/',) + self.write_file(fpath, t, 'xml') 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 + diff --git a/app/figments/urls.py b/app/figments/urls.py new file mode 100644 index 0000000..7dfa328 --- /dev/null +++ b/app/figments/urls.py @@ -0,0 +1,15 @@ +from django.conf.urls import * +from django.views.generic import ListView, DetailView + +from .models import Figment, Series + +urlpatterns = patterns('', + url(r'^(?P<slug>[-\w]+)/$', DetailView.as_view( + model=Figment, + template_name="details/figments.html" + )), + url(r'^$', ListView.as_view( + queryset=Figment.objects.filter(status__exact=1).order_by('-pub_date'), + template_name="archives/figments.html", + )), +) diff --git a/config/base_urls.py b/config/base_urls.py index 83880fc..c59e522 100644 --- a/config/base_urls.py +++ b/config/base_urls.py @@ -8,6 +8,7 @@ from locations.models import WritingbyCountrySitemap from links.models import LatestLinks from photos.models import PhotoGallerySitemap from src.models import SrcSitemap +from figments.models import FigmentSitemap from projects.models.base import ProjectSitemap admin.autodiscover() diff --git a/design/sass/_figments.scss b/design/sass/_figments.scss new file mode 100644 index 0000000..cc4d7f5 --- /dev/null +++ b/design/sass/_figments.scss @@ -0,0 +1,4 @@ +.kindle { + @include smcaps; + @include fontsize(11); +} diff --git a/design/templates/archives/figments.html b/design/templates/archives/figments.html new file mode 100644 index 0000000..5c5e398 --- /dev/null +++ b/design/templates/archives/figments.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} + +{% block primary %} + <main role="main"> + {% for object in object_list %} + <article class="h-entry hentry post--article{% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/Article"> + <header id="header" class="post--header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}"> + <h1 class="p-name entry-title post--title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|widont|safe}}{%endif%}</h1> + <p class="p-author author hide" itemprop="author"><span class="byline-author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Scott Gilbertson</span></span></p> + </header> + <div id="article" class="e-content entry-content post--body post--body--{% with object.template_name as t %}{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%endif%}{%endwith%}" itemprop="articleBody"> + {{object.title|safe|smartypants|widont}} + </div> + </article> + {%endfor%} + </main> +{% endblock %} diff --git a/design/templates/details/figments.html b/design/templates/details/figments.html new file mode 100644 index 0000000..3aeb690 --- /dev/null +++ b/design/templates/details/figments.html @@ -0,0 +1,30 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} + +{% block primary %} + <main role="main"> + <article class="h-entry hentry post--article{% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/Article"> + <header id="header" class="post--header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}"> + <h1 class="p-name entry-title post--title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|widont|safe}}{%endif%}</h1> + <time class="hide dt-published published dt-updated post--date" datetime="{{object.pub_date|date:'c'}}" itemprop="datePublished">{{object.pub_date|date:"F"}} <span>{{object.pub_date|date:"j, Y"}}</span></time> + <p class="kindle"><a href="">Send to Kindle</a></p> + <p class="p-author author hide" itemprop="author"><span class="byline-author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Scott Gilbertson</span></span></p> + </header> + <div id="article" class="e-content entry-content post--body post--body--{% with object.template_name as t %}{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%endif%}{%endwith%}" itemprop="articleBody"> + {{object.body_html|safe|smartypants|widont}} + </div> + </article> + {% with object.get_next_published as next %} + {% with object.get_previous_published as prev %} + <nav id="page-navigation"> + <ul>{% if prev%} + <li id="prev"><span class="bl">Previous:</span> + <a href="{{ prev.get_absolute_url }}" rel="prev" title=" {{prev.title}}">{{prev.title|safe}}</a> + </li>{%endif%}{% if next%} + <li id="next"><span class="bl">Next:</span> + <a href="{{ next.get_absolute_url }}" rel="next" title=" {{next.title}}">{{next.title|safe}}</a> + </li>{%endif%} + </ul> + </nav>{%endwith%}{%endwith%} + </main> +{%endblock%} |