From cfeeda7adec97d618ad1fc01926b1fa88298fc85 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sun, 3 Mar 2019 14:36:45 -0600 Subject: Change sketches to fieldnotes and redid design to allow posting single photos --- app/fieldnotes/__init__.py | 0 app/fieldnotes/admin.py | 38 +++++++ app/fieldnotes/build.py | 36 +++++++ app/fieldnotes/migrations/0001_initial.py | 37 +++++++ .../migrations/0002_auto_20190303_1222.py | 25 +++++ app/fieldnotes/migrations/__init__.py | 0 app/fieldnotes/models.py | 111 +++++++++++++++++++++ app/fieldnotes/urls.py | 39 ++++++++ app/fieldnotes/views.py | 36 +++++++ app/jrnl/migrations/0033_entry_field_notes_two.py | 19 ++++ app/jrnl/models.py | 2 + app/photos/models.py | 3 + config/base_urls.py | 2 +- design/sass/_archives.scss | 29 +++++- design/sass/_details.scss | 10 ++ design/sass/_src.scss | 7 -- .../fieldnotes/fieldnote_archive_list_date.html | 44 ++++++++ design/templates/fieldnotes/fieldnote_detail.html | 81 +++++++++++++++ design/templates/fieldnotes/fieldnote_list.html | 46 +++++++++ 19 files changed, 556 insertions(+), 9 deletions(-) create mode 100644 app/fieldnotes/__init__.py create mode 100644 app/fieldnotes/admin.py create mode 100644 app/fieldnotes/build.py create mode 100644 app/fieldnotes/migrations/0001_initial.py create mode 100644 app/fieldnotes/migrations/0002_auto_20190303_1222.py create mode 100644 app/fieldnotes/migrations/__init__.py create mode 100644 app/fieldnotes/models.py create mode 100644 app/fieldnotes/urls.py create mode 100644 app/fieldnotes/views.py create mode 100644 app/jrnl/migrations/0033_entry_field_notes_two.py create mode 100644 design/templates/fieldnotes/fieldnote_archive_list_date.html create mode 100644 design/templates/fieldnotes/fieldnote_detail.html create mode 100644 design/templates/fieldnotes/fieldnote_list.html diff --git a/app/fieldnotes/__init__.py b/app/fieldnotes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/fieldnotes/admin.py b/app/fieldnotes/admin.py new file mode 100644 index 0000000..838063d --- /dev/null +++ b/app/fieldnotes/admin.py @@ -0,0 +1,38 @@ +from django.contrib import admin +from django.contrib.contenttypes.admin import GenericTabularInline + +from .models import FieldNote +from utils.widgets import LGEntryForm, OLAdminBase +from utils.util import get_latlon + + +@admin.register(FieldNote) +class NoteAdmin(OLAdminBase): + form = LGEntryForm + prepopulated_fields = {"slug": ('title',)} + list_display = ('title', 'slug', 'pub_date', 'location') + fieldsets = ( + ('Note', { + 'fields': ( + ('title', 'note_type'), + 'subtitle', + 'body_markdown', + 'slug', + ('pub_date', 'status'), + 'point' + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) + lat, lon = get_latlon() + default_lon = lon + default_lat = lat + default_zoom = 10 + + class Media: + js = ('image-loader.js', 'next-prev-links.js') diff --git a/app/fieldnotes/build.py b/app/fieldnotes/build.py new file mode 100644 index 0000000..4c5c83b --- /dev/null +++ b/app/fieldnotes/build.py @@ -0,0 +1,36 @@ +import os +from django.urls import reverse +from builder.base import BuildNew + + +class BuildNotes(BuildNew): + + def build(self): + self.build_detail_view() + self.build_list_view( + base_path=reverse("fieldnotes:list"), + paginate_by=24 + ) + self.build_year_view("fieldnotes:list_year") + self.build_month_view("fieldnotes:list_month") + + def get_model_queryset(self): + return self.model.objects.all() + + def build_detail_view(self): + ''' + write out all the expenses for each trip + ''' + 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("fieldnotes", "fieldnote") + j.build() diff --git a/app/fieldnotes/migrations/0001_initial.py b/app/fieldnotes/migrations/0001_initial.py new file mode 100644 index 0000000..cec67fb --- /dev/null +++ b/app/fieldnotes/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# Generated by Django 2.1.7 on 2019-03-03 12:13 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('locations', '0017_auto_20190217_1849'), + ] + + operations = [ + migrations.CreateModel( + name='FieldNote', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(blank=True, max_length=250)), + ('subtitle', models.CharField(blank=True, max_length=250)), + ('slug', models.SlugField(blank=True, unique_for_date='pub_date')), + ('pub_date', models.DateTimeField(default=django.utils.timezone.now)), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField(verbose_name='Note')), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=1)), + ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ], + options={ + 'get_latest_by': 'pub_date', + 'ordering': ('-pub_date',), + }, + ), + ] diff --git a/app/fieldnotes/migrations/0002_auto_20190303_1222.py b/app/fieldnotes/migrations/0002_auto_20190303_1222.py new file mode 100644 index 0000000..c0e352e --- /dev/null +++ b/app/fieldnotes/migrations/0002_auto_20190303_1222.py @@ -0,0 +1,25 @@ +# Generated by Django 2.1.7 on 2019-03-03 12:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('photos', '0018_auto_20161130_1218'), + ('fieldnotes', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='fieldnote', + name='featured_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='photos.LuxImage'), + ), + migrations.AddField( + model_name='fieldnote', + name='note_type', + field=models.IntegerField(choices=[(0, 'Note'), (1, 'Photo')], default=0), + ), + ] diff --git a/app/fieldnotes/migrations/__init__.py b/app/fieldnotes/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/fieldnotes/models.py b/app/fieldnotes/models.py new file mode 100644 index 0000000..e3cb527 --- /dev/null +++ b/app/fieldnotes/models.py @@ -0,0 +1,111 @@ +import re +from django import forms +from django.contrib.gis.db import models +from django.utils import timezone +from django.urls import reverse +from django.conf import settings +from django.contrib.sitemaps import Sitemap + +from locations.models import Location, CheckIn +from photos.models import LuxImage +from utils.util import render_images, parse_image, markdown_to_html, extract_main_image + + +def render_images(s): + s = re.sub('', parse_image, s) + return s + + +class FieldNote(models.Model): + title = models.CharField(max_length=250, blank=True) + subtitle = models.CharField(max_length=250, blank=True) + slug = models.SlugField(unique_for_date='pub_date', blank=True) + pub_date = models.DateTimeField(default=timezone.now) + body_html = models.TextField(blank=True) + body_markdown = models.TextField('Note') + point = models.PointField(blank=True, null=True) + location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True, null=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=1) + NOTE_TYPE = ( + (0, 'Note'), + (1, 'Photo'), + ) + note_type = models.IntegerField(choices=NOTE_TYPE, default=0) + featured_image = models.ForeignKey(LuxImage, on_delete=models.SET_NULL, blank=True, null=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse("fieldnotes:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) + + @property + def region(self): + return self.location.lux_region + + @property + def longitude(self): + '''Get the site's longitude.''' + return round(self.point.x, 2) + + @property + def latitude(self): + '''Get the site's latitude.''' + return round(self.point.y, 2) + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date() + + @property + def get_next_published(self): + return self.get_next_by_pub_date() + + @property + def get_previous_admin_url(self): + n = self.get_previous_by_pub_date() + return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] ) + + @property + def get_next_admin_url(self): + model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name) + try: + return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] ) + except model.DoesNotExist: + return '' + + def save(self, *args, **kwargs): + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) + if not self.point: + self.point = CheckIn.objects.latest().point + try: + self.location = Location.objects.filter(geometry__contains=self.point).get() + except Location.DoesNotExist: + raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) + if not self.id: + self.pub_date = timezone.now() + self.date_last_updated = timezone.now() + if self.note_type == 1: + self.featured_image = extract_main_image(self.body_markdown) + super(FieldNote, self).save() + + +class FieldNoteSitemap(Sitemap): + changefreq = "never" + priority = 0.7 + protocol = "https" + + def items(self): + return FieldNote.objects.filter(status=1) + + def lastmod(self, obj): + return obj.pub_date diff --git a/app/fieldnotes/urls.py b/app/fieldnotes/urls.py new file mode 100644 index 0000000..f3ef944 --- /dev/null +++ b/app/fieldnotes/urls.py @@ -0,0 +1,39 @@ +from django.urls import path, re_path + +from . import views + +app_name = "fieldnotes" + +urlpatterns = [ + re_path( + r'(?P[0-9]{4})/$', + views.FieldNoteYearArchiveView.as_view(), + name="list_year" + ), + path( + r'', + views.FieldNoteListView.as_view(), + {'page': 1}, + name="list" + ), + path( + r'/', + views.FieldNoteListView.as_view(), + name="list" + ), + path( + r'//.txt', + views.FieldNoteDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'//', + views.FieldNoteDetailView.as_view(), + name="detail" + ), + path( + r'//', + views.FieldNoteMonthArchiveView.as_view(month_format='%m'), + name="list_month" + ), +] diff --git a/app/fieldnotes/views.py b/app/fieldnotes/views.py new file mode 100644 index 0000000..fefd138 --- /dev/null +++ b/app/fieldnotes/views.py @@ -0,0 +1,36 @@ +from django.views.generic.dates import YearArchiveView, MonthArchiveView +from django.views.generic.detail import DetailView + +from utils.views import PaginatedListView + +from .models import FieldNote + + +class FieldNoteListView(PaginatedListView): + """ + Return a list of Notes in reverse chronological order + """ + queryset = FieldNote.objects.filter(status=1).order_by('-pub_date') + + +class FieldNoteDetailView(DetailView): + model = FieldNote + slug_field = "slug" + + +class FieldNoteDetailViewTXT(FieldNoteDetailView): + template_name = "jrnl/entry.txt" + + +class FieldNoteYearArchiveView(YearArchiveView): + queryset = FieldNote.objects.filter(status=1) + date_field = "pub_date" + template_name = "fieldnotes/fieldnote_archive_list_date.html" + make_object_list = True + + +class FieldNoteMonthArchiveView(MonthArchiveView): + queryset = FieldNote.objects.filter(status=1) + date_field = "pub_date" + make_object_list = True + template_name = "fieldnotes/fieldnote_archive_list_date.html" diff --git a/app/jrnl/migrations/0033_entry_field_notes_two.py b/app/jrnl/migrations/0033_entry_field_notes_two.py new file mode 100644 index 0000000..b90e86b --- /dev/null +++ b/app/jrnl/migrations/0033_entry_field_notes_two.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.7 on 2019-03-03 15:25 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fieldnotes', '0002_auto_20190303_1222'), + ('jrnl', '0032_entry_subtitle'), + ] + + operations = [ + migrations.AddField( + model_name='entry', + name='field_notes_two', + field=models.ManyToManyField(blank=True, to='fieldnotes.FieldNote'), + ), + ] diff --git a/app/jrnl/models.py b/app/jrnl/models.py index beb0723..dc2b3dc 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -22,6 +22,7 @@ from photos.models import PhotoGallery, LuxImage, LuxImageSize from locations.models import Location from sketches.models import Sketch from books.models import Book +from fieldnotes.models import FieldNote from utils.util import render_images, parse_video, markdown_to_html @@ -66,6 +67,7 @@ class Entry(models.Model): featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) has_video = models.BooleanField(blank=True, default=False) field_notes = models.ManyToManyField(Sketch, blank=True) + field_notes_two = models.ManyToManyField(FieldNote, blank=True) books = models.ManyToManyField(Book, blank=True) class Meta: diff --git a/app/photos/models.py b/app/photos/models.py index 2e022e2..df8eac4 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -159,6 +159,9 @@ class LuxImage(models.Model): else: return "%s/%s/%s_%s.%s" % (settings.IMAGES_ROOT, self.pub_date.strftime("%Y"), base, size, self.get_image_ext()) + def get_thumbnail_url(self): + return self.get_image_by_size("tn") + def admin_thumbnail(self): return format_html('' % (self.get_image_by_size(), self.get_image_by_size("tn"))) admin_thumbnail.short_description = 'Thumbnail' diff --git a/config/base_urls.py b/config/base_urls.py index 18e63b4..ee9fce1 100644 --- a/config/base_urls.py +++ b/config/base_urls.py @@ -49,7 +49,7 @@ urlpatterns = [ path(r'book-notes/', include('books.urls')), path(r'people/', include('people.urls')), path(r'dialogues/', include('sightings.urls', namespace='sightings')), - path(r'field-notes/', include('sketches.urls', namespace='sketches')), + path(r'field-notes/', include('fieldnotes.urls', namespace='fieldnotes')), path(r'src/', include('src.urls', namespace='src')), path(r'tools/', include('essays.urls', namespace='tools')), path(r'essays/', include('essays.urls', namespace='essays')), diff --git a/design/sass/_archives.scss b/design/sass/_archives.scss index 1d2060e..36dca63 100644 --- a/design/sass/_archives.scss +++ b/design/sass/_archives.scss @@ -408,5 +408,32 @@ line-height: 1.3; margin-top: 4px; } - + h3.p-summary { + font-family: $headline_font_serif; + font-style: italic; + margin-top: .25rem; + margin-bottom: .25rem; + line-height: 1.2; + @include fontsize(22); + } + .post-location { + margin: .5rem 0 0 0; + } +} +.circle-img-wrapper { + width: 106px; + height: 106px; + float: left; + overflow: hidden; + border-radius: 50%; + border: 3px solid #666; + margin-right: .5rem; + img { + width: 160px; + max-width: 160px; + } + @include breakpoint(gamma) { + margin-left: -128px; + margin-top: -10px; + } } diff --git a/design/sass/_details.scss b/design/sass/_details.scss index 8f25038..8996712 100644 --- a/design/sass/_details.scss +++ b/design/sass/_details.scss @@ -41,11 +41,21 @@ display: inline-block; border-top: 1px solid #efefef; color: #b6b6b6; + text-align: center; a { color: #b6b6b6; text-decoration: underline; text-decoration-color: $orange; } + @include breakpoint(gamma) { + text-align: left; + } + } + .post-date { + text-align: center; + @include breakpoint(alpha) { + text-align: left; + } } .map { width: 100vw; diff --git a/design/sass/_src.scss b/design/sass/_src.scss index a20e1f3..3cdaa57 100644 --- a/design/sass/_src.scss +++ b/design/sass/_src.scss @@ -168,10 +168,3 @@ code > .comment::after { } } -#essay-archive h1 { - @include constrain_narrow; -} -#essay-archive h4 { - margin-bottom: 3em; - margin-top: -.85em; -} diff --git a/design/templates/fieldnotes/fieldnote_archive_list_date.html b/design/templates/fieldnotes/fieldnote_archive_list_date.html new file mode 100644 index 0000000..57bbb69 --- /dev/null +++ b/design/templates/fieldnotes/fieldnote_archive_list_date.html @@ -0,0 +1,44 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load html5_datetime %} +{% load pagination_tags %} +{% block pagetitle %} Field Notes | luxagraf {% endblock %} +{% block metadescription %} Rough notes and sketches from the field {% endblock %} +{%block bodyid%}id="field-notes"{%endblock%} + +{% block primary %} + +
+
+

Field Notes {% if month or year %}{% if month %} from {{month|date:"F"}} {{month|date:"Y"}}{%else%} from {{year|date:"Y"}}{%endif%}{%endif%}

+

Quick notes, sketches and images from the road. This is the semi-orgnized brain dump that comes before the more organized journal entries and essays. If I used social media this is the stuff I'd probably put there, but I prefer to put it here, even if it means a lot few people read it.

+
+ +
+ +{% endblock %} + + + diff --git a/design/templates/fieldnotes/fieldnote_detail.html b/design/templates/fieldnotes/fieldnote_detail.html new file mode 100644 index 0000000..fb5e9e4 --- /dev/null +++ b/design/templates/fieldnotes/fieldnote_detail.html @@ -0,0 +1,81 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load html5_datetime %} +{% load month_number_to_name %} +{% block pagetitle %}{{object.title|title|smartypants|safe}} - Luxagraf, Field Notes{% endblock %} + +{% block metadescription %}{{object.body_html|striptags|safe|truncatewords:30}}{% endblock %} +{%block extrahead%} + + + + + +{%endblock%} +{% block bodyid %}class="notes--permalin detail" id="archive-{% if month %}{{month|month_number_to_name}}{%endif%}{{year}}"{%endblock%} + + +{% block primary %} +
+
+
+

{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|safe}}{%endif%}

+ {% if object.subtitle %}

{{object.subtitle|smartypants|safe}}

{%endif%} + + + +
+
+ {{object.body_html|safe|smartypants}} +
+ + + + + + + + {% with object.get_next_published as next %} + {% with object.get_previous_published as prev %} + {%endwith%}{%endwith%} +
+
+{% endblock %} diff --git a/design/templates/fieldnotes/fieldnote_list.html b/design/templates/fieldnotes/fieldnote_list.html new file mode 100644 index 0000000..c667ef3 --- /dev/null +++ b/design/templates/fieldnotes/fieldnote_list.html @@ -0,0 +1,46 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load html5_datetime %} +{% load pagination_tags %} +{% block pagetitle %} Field Notes | luxagraf {% endblock %} +{% block metadescription %} Rough notes and sketches from the field {% endblock %} +{%block bodyid%}id="field-notes"{%endblock%} + +{% block primary %} + +
+
+

Field Notes

+

Quick notes, sketches and images from the road. This is the semi-orgnized brain dump that comes before the more organized journal entries and essays. If I used social media this is the stuff I'd probably put there, but I prefer to put it here, even if it means a lot few people read it.

+
+ {% autopaginate object_list 30 %} + +
+ + +{% endblock %} + + + -- cgit v1.2.3-70-g09d2