diff options
Diffstat (limited to 'app/notes/build.py')
-rw-r--r-- | app/notes/build.py | 94 |
1 files changed, 31 insertions, 63 deletions
diff --git a/app/notes/build.py b/app/notes/build.py index 96c4812..499adc6 100644 --- a/app/notes/build.py +++ b/app/notes/build.py @@ -1,68 +1,36 @@ -from builder.base import * -from django.apps import apps +import os +from django.core.urlresolvers import reverse +from builder.base import BuildNew -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().order_by('-date_created') +class BuildNotes(BuildNew): - def get_model(self): - return apps.get_model('notes', 'note') - - def build_detail_pages(self): + def build(self): + self.build_detail_view() + self.build_list_view( + base_path=reverse("notes:live_redirect"), + paginate_by=24 + ) + self.build_year_view("notes:list_year") + self.build_month_view("notes:list_month") + + def get_model_queryset(self): + return self.model.objects.all() + + def build_detail_view(self): ''' - Grab all the notes, render them to a template string and write that out to the filesystem + write out all the expenses for each trip ''' - for entry in self.queryset(): - 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/note.html', c).encode('utf-8') - path = 'field-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 = 'field-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 = 'field-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 = 'field-notes/%s/%s/' % (year, month) - self.write_file(fpath, t) + for obj in self.get_model_queryset(): + url = obj.get_absolute_url() + path, slug = os.path.split(url) + path = '%s/' % path + # write html + response = self.client.get(url) + print(path, slug) + self.write_file(path, response.content, filename=slug) + + +def builder(): + j = BuildNotes("notes", "luxnote") + j.build() |