from builder.base import * 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 self.get_model().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)