summaryrefslogtreecommitdiff
path: root/app/notes/build.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/notes/build.py')
-rw-r--r--app/notes/build.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/app/notes/build.py b/app/notes/build.py
new file mode 100644
index 0000000..44226f9
--- /dev/null
+++ b/app/notes/build.py
@@ -0,0 +1,68 @@
+from builder.base import *
+from .models import Note
+
+
+class BuildNotes(Build):
+ def build(self):
+ self.build_archive()
+ self.build_archive_year()
+ self.build_archive_month()
+ self.build_detail_pages()
+
+ def queryset(self):
+ return Note.objects.all()
+
+ def get_model(self):
+ return get_model('notes', 'note')
+
+ 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 self.queryset():
+ c = Context({'object': entry, 'MEDIA_URL': settings.BAKED_MEDIA_URL, 'IMAGES_URL': settings.BAKED_IMAGES_URL})
+ t = render_to_string('details/note.html', c).encode('utf-8')
+ path = 'notes/%s/' % (entry.date_created.strftime("%Y/%m").lower())
+ 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 = 'notes/'
+ c = Context({
+ 'object_list': self.queryset(),
+ 'MEDIA_URL': settings.BAKED_MEDIA_URL,
+ 'IMAGES_URL': settings.BAKED_IMAGES_URL
+ })
+ t = render_to_string('archives/notes.html', c).encode('utf-8')
+ self.write_file(path, t)
+
+ def build_archive_year(self):
+ note = self.get_model()
+ years = note.objects.dates('date_created', 'year')
+ for year in years:
+ year = year.strftime('%Y')
+ qs = note.objects.filter(date_created__year=year).order_by('-date_created')
+ c = Context({
+ 'year': year,
+ 'object_list': qs
+ })
+ t = render_to_string('archives/notes_date.html', c).encode('utf-8')
+ fpath = 'notes/%s/' % (year)
+ self.write_file(fpath, t)
+
+ def build_archive_month(self):
+ note = self.get_model()
+ months = note.objects.dates('date_created', 'month')
+ for m in months:
+ year = m.strftime('%Y')
+ month = m.strftime('%m')
+ qs = note.objects.filter(date_created__year=year, date_created__month=month).order_by('-date_created')
+ c = Context({
+ 'month': month,
+ 'year': year,
+ 'object_list': qs,
+ })
+ t = render_to_string('archives/notes_date.html', c).encode('utf-8')
+ fpath = 'notes/%s/%s/' % (year, month)
+ self.write_file(fpath, t)