summaryrefslogtreecommitdiff
path: root/app/figments
diff options
context:
space:
mode:
Diffstat (limited to 'app/figments')
-rw-r--r--app/figments/TODO1
-rw-r--r--app/figments/admin.py45
-rw-r--r--app/figments/build.py51
-rw-r--r--app/figments/models.py87
-rw-r--r--app/figments/urls.py15
5 files changed, 199 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",
+ )),
+)