summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/figments/admin.py5
-rw-r--r--app/figments/build.py59
-rw-r--r--app/figments/ebook.py14
-rw-r--r--app/figments/models.py23
-rw-r--r--app/figments/urls.py42
-rw-r--r--app/figments/views.py42
-rw-r--r--app/jrnl/admin.py13
-rw-r--r--app/src/admin.py4
-rw-r--r--app/utils/widgets.py (renamed from app/jrnl/widgets.py)9
9 files changed, 116 insertions, 95 deletions
diff --git a/app/figments/admin.py b/app/figments/admin.py
index 4c8127b..34452bd 100644
--- a/app/figments/admin.py
+++ b/app/figments/admin.py
@@ -1,10 +1,10 @@
from django.contrib import admin
from .models import Figment, Series
-from jrnl.admin import BlogEntryForm
+from utils.widgets import LGEntryForm
class FigmentAdmin(admin.ModelAdmin):
- form = BlogEntryForm
+ form = LGEntryForm
list_display = ('title', 'pub_date', 'get_series')
prepopulated_fields = {"slug": ('title',)}
fieldsets = (
@@ -38,6 +38,7 @@ class FigmentAdmin(admin.ModelAdmin):
),
)
+
class SeriesAdmin(admin.ModelAdmin):
pass
diff --git a/app/figments/build.py b/app/figments/build.py
index 349a399..07720ac 100644
--- a/app/figments/build.py
+++ b/app/figments/build.py
@@ -1,52 +1,17 @@
-from builder.base import *
-from .models import Figment, Series
+from django.core.urlresolvers import reverse
+from builder.base import BuildNew
-class BuildFigments(Build):
+class BuildFigments(BuildNew):
def build(self):
- self.build_archive()
- self.build_topic_archive()
- self.build_detail_pages()
- self.build_detail_epub()
- self.build_feed()
+ self.build_list_view(
+ base_path=reverse('figments:list'),
+ paginate_by=99999
+ )
+ self.build_detail_view()
+ self.build_feed('figments: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')
+def builder():
+ j = BuildFigments("figments", "figment")
+ j.build()
diff --git a/app/figments/ebook.py b/app/figments/ebook.py
index 23e3fc5..81210a4 100644
--- a/app/figments/ebook.py
+++ b/app/figments/ebook.py
@@ -4,6 +4,7 @@ from ebooklib import epub
from django.conf import settings
from typogrify.filters import typogrify
+
def generate_epub_file(f):
book = epub.EpubBook()
@@ -16,17 +17,16 @@ def generate_epub_file(f):
# 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="http://luxagraf.net/figments/">luxagraf.net</a>.</p><p>&ndash; Scott Gilbertson <br/> &nbsp;&nbsp;sng@luxagraf.net</p></body></html>' % f.title
+ 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>&ndash; Scott Gilbertson <br/> &nbsp;&nbsp;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)
+ 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
@@ -48,7 +48,7 @@ body {
h2 {
text-align: left;
text-transform: uppercase;
- font-weight: 200;
+ font-weight: 200;
}
ol {
list-style-type: none;
@@ -71,9 +71,9 @@ nav[epub|type~='toc'] > ol > li > ol > li {
# create spine
book.spine = ['nav', c1, c2]
path, filename = os.path.split(f.get_absolute_url())
- fpath = '%s%s/' %(settings.FLATFILES_ROOT, path)
+ fpath = '%s%s/' % (settings.FLATFILES_ROOT, path)
if not os.path.isdir(fpath):
os.makedirs(fpath)
- bk = '%s%s.epub' %(fpath, f.slug)
+ bk = '%s%s.epub' % (fpath, f.slug)
# create epub file
epub.write_epub(bk, book, {})
diff --git a/app/figments/models.py b/app/figments/models.py
index 858c6ed..e108e21 100644
--- a/app/figments/models.py
+++ b/app/figments/models.py
@@ -1,14 +1,18 @@
import datetime
+from itertools import chain
from django.db import models
+from django.core.urlresolvers 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
-
# http://freewisdom.org/projects/python-markdown/
import markdown
+from .ebook import generate_epub_file
+
+
class Series(models.Model):
title = models.CharField(max_length=200)
slug = models.CharField(max_length=50)
@@ -23,6 +27,7 @@ class Series(models.Model):
def __str__(self):
return self.title
+
class Figment(models.Model):
title = models.CharField(max_length=200)
slug = models.CharField(max_length=50)
@@ -36,7 +41,7 @@ class Figment(models.Model):
(1, 'Published'),
)
status = models.IntegerField(choices=PUB_STATUS, default=0)
- series = models.ManyToManyField(Series, blank=True)
+ series = models.ManyToManyField(Series, related_name="series", blank=True)
TEMPLATES = (
(0, 'default'),
)
@@ -48,10 +53,10 @@ class Figment(models.Model):
def __str__(self):
return self.title
-
+
def get_absolute_url(self):
- return "/figments/%s" % self.slug
-
+ return reverse("figments:detail", kwargs={"slug": self.slug})
+
def get_series(self):
return "\n".join([s.title for s in self.series.all()])
@@ -76,8 +81,6 @@ 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']:
@@ -97,9 +100,6 @@ class LatestFull(Feed):
return Figment.objects.filter(status__exact=1).order_by('-pub_date')[:10]
-
-from itertools import chain
-
class FigmentSitemap(Sitemap):
changefreq = "never"
priority = 0.7
@@ -107,7 +107,6 @@ class FigmentSitemap(Sitemap):
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
index 7dfa328..2114792 100644
--- a/app/figments/urls.py
+++ b/app/figments/urls.py
@@ -1,15 +1,31 @@
-from django.conf.urls import *
-from django.views.generic import ListView, DetailView
+from django.conf.urls import url
-from .models import Figment, Series
+from . import views
-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",
- )),
-)
+urlpatterns = [
+ url(
+ regex=r'^feed.xml',
+ view=views.FigRSSFeedView(),
+ name="feed"
+ ),
+ url(
+ regex=r'series/$',
+ view=views.SeriesListView.as_view(),
+ name='list_series'
+ ),
+ url(
+ regex=r'(?P<slug>[-\w]+).txt$',
+ view=views.FigmentDetailViewTXT.as_view(),
+ name="detail-txt"
+ ),
+ url(
+ regex=r'(?P<slug>[-\w]+)$',
+ view=views.FigmentDetailView.as_view(),
+ name='detail'
+ ),
+ url(
+ regex=r'^$',
+ view=views.FigmentListView.as_view(),
+ name='list'
+ ),
+]
diff --git a/app/figments/views.py b/app/figments/views.py
new file mode 100644
index 0000000..6521c29
--- /dev/null
+++ b/app/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]
diff --git a/app/jrnl/admin.py b/app/jrnl/admin.py
index 15a7512..da4bae3 100644
--- a/app/jrnl/admin.py
+++ b/app/jrnl/admin.py
@@ -2,7 +2,7 @@ from django.contrib import admin
from django import forms
from django.contrib.gis.admin import OSMGeoAdmin
-from .widgets import AdminImageWidget
+from utils.widgets import AdminImageWidget, LGEntryForm
from .models import Entry, EntryAside, PostImage, HomepageCurrator
@@ -15,17 +15,8 @@ class EntryAsideAdmin(admin.ModelAdmin):
pass
-class BlogEntryForm(forms.ModelForm):
- class Meta:
- model = Entry
- fields = '__all__'
- widgets = {
- 'body_markdown': forms.Textarea(attrs={'rows': 50, 'cols': 100}),
- }
-
-
class EntryAdmin(OSMGeoAdmin):
- form = BlogEntryForm
+ form = LGEntryForm
inlines = [EntryAsideInline]
def formfield_for_dbfield(self, db_field, **kwargs):
diff --git a/app/src/admin.py b/app/src/admin.py
index 31c0255..cd6ba1d 100644
--- a/app/src/admin.py
+++ b/app/src/admin.py
@@ -1,6 +1,6 @@
from django.contrib import admin
from .models import Topic, Entry, Book
-from jrnl.admin import BlogEntryForm
+from utils.widgets import LGEntryForm
class TopicAdmin(admin.ModelAdmin):
@@ -32,7 +32,7 @@ class BookAdmin(admin.ModelAdmin):
class EntryAdmin(admin.ModelAdmin):
- form = BlogEntryForm
+ form = LGEntryForm
list_display = ('title', 'pub_date', 'enable_comments', 'status')
list_filter = ('pub_date', 'enable_comments', 'status')
prepopulated_fields = {"slug": ('title',)}
diff --git a/app/jrnl/widgets.py b/app/utils/widgets.py
index 030437b..dc0c4e0 100644
--- a/app/jrnl/widgets.py
+++ b/app/utils/widgets.py
@@ -1,5 +1,5 @@
import os
-
+from django import forms
from django.contrib.admin.widgets import AdminFileWidget
from django.utils.safestring import mark_safe
from django.conf import settings
@@ -30,3 +30,10 @@ class AdminImageWidget(AdminFileWidget):
output.append(super(AdminFileWidget, self).render(name, value, attrs))
return mark_safe(''.join(output))
+
+
+class LGEntryForm(forms.ModelForm):
+ class Meta:
+ widgets = {
+ 'body_markdown': forms.Textarea(attrs={'rows': 50, 'cols': 100}),
+ }