From d674d75c68c3aa65b0f9bb40c512ea8f4f657377 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sat, 6 May 2023 11:50:00 -0400 Subject: jrnl: added a film category (repurposed friends) --- app/posts/migrations/0021_alter_post_post_type.py | 18 ++++ app/posts/models.py | 4 +- app/posts/templates/posts/film_detail.html | 115 ++++++++++++++++++++++ app/posts/templates/posts/film_list.html | 22 +++++ app/posts/urls/film_urls.py | 24 +++++ app/posts/urls/friends_urls.py | 20 ++-- app/posts/views/film_views.py | 51 ++++++++++ app/posts/views/friends_views.py | 1 - 8 files changed, 243 insertions(+), 12 deletions(-) create mode 100644 app/posts/migrations/0021_alter_post_post_type.py create mode 100644 app/posts/templates/posts/film_detail.html create mode 100644 app/posts/templates/posts/film_list.html create mode 100644 app/posts/urls/film_urls.py create mode 100644 app/posts/views/film_views.py (limited to 'app/posts') diff --git a/app/posts/migrations/0021_alter_post_post_type.py b/app/posts/migrations/0021_alter_post_post_type.py new file mode 100644 index 0000000..c05c6e7 --- /dev/null +++ b/app/posts/migrations/0021_alter_post_post_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.1 on 2023-05-06 11:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0020_remove_post_issue'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='post_type', + field=models.IntegerField(choices=[(0, 'range'), (1, 'review'), (2, 'essay'), (3, 'src'), (4, 'jrnl'), (5, 'field note'), (6, 'guide'), (7, 'film')], default=4), + ), + ] diff --git a/app/posts/models.py b/app/posts/models.py index 9697f27..1dafa1a 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -46,7 +46,7 @@ class PostType(models.IntegerChoices): JRNL = 4, ('jrnl') FIELD_NOTE = 5, ('field note') GUIDE = 6, ('guide') - FRIENDS = 7, ('friends') + FILM = 7, ('film') class Post(models.Model): @@ -104,6 +104,8 @@ class Post(models.Model): return self.title def get_absolute_url(self): + if self.post_type == PostType.FILM: + return reverse('essays:detail', kwargs={"slug": self.slug}) if self.post_type == PostType.ESSAY: return reverse('essays:detail', kwargs={"slug": self.slug}) if self.post_type == PostType.RANGE: diff --git a/app/posts/templates/posts/film_detail.html b/app/posts/templates/posts/film_detail.html new file mode 100644 index 0000000..42d06a2 --- /dev/null +++ b/app/posts/templates/posts/film_detail.html @@ -0,0 +1,115 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load comments %} +{%block htmlclass%}class="detail single"{%endblock%} +{% block pagetitle %}{{object.title|title|smartypants|safe}} - by Scott Gilbertson{% endblock %} + +{% block metadescription %}{% autoescape on %}{{object.meta_description|striptags|safe}}{% endautoescape %}{% endblock %}{%block extrahead%} + +{% if object.has_code %} {%endif %} +{%endblock%} +{% block breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{% endblock %} +{% block primary %}
+
+
+

{{object.title|smartypants|safe}}

+ {% if object.subtitle %}

{{object.subtitle|smartypants|safe}}

{%endif%} + +
+
+ {% if object.prologue_html %}
+ {{object.prologue_html|smartypants|safe}} +

{%endif%} + {{object.body_html|safe|smartypants}} + {% if object.epilogue_html %}
+ {{object.epilogue_html|smartypants|safe}} +
{%endif%} +
+ {%if wildlife or object.field_notes.all or object.books.all %}{%endif%} +
+
+ {% if object.related.all %}
+ +
{%endif%} + {% comment %}
+
If you enjoyed this, you should join the mailing list…
+ {% include 'mailing_list.html' %} +
{% endcomment %} + {% if object.enable_comments %} +{% get_comment_count for object as comment_count %} +{%if comment_count > 0 %} +
+

{{comment_count}} Comment{{ comment_count|pluralize }}

+{% render_comment_list for object %} +{%endif%} +
+{% render_comment_form for object %} +
+{% else %} +

Sorry, comments have been disabled for this post.

+
+{%endif%} + +{% endblock %} +{% block js %} + +{{ block.super }} +{%endblock%} diff --git a/app/posts/templates/posts/film_list.html b/app/posts/templates/posts/film_list.html new file mode 100644 index 0000000..7a68058 --- /dev/null +++ b/app/posts/templates/posts/film_list.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% block pagetitle %}Notes and Essays On Living - By Scott Gilbertson {% endblock %} +{% block metadescription %}Essays and stories on self-reliance, DIY, repair, tools, birding, walking, living well, and other ephemera.{% endblock %} +{% block breadcrumbs %}{% if breadcrumbs %}{% include "lib/breadcrumbs.html" with breadcrumbs=breadcrumbs %}{%endif%}{% endblock %} +{% block primary %}
+
+

Films

+

Être fort pour être utile

+

Films about paddleboarding, hiking, repair, tools, birding, walking, living well, and other bric-à-brac. Please, enjoy.

+
+ +
+{%endblock%} diff --git a/app/posts/urls/film_urls.py b/app/posts/urls/film_urls.py new file mode 100644 index 0000000..872d3f4 --- /dev/null +++ b/app/posts/urls/film_urls.py @@ -0,0 +1,24 @@ +from django.urls import path, re_path + +from ..views import film_views as views + +app_name = "film" + +urlpatterns = [ + path( + r'', + views.FilmDetailView.as_view(), + name="detail" + ), + path( + r'/', + views.FilmListView.as_view(), + name="list" + ), + path( + r'', + views.FilmListView.as_view(), + {'page':1}, + name="list" + ), +] diff --git a/app/posts/urls/friends_urls.py b/app/posts/urls/friends_urls.py index b7f7608..ca68ca0 100644 --- a/app/posts/urls/friends_urls.py +++ b/app/posts/urls/friends_urls.py @@ -6,16 +6,16 @@ from ..views import friends_views as views app_name = "range" urlpatterns = [ - path( - r'feed.xml', - views.FriendsRSSFeedView(), - name="feed" - ), - path( - r'/', - views.FriendsDetailView.as_view(), - name="friends-detail" - ), + # path( + # r'feed.xml', + # views.FriendsRSSFeedView(), + # name="feed" + # ), + # path( + # r'/', + # views.FriendsDetailView.as_view(), + # name="friends-detail" + # ), path( r'', views.FriendsListView.as_view(), diff --git a/app/posts/views/film_views.py b/app/posts/views/film_views.py new file mode 100644 index 0000000..3122240 --- /dev/null +++ b/app/posts/views/film_views.py @@ -0,0 +1,51 @@ +from django.views.generic import ListView +from django.views.generic.detail import DetailView +from django.contrib.syndication.views import Feed +from django.apps import apps +from django.conf import settings + +from utils.views import PaginatedListView, LuxDetailView + +from ..models import Post, PostType +from taxonomy.models import Category + + +class FilmListView(PaginatedListView): + model = Post + template_name = "posts/film_list.html" + + def get_queryset(self): + queryset = super(FilmListView, self).get_queryset() + return queryset.filter(site__domain='luxagraf.net').filter(post_type__in=[PostType.FILM]).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(FilmListView, self).get_context_data(**kwargs) + context['breadcrumbs'] = ('Film',) + return context + + +class FilmDetailView(LuxDetailView): + model = Post + slug_field = "slug" + + def get_queryset(self): + queryset = super(FilmDetailView, self).get_queryset() + return queryset.select_related('location').prefetch_related('field_notes') + + def get_context_data(self, **kwargs): + context = super(FilmDetailView, self).get_context_data(**kwargs) + related = [] + for obj in self.object.related.all(): + 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 + return context + + def get_template_names(self): + obj = self.get_object() + return ["posts/film_detail.html"] + diff --git a/app/posts/views/friends_views.py b/app/posts/views/friends_views.py index 3d6ea8d..c83ca36 100644 --- a/app/posts/views/friends_views.py +++ b/app/posts/views/friends_views.py @@ -29,7 +29,6 @@ class FriendsListView(PaginatedListView): """ model = Post template_name = "posts/friends_list.html" - queryset = Post.objects.filter(post_type=PostType.FRIENDS,status=1).order_by('-pub_date') def get_context_data(self, **kwargs): context = super(FriendsListView, self).get_context_data(**kwargs) -- cgit v1.2.3-70-g09d2