diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/builder/views.py | 4 | ||||
-rw-r--r-- | app/notes/admin.py | 2 | ||||
-rw-r--r-- | app/notes/build.py | 94 | ||||
-rw-r--r-- | app/notes/migrations/0006_auto_20160617_2058.py | 24 | ||||
-rw-r--r-- | app/notes/models.py | 7 |
5 files changed, 65 insertions, 66 deletions
diff --git a/app/builder/views.py b/app/builder/views.py index dfce406..1b537bd 100644 --- a/app/builder/views.py +++ b/app/builder/views.py @@ -8,6 +8,7 @@ from books.build import builder as book_builder from birds.build import builder as bird_builder from photos.build import builder as photo_builder from figments.build import builder as figments_builder +from notes.build import builder as notes_builder options = { 'writing': BuildWriting, @@ -53,6 +54,9 @@ def do_build(request): elif section == 'figments': context = {'message': 'Writing figments to Disk'} figments_builder() + elif section == 'notes': + context = {'message': 'Writing notes to Disk'} + notes_builder() elif section == 'buildamp': context = {'message': 'Writing detail amp pages to Disk'} amp_builder() diff --git a/app/notes/admin.py b/app/notes/admin.py index e84b7a0..e439168 100644 --- a/app/notes/admin.py +++ b/app/notes/admin.py @@ -13,7 +13,7 @@ class LuxNoteAdmin(OLAdminBase): 'fields': ( ('title', 'slug'), 'body_markdown', - 'pub_date', + ('pub_date', 'status'), 'point' ), 'classes': ( 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() diff --git a/app/notes/migrations/0006_auto_20160617_2058.py b/app/notes/migrations/0006_auto_20160617_2058.py new file mode 100644 index 0000000..8d32528 --- /dev/null +++ b/app/notes/migrations/0006_auto_20160617_2058.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-06-17 20:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('notes', '0005_auto_20160616_1445'), + ] + + operations = [ + migrations.RemoveField( + model_name='luxnote', + name='images', + ), + migrations.AddField( + model_name='luxnote', + name='status', + field=models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0), + ), + ] diff --git a/app/notes/models.py b/app/notes/models.py index 1acf966..d59b4de 100644 --- a/app/notes/models.py +++ b/app/notes/models.py @@ -17,7 +17,6 @@ import markdown from utils.widgets import markdown_to_html from daily.models import CheckIn -from photos.models import LuxImage from jrnl.models import render_images @@ -34,7 +33,11 @@ class LuxNote(models.Model): body_markdown = models.TextField('Note') point = models.PointField(blank=True, null=True) location = models.ForeignKey(Location, blank=True, null=True) - images = models.ManyToManyField(LuxImage, blank=True, null=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=1) def __str__(self): return self.title |