diff options
author | luxagraf <sng@luxagraf.net> | 2020-01-27 20:37:10 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2020-01-27 20:37:10 -0500 |
commit | 6e8b62d8c38f6ca366f240ea45ad738ebfd62943 (patch) | |
tree | b8c695cdd5c7f1f7729fa6750ed49c1eb2eae3e8 | |
parent | 09abece4982e8dceabe1dd8d678639205a4a6208 (diff) |
abstracted breadcrumbs into seperate template
38 files changed, 417 insertions, 106 deletions
diff --git a/design/templates/details/book.html b/app/books/templates/books/book_detail.html index 8a87ae5..99d5b9d 100644 --- a/design/templates/details/book.html +++ b/app/books/templates/books/book_detail.html @@ -1,12 +1,8 @@ {% extends 'base.html' %} {% load typogrify_tags %} {%block bodyid%}class="detail"{%endblock%} -{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - <li><a href="/book-notes/" title="books" itemprop="url"><span itemprop="title">books</span></a> → </li> - <li>{{object.title|smartypants|safe}}</li> - </ul> - <main itemprop="mainEntity" itemscope itemtype="http://schema.org/Book"> +{% block breadcrumbs %}{% include "lib/breadcrumbs_detail.html" with breadcrumbs=breadcrumbs %}{% endblock %} + {% block primary %}<main itemprop="mainEntity" itemscope itemtype="http://schema.org/Book"> <header class="tight"> <h1 class="post-title book-title" itemprop="name">{{object.title|smartypants|widont|safe}}</h1> <h2 class="post-subtitle" itemprop="author" itemscope itemtype="http://schema.org/Person"> diff --git a/design/templates/archives/books.html b/app/books/templates/books/book_list.html index 1862563..96d4d1b 100644 --- a/design/templates/archives/books.html +++ b/app/books/templates/books/book_list.html @@ -5,13 +5,8 @@ {% block pagetitle %} Books | luxagraf {% endblock %} {% block metadescription %}Books I've read and thoughts on them. {% endblock %} {%block bodyid%}class="archive" id="books-archive"{%endblock%} - -{% block primary %} - <ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - <li>Books</li> - </ul> - <main>{% autopaginate object_list 24 %} +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}<main>{% autopaginate object_list 24 %} <h1 class="hide">Books</h1> <div class="intro"> <p>I wear glasses because as a child I would stay up late, covers pulled over my head, reading by the dim light of a dying flashlight. At least that's what an eye doctor told me when I was younger. Probably a load of crap, but I still love reading and I still often do it by poor light far later in the night than is reasonable.</p> diff --git a/app/books/views.py b/app/books/views.py index e829476..bf09996 100644 --- a/app/books/views.py +++ b/app/books/views.py @@ -1,17 +1,16 @@ from django.views.generic.detail import DetailView -from utils.views import PaginatedListView +from utils.views import PaginatedListView, LuxDetailView from .models import Book class BookListView(PaginatedListView): - template_name = 'archives/books.html' + model = Book def get_queryset(self): return Book.objects.filter(is_public=True).order_by('-read_date').select_related() -class BookDetailView(DetailView): +class BookDetailView(LuxDetailView): model = Book - template_name = "details/book.html" slug_field = "slug" diff --git a/app/fieldnotes/templates/fieldnotes/fieldnote_detail.html b/app/fieldnotes/templates/fieldnotes/fieldnote_detail.html index dc90e16..0d25108 100644 --- a/app/fieldnotes/templates/fieldnotes/fieldnote_detail.html +++ b/app/fieldnotes/templates/fieldnotes/fieldnote_detail.html @@ -13,15 +13,8 @@ <meta name="geo.region" content="{{object.country.iso2}}{%if object.state.code != '' %}-{{object.state.code}}{%endif%}"> {%endblock%} {% block bodyid %}class="notes--permalin detail" id="archive-{% if month %}{{month|month_number_to_name}}{%endif%}{{year}}"{%endblock%} - - -{% block primary %}<ul class="bl crumbs" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - <li><a href="/field-notes/" itemprop="url"><span itemprop="title">Field Notes</span></a> →</li> - <li><a href="/field-notes/{{object.pub_date|date:"Y"}}/">{{object.pub_date|date:"Y"}}</a> →</li> - <li itemprop="title"><a href="/field-notes/{{object.pub_date|date:"Y"}}/{{object.pub_date|date:"m"}}/">{{object.pub_date|date:"F"}}</a></li> - </ul> - <main role="main"> +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}<main role="main"> <article class="h-entry hentry {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/BlogPosting"> <header id="header" class="post-header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}"> <h1 class="p-name entry-title post-title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|safe}}{%endif%}</h1> diff --git a/app/fieldnotes/templates/fieldnotes/fieldnote_list.html b/app/fieldnotes/templates/fieldnotes/fieldnote_list.html index c201382..5ee6f06 100644 --- a/app/fieldnotes/templates/fieldnotes/fieldnote_list.html +++ b/app/fieldnotes/templates/fieldnotes/fieldnote_list.html @@ -5,13 +5,8 @@ {% block pagetitle %} Field Notes | luxagraf {% endblock %} {% block metadescription %}Rough notes and sketches from the field {% endblock %} {%block bodyid%}id="field-notes"{%endblock%} - -{% block primary %} - <ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - <li>Field Notes</li> - </ul> - <main role="main" id="essay-archive" class="essay-archive archive-list"> +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}<main role="main" id="essay-archive" class="essay-archive archive-list"> <div class="essay-intro"> <h2>Field Notes</h2> <p>Quick notes, sketches and images from the road. This is the semi-orgnized brain dump that comes before the more organized <a href="/jrnl/" title="read the journal">journal entries</a> and <a href="/essays/" title="read essays">essays</a>. 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 fewer people read it.</p> diff --git a/app/fieldnotes/urls.py b/app/fieldnotes/urls.py index f3ef944..85ee710 100644 --- a/app/fieldnotes/urls.py +++ b/app/fieldnotes/urls.py @@ -2,7 +2,7 @@ from django.urls import path, re_path from . import views -app_name = "fieldnotes" +app_name = "field notes" urlpatterns = [ re_path( diff --git a/app/fieldnotes/views.py b/app/fieldnotes/views.py index fefd138..9b49cc0 100644 --- a/app/fieldnotes/views.py +++ b/app/fieldnotes/views.py @@ -1,19 +1,20 @@ from django.views.generic.dates import YearArchiveView, MonthArchiveView from django.views.generic.detail import DetailView -from utils.views import PaginatedListView +from utils.views import PaginatedListView, LuxDetailView from .models import FieldNote class FieldNoteListView(PaginatedListView): + model = FieldNote """ Return a list of Notes in reverse chronological order """ queryset = FieldNote.objects.filter(status=1).order_by('-pub_date') -class FieldNoteDetailView(DetailView): +class FieldNoteDetailView(LuxDetailView): model = FieldNote slug_field = "slug" diff --git a/app/jrnl/models.py b/app/jrnl/models.py index dda9d6d..f3734da 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -273,14 +273,17 @@ def cache_gravatar(sender, comment, **kwargs): urllib.request.urlretrieve(url, local_grav) -#@receiver(post_save, sender=Entry) -#def post_save_events(sender, update_fields, created, instance, **kwargs): -# related, created = RelatedPost.objects.get_or_create(model_name=instance.get_content_type(), entry_id = instance.id) -# related.title = instance.title -# related.slug = instance.slug -# post_save.disconnect(post_save_events, sender=Entry) -# instance.save() -# post_save.connect(post_save_events, sender=Entry) +@receiver(post_save, sender=Entry) +def post_save_events(sender, update_fields, created, instance, **kwargs): + """ + Creates a generic related entry when a new post is added + """ + if created: + related, c = RelatedPost.objects.get_or_create(model_name=instance.get_content_type(), entry_id = instance.id, pub_date=instance.pubdate) + if c: + related.title = instance.title + related.slug = instance.slug + related.save() # from django_comments.signals import comment_will_be_posted # from django_comments import akismet diff --git a/design/templates/jrnl/entry_detail.html b/app/jrnl/templates/jrnl/entry_detail.html index b676ba5..0904178 100644 --- a/design/templates/jrnl/entry_detail.html +++ b/app/jrnl/templates/jrnl/entry_detail.html @@ -57,7 +57,7 @@ {%block htmlclass%}{% with object.template_name as t %} class="detail {%if t == 1 or t == 3 or t == 5 %}double{%else%}single{%endif%}{%if t == 2 or t == 3 %} dark{%endif%}{%if t == 4 or t == 5 %} black{%endif%}"{%endwith%}{%endblock%} - + {% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} {% block primary %} <main> <article class="h-entry hentry entry-content content{% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/BlogPosting"> diff --git a/design/templates/jrnl/entry_detail.txt b/app/jrnl/templates/jrnl/entry_detail.txt index 547ce79..547ce79 100644 --- a/design/templates/jrnl/entry_detail.txt +++ b/app/jrnl/templates/jrnl/entry_detail.txt diff --git a/design/templates/jrnl/entry_list.html b/app/jrnl/templates/jrnl/entry_list.html index 5aef750..6eefe10 100644 --- a/design/templates/jrnl/entry_list.html +++ b/app/jrnl/templates/jrnl/entry_list.html @@ -4,15 +4,8 @@ {% block pagetitle %}Luxagraf | {% if region %}Travel Writing from {{region.name|title|smartypants|safe}}{%else%}Travel Writing from Around the World {%endif%}{% if page != "1" %} -- Page {{page}}{%endif%}{% endblock %} {% block metadescription %}{% if region %}Travel writing, essays and dispatches from {{region.name|title|smartypants|safe}}{%else%}Travel writing, essays and dispatches from around the world{%endif%} Page {{page}}{% endblock %} {%block bodyid%}id="writing" class="archive"{%endblock%} - - -{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - {% if region %}{%if region.name == 'United States'%} <li><a href="/jrnl/" title="See all Journal Entries" itemprop="url"><span itemprop="title">Jrnl</span></a> →</li> - <li itemprop="title">the United States</li>{%else%}<li><a href="/jrnl/" title="See all Journal Entries" itemprop="url"><span>Jrnl</span></a> →</li> - <li>{{region.name|title|smartypants|safe}}</li>{%endif%}{%else%}<li>Jrnl</li>{%endif%} - </ul> - <main class="archive-grid"> +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}<main class="archive-grid"> <h1 class="hide">{% if region %}Journal entries from {%if region.name == 'United States'%}the United States{%else%}{{region.name|title|smartypants|safe}}{%endif%}{%else%}Journal {%endif%}</h1>{% autopaginate object_list 24 %} {% for object in object_list %} <article class="h-entry hentry archive-card {% cycle 'odd' 'even' %} {% cycle 'first' 'second' 'third' %}" itemscope itemType="http://schema.org/Article"> <div class="post-image"> diff --git a/app/jrnl/views.py b/app/jrnl/views.py index 1b38de9..6b7cc8d 100644 --- a/app/jrnl/views.py +++ b/app/jrnl/views.py @@ -1,6 +1,7 @@ from django.views.generic import ListView from django.views.generic.detail import DetailView from django.views.generic.dates import DateDetailView +from django.urls import reverse from django.views.generic.dates import YearArchiveView, MonthArchiveView from django.contrib.syndication.views import Feed from django.apps import apps @@ -31,6 +32,7 @@ class EntryCountryList(PaginatedListView): """ Return a list of Entries by Country in reverse chronological order """ + model = Entry def get_context_data(self, **kwargs): # Call the base implementation first to get a context @@ -102,6 +104,8 @@ class EntryDetailView(DateDetailView): model = apps.get_model(obj.model_name.app_label, obj.model_name.model) related.append(model.objects.get(slug=obj.slug, pub_date=obj.pub_date)) context['related'] = related + context['breadcrumbs'] = ("jrnl",) + context['crumb_url'] = reverse('jrnl:list') return context diff --git a/app/locations/admin.py b/app/locations/admin.py index 0e78948..4beca5b 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -300,9 +300,10 @@ class WalkAdmin(OLAdminBase): ('Region', { 'fields': ( ('title', 'rating'), + 'subtitle', 'body_markdown', ('date_walked', 'slug'), - 'distance', + ('distance', 'duration'), 'gpx_file', 'point', ), diff --git a/app/locations/migrations/0025_auto_20191230_0738.py b/app/locations/migrations/0025_auto_20191230_0738.py new file mode 100644 index 0000000..3dd9093 --- /dev/null +++ b/app/locations/migrations/0025_auto_20191230_0738.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.2 on 2019-12-30 07:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('locations', '0024_auto_20191229_1817'), + ] + + operations = [ + migrations.AddField( + model_name='walk', + name='duration', + field=models.DecimalField(decimal_places=0, help_text='in minutes', max_digits=3, null=True), + ), + migrations.AlterField( + model_name='walk', + name='distance', + field=models.DecimalField(decimal_places=2, max_digits=3, null=True), + ), + ] diff --git a/app/locations/migrations/0026_walk_subtitle.py b/app/locations/migrations/0026_walk_subtitle.py new file mode 100644 index 0000000..e5aae3f --- /dev/null +++ b/app/locations/migrations/0026_walk_subtitle.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.2 on 2020-01-22 10:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('locations', '0025_auto_20191230_0738'), + ] + + operations = [ + migrations.AddField( + model_name='walk', + name='subtitle', + field=models.CharField(blank=True, max_length=200), + ), + ] diff --git a/app/locations/models.py b/app/locations/models.py index e9eb047..6f598b2 100644 --- a/app/locations/models.py +++ b/app/locations/models.py @@ -469,6 +469,7 @@ def parse_gpx(gpx_obj, gpx_data): class Walk(models.Model): title = models.CharField(max_length=300) + subtitle = models.CharField(max_length=200, blank=True) slug = models.SlugField() body_markdown = models.TextField() body_html = models.TextField(blank=True) @@ -484,11 +485,19 @@ class Walk(models.Model): ('5', "5 Stars"), ) rating = models.CharField(max_length=1, choices=RATINGS, null=True, blank=True) - distance = models.DecimalField(max_digits=3, decimal_places=1, null=True) + distance = models.DecimalField(max_digits=3, decimal_places=2, null=True) + duration = models.DecimalField(max_digits=3, decimal_places=0, null=True, help_text="in minutes") def __str_(self): return self.title + def get_rating(self): + return int(self.rating) + + @property + def ratings_range(cls): + return range(1, 6) + def save(self, *args, **kwargs): created = self.pk is None if not created: diff --git a/app/locations/templates/locations/walk_detail.html b/app/locations/templates/locations/walk_detail.html new file mode 100644 index 0000000..f36a507 --- /dev/null +++ b/app/locations/templates/locations/walk_detail.html @@ -0,0 +1,76 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{%block bodyid%}class="detail"{%endblock%} +{% block primary %}<ul class="bl crumbs" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> + <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> + <li><a href="/walks/" itemprop="url"><span itemprop="title">Walks</span></a> →</li> + <li><a href="/walks/{{object.pub_date|date:"Y"}}/">{{object.date_walked|date:"Y"}}</a> →</li> + <li>{{object.title}}</li> + </ul> + <main> + <article class="h-entry hentry {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/BlogPosting"> + <header id="header" class="post-header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}"> + <h1 class="p-name entry-title post-title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|safe}}{%endif%}</h1> + {% if object.subtitle %}<h2 class="post-subtitle">{{object.subtitle|smartypants|safe}}</h2>{%endif%} + <div class="post-linewrapper"> + {% if object.location %}<div class="p-location h-adr adr post-location" itemprop="contentLocation" itemscope itemtype="http://schema.org/Place"> + <h3 class="h-adr" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{% if object.location.country_name == "United States" %}<span class="p-locality locality" itemprop="addressLocality">{{object.location.name|smartypants|safe}}</span>, <a class="p-region region" href="/jrnl/united-states/" title="travel writing from the United States">{{object.location.state_name|safe}}</a>, <span class="p-country-name" itemprop="addressCountry">U.S.</span>{%else%}<span class="p-region" itemprop="addressRegion">{{object.location.name|smartypants|safe}}</span>, <a class="p-country-name country-name" href="/jrnl/{{object.location.country_slug}}/" title="travel writing from {{object.location.country_name}}"><span itemprop="addressCountry">{{object.location.country_name|safe}}</span></a>{%endif%}</h3> + </div>{%endif%} + <time class="dt-published published dt-updated post-date" datetime="{{object.date_walked|date:'c'}}" itemprop="datePublished">{{object.date_walked|date:"F"}} <span>{{object.date_walked|date:"j, Y"}}</span></time> + <span class="hide" itemprop="author" itemscope itemtype="http://schema.org/Person">by <a class="p-author h-card" href="/about"><span itemprop="name">Scott Gilbertson</span></a></span> + </div> + </header> + <img src="{{object.get_image_url}}" alt="{{object.title}} map" /> + + <div class="meta-cover"> + <dl class="book-metadata"> + {% if object.distance %}<dt>Distance</dt> + <dd>{{object.distance}} miles</dd>{%endif%} + {% if object.duration%}<dt>Duration</dt> + <dd>{{object.duration}} minutes</dd>{%endif%} + + {% if object.rating %}<dt>Rating</dt><dd class="book-stars"> + {% for i in object.ratings_range %}{% if i <= object.get_rating%}★{%else%}☆{%endif%}{%endfor%}</span></dd>{%endif%} + </dl> + <div class="e-content"> + <h5>Notes</h5> + {{object.body_html|safe|smartypants}} + </div> + + {%if wildlife %}<div class="entry-footer"> + <aside id="wildlife"> + <h3>Fauna and Flora</h3> + {% regroup wildlife by ap.apclass.get_kind_display as wildlife_list %} + <ul> + {% for object_list in wildlife_list %} + <li class="grouper">{{object_list.grouper}}<ul> + {% for object in object_list.list %} + <li>{%if object.ap.body_markdown%}<a href="{% url 'sightings:detail' object.ap.slug %}">{{object}}</a>{%else%}{{object}}{%endif%} </li> + {% endfor %}</ul> + {% endfor %}</ul> + </aside> + {% endif %} + {%if entry_list %} + <aside {% if wildlife %}class="margin-left-none" {%endif%}id="field_notes"> + <h3>Related Posts</h3> + <ul>{% for obj in entry_list %} + <li><a href="{% url 'jrnl:detail' year=obj.pub_date.year month=obj.pub_date|date:"m" slug=obj.slug %}">{{obj}}</a></li> + {% endfor %}</ul> + </aside>{% endif %} + </article> + {% with object.get_next_published as next %} + {% with object.get_previous_published as prev %} + <div class="nav-wrapper"> + <nav id="page-navigation" {%if wildlife or object.field_notes.all or object.books.all %}{%else%}class="page-border-top"{%endif%}> + <ul>{% if prev%} + <li id="prev"><span class="bl">Previous:</span> + <a href="{{ prev.get_absolute_url }}" rel="prev" title=" {{prev.title}}">{{prev.title|safe}}</a> + </li>{%endif%}{% if next%} + <li id="next"><span class="bl">Next:</span> + <a href="{{ next.get_absolute_url }}" rel="next" title=" {{next.title}}">{{next.title|safe}}</a> + </li>{%endif%} + </ul> + </nav>{%endwith%}{%endwith%} + </div> + </main> +{% endblock %} diff --git a/app/locations/templates/locations/walk_list.html b/app/locations/templates/locations/walk_list.html new file mode 100644 index 0000000..28d86ec --- /dev/null +++ b/app/locations/templates/locations/walk_list.html @@ -0,0 +1,40 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load html5_datetime %} +{% load pagination_tags %} +{% block pagetitle %}Walks.{% endblock %} +{% block metadescription %}{% endblock %} +{% block breadcrumbs %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList"> + <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> + <a href="/" title="luxagraf homepage" itemprop="item"> + <span itemprop="title">Home</span> + </a> → + </li> + <li itemprop="title">Walks</li> + </ul>{% endblock %} +{% block primary %}<main role="main" id="essay-archive" class="essay-archive archive-list"> + <div class="essay-intro"> + <h2>Walks</h2> + <h3>Walks, hikes, forays, whatever you wish to call them.</h3> + <p>Walking is [meditation](/meditation), particularly the discursive meditation I practice. So this is not so much a record of physical activity as mental. If you're looking for awesome hikes, there might be some in here, but don't expect details. That's not what I'm interested in recording.<p> + </div> + <h1 class="topic-hed">Walks</h1> + {% autopaginate object_list 30 %} + <ul class="fancy-archive-list">{% for object in object_list %} + <li class="h-entry hentry" itemscope itemType="http://schema.org/Article"> + <a href="{{object.get_absolute_url}}" class="u-url"> + <div class="circle-img-wrapper"><img src="{{object.featured_image.get_thumbnail_url}}" alt="{{object.featured_image.alt}}" class="u-photo" /></div> + <span class="date dt-published">{{object.pub_date|date:"F d, Y"}}</span> + <a href="{% url 'walks:walk-detail' object.slug %}"> + <h2>{{object.title|safe|smartypants|widont}}</h2> + {% if object.subtitle %}<h3 class="p-summary">{{object.subtitle|safe|smartypants|widont}}</h3>{%endif%} + </a> + {% if object.location %}<h4 class="p-location h-adr post-location" itemprop="geo" itemscope itemtype="http://data-vocabulary.org/Geo"> + <span class="p-locality">{{object.location.name|smartypants|safe}}</span>, + <span class="p-region">{{object.location.state_name}}</span>, + <span class="p-country-name">{{object.location.country_name}}</span> + </h4>{% endif %} + </li> + {%endfor%}</ul> + </main> +{%endblock%} diff --git a/app/locations/urls.py b/app/locations/urls.py index 5faefc1..ee98b17 100644 --- a/app/locations/urls.py +++ b/app/locations/urls.py @@ -6,6 +6,11 @@ app_name = "locations" urlpatterns = [ path( + r'<str:slug>', + views.WalkDetail.as_view(), + name="walk-detail" + ), + path( r'<str:country>/<str:state>/<str:slug>/', views.LocationDetail.as_view(), name="location-detail" diff --git a/app/locations/views.py b/app/locations/views.py index 3a93c0d..48ecc07 100644 --- a/app/locations/views.py +++ b/app/locations/views.py @@ -8,8 +8,8 @@ from django.db.models import Q from jrnl.models import Entry from projects.shortcuts import render_to_geojson from sightings.models import Sighting - -from .models import Country, Region, Route, Location +from utils.views import PaginatedListView +from .models import Country, Region, Route, Location, Walk def map_list(request): context = { @@ -99,3 +99,25 @@ class LocationDetail(DetailView): Q(location__in=Location.objects.filter(parent=self.get_object())) ).order_by('ap_id', 'ap__apclass__kind').distinct("ap") return context + + +class WalkDetail(DetailView): + model = Walk + + def get_context_data(self, **kwargs): + context = super(WalkDetail, self).get_context_data(**kwargs) + context['entry_list'] = Entry.objects.filter( + Q(location=self.get_object().location) | + Q(location__in=Location.objects.filter(parent=self.get_object().location)) + ) + context['wildlife'] = Sighting.objects.filter( + Q(location=self.get_object().location) | + Q(location__in=Location.objects.filter(parent=self.get_object().location)) + ).order_by('ap_id', 'ap__apclass__kind').distinct("ap") + return context + +class WalkList(PaginatedListView): + """ + Return list of Walks + """ + model = Walk diff --git a/app/locations/walk_urls.py b/app/locations/walk_urls.py new file mode 100644 index 0000000..4019ef6 --- /dev/null +++ b/app/locations/walk_urls.py @@ -0,0 +1,24 @@ +from django.urls import path, re_path + +from . import views + +app_name = "walks" + +urlpatterns = [ + path( + r'<str:slug>', + views.WalkDetail.as_view(), + name="walk-detail" + ), + re_path( + r'^(?P<page>\d+)/$', + views.WalkList.as_view(), + name="walk-list" + ), + re_path( + r'', + views.WalkList.as_view(), + {'page':1}, + name="walk-list" + ), +] diff --git a/design/templates/details/page.html b/app/pages/templates/pages/page_detail.html index bb80a72..4644386 100644 --- a/design/templates/details/page.html +++ b/app/pages/templates/pages/page_detail.html @@ -5,13 +5,8 @@ {% block metadescription %}{{object.meta_description}}{% endblock %} {%block htmlclass%}class="detail"{%endblock%} {%block bodyid%}id="{{object.title|slugify}}"{%endblock%} - -{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - {% if object.path%}<li><a href="/{{object.path|slugify}}/">{{object.path}}</a> → </li>{%endif%} - <li>{{object.title}}</li> - </ul> - <main> +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}<main> <article> <header class="post-header"> <h1 class="post-title">{{object.title}}</h1> diff --git a/design/templates/details/page.txt b/app/pages/templates/pages/page_detail.txt index 547ce79..547ce79 100644 --- a/design/templates/details/page.txt +++ b/app/pages/templates/pages/page_detail.txt diff --git a/app/pages/urls.py b/app/pages/urls.py new file mode 100644 index 0000000..c40eee0 --- /dev/null +++ b/app/pages/urls.py @@ -0,0 +1,13 @@ +from django.urls import path, re_path + +from . import views + +app_name = "pages" + +urlpatterns = [ + path( + r'', + views.PageDetailView.as_view(), + name="detail" + ), +] diff --git a/app/pages/views.py b/app/pages/views.py index 8431bc2..bef6529 100644 --- a/app/pages/views.py +++ b/app/pages/views.py @@ -1,12 +1,15 @@ -from django.views.generic.detail import DetailView +from utils.views import LuxDetailView from .models import Page -class PageDetailView(DetailView): +class PageDetailView(LuxDetailView): model = Page - slug_field = "slug" def get_template_names(self): obj = self.get_object() - return ["details/%s.html" % obj.slug, 'details/page.html'] + return ["pages/%s.html" % obj.slug, 'pages/page_detail.html'] + +class PageDetailTXTView(LuxDetailView): + model = Page + slug_field = "slug" diff --git a/app/posts/templates/posts/essay_detail.html b/app/posts/templates/posts/essay_detail.html index 8ffcfe5..23619d0 100644 --- a/app/posts/templates/posts/essay_detail.html +++ b/app/posts/templates/posts/essay_detail.html @@ -29,7 +29,7 @@ {%endblock%} {%block bodyid %}{% if object.get_post_type_display == 'tools' %}class="src"{% endif %}{%endblock%} - +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} {% block primary %} <main> <article class="h-entry hentry {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/Article"> diff --git a/app/posts/templates/posts/essay_list.html b/app/posts/templates/posts/essay_list.html index 271f83f..8a35225 100644 --- a/app/posts/templates/posts/essay_list.html +++ b/app/posts/templates/posts/essay_list.html @@ -3,16 +3,12 @@ {% block pagetitle %}Collected Essays of Scott Gilbertson {% endblock %} {% block metadescription %}Collected writing: essays, articles and stories on travel, photography, tools, walking, the natural world and other ephemera.{% endblock %} - -{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - <li>Essays</li> - </ul> - <main role="main" id="essay-archive" class="essay-archive archive-list"> +{% block breadcrumbs %}{% if breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{%endif%}{% endblock %} +{% block primary %}<main role="main" id="essay-archive" class="essay-archive archive-list"> <div class="essay-intro"> - <h2>My various articles and essays collected in one spot.</h2> + <h2>Essays & Articles</h2> <p>Topics include travel, writing, photography, free software, culture, and once, Del Taco.</p> - <p>Many essays below were previously published in: <em><a href="https://www.wired.com/author/scott-gilbertson/">WIRED</a></em>, <em><a href="https://www.budgettravel.com/article/0902_HTTN_SocialNetwork_5488">Budget Travel</a></em>, <em><a href="https://arstechnica.com/">Ars Technica</a></em>, <em><a href="https://web.archive.org/web/20100904114555/http://one.longshotmag.com/article/going-for-seconds">Longshot Magazine</a>,</em> <em><a href="https://web.archive.org/web/20150506051746/http://1888.center/scott-gilbertson/">The Cost of Paper</a></em> and elsewhere.</a></p> + <p>Some essays below were previously published in: <em><a href="https://www.wired.com/author/scott-gilbertson/" rel="me">WIRED</a></em>, <em><a href="https://www.budgettravel.com/article/0902_HTTN_SocialNetwork_5488">Budget Travel</a></em>, <em><a href="https://arstechnica.com/">Ars Technica</a></em>, <em><a href="https://www.epicurious.com/contributors/scott-gilbertson" rel="me">Epicurious</a></em>, <em><a href="https://web.archive.org/web/20100904114555/http://one.longshotmag.com/article/going-for-seconds">Longshot Magazine</a>,</em> <em><a href="https://web.archive.org/web/20150506051746/http://1888.center/scott-gilbertson/" rel="me">The Cost of Paper</a></em> and elsewhere.</a></p> </div> <h1 class="topic-hed">Essays</h1> <ul>{% for object in object_list %} diff --git a/app/posts/views.py b/app/posts/views.py index fc85fa7..47c8c86 100644 --- a/app/posts/views.py +++ b/app/posts/views.py @@ -4,7 +4,7 @@ from django.contrib.syndication.views import Feed from django.apps import apps from django.conf import settings -from utils.views import PaginatedListView +from utils.views import PaginatedListView, LuxDetailView from .models import Post from taxonomy.models import Category @@ -40,8 +40,17 @@ class EssayListView(PostList): queryset = super(EssayListView, self).get_queryset() return queryset.filter(post_type__in=[2,]).filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + def get_context_data(self, **kwargs): + ''' + override for custom breadcrumb path + ''' + # Call the base implementation first to get a context + context = super(EssayListView, self).get_context_data(**kwargs) + context['breadcrumbs'] = ('Essays',) + return context -class PostDetailView(DetailView): + +class PostDetailView(LuxDetailView): model = Post slug_field = "slug" @@ -62,6 +71,7 @@ class PostDetailView(DetailView): obj = self.get_object() return ["posts/%s_detail.html" % obj.get_post_type_display(), 'posts/post_detail.html'] + class PostDetailViewTXT(PostDetailView): template_name = "posts/entry_detail.txt" diff --git a/design/templates/src/post_detail.html b/app/src/templates/src/srcpost_detail.html index fb1bde0..2ad4e26 100644 --- a/design/templates/src/post_detail.html +++ b/app/src/templates/src/srcpost_detail.html @@ -17,18 +17,26 @@ <meta name="twitter:card" content="summary_large_image"/> <meta name="twitter:site" content="@luxagraf"/> <meta name="twitter:creator" content="@luxagraf"/> - -<link rel="stylesheet" href="/media/src/solarized.css" type="text/css" media="screen"/> + <link rel="stylesheet" href="/media/src/solarized.css" type="text/css" media="screen"/> {%endblock%} {% block bodyid %}class="src detail single"{% endblock %} {%block sitesubtitle %}Code Slowly{% endblock%} - -{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> - <li><a href="/src/"><code>src</code></a></li> - </ul> - <main role="main"> +{% block breadcrumbs %}<ol class="bl" id="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList"> + <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> + <a itemprop="item" href="/"> + <span itemprop="name">Home</span> + </a> → + <meta itemprop="position" content="1" /> + </li> + <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> + <a href="/src/" itemprop="item"> + <span itemprop="name">Book Notes</span> + </a> + <meta itemprop="position" content="2" /> + </li> + </ol>{% endblock %} +{% block primary %}<main role="main"> <article class="hentry post-article{% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/Article"> <header id="header" class="post-header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}"> <h1 class="p-name entry-title post--title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|safe|smartypants}}{%else%}{{object.title|safe|smartypants|widont}}{%endif%}</h1> diff --git a/design/templates/src/post_list.html b/app/src/templates/src/srcpost_list.html index af65ea7..dd5d410 100644 --- a/design/templates/src/post_list.html +++ b/app/src/templates/src/srcpost_list.html @@ -4,15 +4,9 @@ {% block pagetitle %}Tutorials and tools for building great things{% endblock %} {% block metadescription %}Tutorials and tools for building great things on the web - by Scott Gilbertson.{% endblock %} - {%block sitesubtitle %}Code Slowly{% endblock%} -{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> - <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li>{% if topic %} - <li><a href="/src/" title="luxagraf:src homepage" itemprop="url"><span itemprop="title"><code>src</code></span></a> → </li> - <li>{{topic}}</li>{%else%} - <li><code>src</code></li>{%endif%} - </ul> - <main role="main" id="essay-archive" class="essay-archive archive-list"> +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}<main role="main" id="essay-archive" class="essay-archive archive-list"> <div class="essay-intro"> <h2>Tutorials and tools for building great things on the web.</h2> <p>The indie web is an amazing democratic publishing platform unlike anything in history. The catch is, to avoid serving at the pleasure of the corporate king, you need to know <em>how</em> to publish. That's what these articles are here for, to help you learn how to use independent, community supported open source tools. The web won't last forever, let's build something cool while we can.</p> diff --git a/design/templates/src/topic_list.html b/app/src/templates/src/topic_list.html index 7149823..7149823 100644 --- a/design/templates/src/topic_list.html +++ b/app/src/templates/src/topic_list.html diff --git a/app/src/urls.py b/app/src/urls.py index 1e1488a..0ac6897 100644 --- a/app/src/urls.py +++ b/app/src/urls.py @@ -26,18 +26,24 @@ urlpatterns = [ name='list_books' ), path( - r'<slug>.txt', + r'<str:slug>.txt', views.EntryDetailViewTXT.as_view(), name="detail-txt" ), path( - r'<slug>', + r'<str:slug>', views.EntryDetailView.as_view(), name="detail" ), + re_path( + r'<int:page>', + views.SrcListView.as_view(), + name="list" + ), path( r'', views.SrcListView.as_view(), - name="list", + {'page':1}, + name="list" ), ] diff --git a/app/src/views.py b/app/src/views.py index f929949..7540e02 100644 --- a/app/src/views.py +++ b/app/src/views.py @@ -5,7 +5,7 @@ from django.urls import reverse from django.conf import settings #from paypal.standard.forms import PayPalPaymentsForm - +from utils.views import PaginatedListView from .models import SrcPost, Topic, Book @@ -44,7 +44,8 @@ class BookDetailView(DetailView): return context -class SrcListView(ListView): +class SrcListView(PaginatedListView): + model = SrcPost def get_queryset(self): return SrcPost.objects.filter(status__exact=1) diff --git a/app/utils/views.py b/app/utils/views.py index 60cb7de..152b2b7 100644 --- a/app/utils/views.py +++ b/app/utils/views.py @@ -1,7 +1,8 @@ from itertools import chain import json +from django.urls import reverse from django.http import Http404, HttpResponse -from django.views.generic import ListView +from django.views.generic import ListView, DetailView from django.apps import apps from django.shortcuts import render_to_response from django.shortcuts import render @@ -11,9 +12,15 @@ from photos.models import LuxImage, LuxVideo from recordings.models import Audio +BREADCRUMBS = { + 'SrcPost':'SRC', + 'Book':'Book Notes', + 'Entry':'Jrnl' +} + class PaginatedListView(ListView): """ - handles my own pagination system + handles my own pagination system and breadcrumbs """ context_object_name = 'object_list' @@ -29,6 +36,49 @@ class PaginatedListView(ListView): request.base_path = path return super(PaginatedListView, self).dispatch(request, *args, **kwargs) + def get_context_data(self, **kwargs): + ''' + Adds breadcrumb path to every view + ''' + # Call the base implementation first to get a context + context = super(PaginatedListView, self).get_context_data(**kwargs) + try: + context['breadcrumbs'] = (BREADCRUMBS[self.model.__name__],) + except KeyError: + context['breadcrumbs'] = (self.model._meta.verbose_name_plural,) + return context + + +class LuxDetailView(DetailView): + """ + handles breadcrumbs for detail pages + """ + def get_context_data(self, **kwargs): + ''' + Adds breadcrumb path to every view + ''' + # Call the base implementation first to get a context + context = super(LuxDetailView, self).get_context_data(**kwargs) + print(self.object._meta.verbose_name_plural) + try: + context['breadcrumbs'] = (BREADCRUMBS[self.object._meta.model],) + except KeyError: + if self.object._meta.verbose_name_plural == 'posts': + context['breadcrumbs'] = (self.object.get_post_type_display()+"s",) + context['crumb_url'] = "/%ss/" % self.object.get_post_type_display() + else: + context['breadcrumbs'] = (self.object._meta.verbose_name_plural,) + try: + context['crumb_url'] + except KeyError: + try: + context['crumb_url'] = reverse('%s:list' % self.object._meta.verbose_name_plural) + except: + # special case for pages: + context['breadcrumbs'] = (self.object.title,) + context['crumb_url'] = None + return context + def insert_image(request): """ diff --git a/config/base_urls.py b/config/base_urls.py index f77a8c1..ed73844 100644 --- a/config/base_urls.py +++ b/config/base_urls.py @@ -5,7 +5,7 @@ from django.conf import settings from django.contrib.sitemaps.views import sitemap from django.views.generic.base import RedirectView -from pages.views import PageDetailView +from pages.views import PageDetailView, PageDetailTXTView from jrnl.models import BlogSitemap from fieldnotes.models import FieldNoteSitemap from jrnl.views import HomepageList @@ -47,6 +47,8 @@ urlpatterns = [ path(r'jrnl/', include('jrnl.urls')), path(r'projects/', include('projects.urls')), path(r'topics/', include('taxonomy.urls')), + path(r'walk/', include('locations.walk_urls')), + path(r'walks/', include('locations.walk_urls')), path(r'locations/', include('locations.urls')), path(r'expenses/', include('expenses.urls', namespace='expenses')), path(r'photos/', include('photos.urls')), @@ -69,7 +71,8 @@ urlpatterns = [ path(r'map/', include('locations.urls', namespace='map')), path(r'', HomepageList.as_view(), name="homepage"), path(r'comments/', include('django_comments.urls')), - path(r'<slug>', PageDetailView.as_view()), + path(r'<slug>.txt', PageDetailTXTView.as_view()), + path(r'<slug>', include('pages.urls', namespace='pages')), path(r'<path>/<slug>/', PageDetailView.as_view()), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/design/templates/base.html b/design/templates/base.html index 67edd7a..2bdd7c0 100644 --- a/design/templates/base.html +++ b/design/templates/base.html @@ -41,6 +41,7 @@ </nav> </header> </div> + {% block breadcrumbs %}{% endblock %} {% block primary %}{% endblock %} {% block extrabody %}{% endblock %} {% block disclaimer %}{% endblock%} diff --git a/design/templates/details/note.html b/design/templates/details/note.html index 583d50b..4b52537 100644 --- a/design/templates/details/note.html +++ b/design/templates/details/note.html @@ -13,7 +13,27 @@ <meta name="geo.region" content="{{object.country.iso2}}{%if object.state.code != '' %}-{{object.state.code}}{%endif%}"> {%endblock%} {% block bodyid %}class="notes--permalin detail" id="archive-{% if month %}{{month|month_number_to_name}}{%endif%}{{year}}"{%endblock%} - +{% block breadcrumbs %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList"> + <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> + <a href="/" title="luxagraf homepage" itemprop="item"> + <span itemprop="title">Home</span> + </a> → + <meta itemprop="position" content="1" /> + </li> + <li itemscope itemtype="http://schema.org/ListItem"> + <a href="/field-notes/" itemprop="item"> + <span itemprop="title">Field Notes</span> + </a> → + <meta itemprop="position" content="2" /> + </li> + <li itemscope itemtype="http://schema.org/ListItem"> + <a href="/field-notes/{{object.pub_date|date:"Y"}}/"> + <span itemprop="title">{{object.pub_date|date:"Y"}}</span> + </a> → + <meta itemprop="position" content="3" /> + </li> + <li itemprop="title">Walks</li> + </ul>{% endblock %} {% block primary %}<ul class="bl crumbs" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"> <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> → </li> diff --git a/design/templates/lib/breadcrumbs.html b/design/templates/lib/breadcrumbs.html new file mode 100644 index 0000000..ac47d5a --- /dev/null +++ b/design/templates/lib/breadcrumbs.html @@ -0,0 +1,14 @@ +<ol class="bl" id="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList"> + <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="/"><span itemprop="name">Home</span></a> → + <meta itemprop="position" content="1" /> + </li> + {% for crumb in breadcrumbs %}<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> + {% if crumb_url %} + <a href="{{crumb_url}}" itemprop="item"><span itemprop="name">{{crumb}}</span></a> + <meta itemprop="position" content="{{ forloop.counter|add:"+1" }}" />{% else %} + <span itemprop="item"> + <span itemprop="name">{{crumb}}</span> + </span>{% endif %} + <meta itemprop="position" content="2" /> + </li>{%endfor%} + </ol> |