From 5bc22c064fbc51987007d85fbc8296a998cf6e84 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 18 Sep 2019 21:14:38 -0400 Subject: added posts, consolidated essays into posts --- app/builder/views.py | 4 + app/guides/__init__.py | 0 app/guides/admin.py | 67 ------- app/guides/build.py | 22 --- app/guides/guide_urls.py | 18 -- app/guides/migrations/0001_initial.py | 60 ------- .../migrations/0002_remove_guide_category.py | 17 -- app/guides/migrations/0003_guide_category.py | 21 --- app/guides/migrations/0004_auto_20190914_0646.py | 47 ----- .../migrations/0005_remove_guide_category.py | 17 -- app/guides/migrations/__init__.py | 0 app/guides/models.py | 136 -------------- app/guides/review_urls.py | 18 -- app/guides/templates/guides/guide_detail.html | 176 ------------------ app/guides/templates/guides/guide_detail.txt | 8 - app/guides/templates/guides/guide_list.html | 40 ----- app/guides/urls.py | 34 ---- app/guides/views.py | 62 ------- app/jrnl/admin.py | 8 +- app/jrnl/migrations/0044_auto_20190917_1703.py | 18 ++ app/jrnl/models.py | 19 +- app/normalize/__init__.py | 0 app/normalize/migrations/0001_initial.py | 26 +++ app/normalize/migrations/__init__.py | 0 app/normalize/models.py | 12 ++ app/posts/__init__.py | 0 app/posts/admin.py | 103 +++++++++++ app/posts/build.py | 27 +++ app/posts/essay_urls.py | 29 +++ app/posts/guide_urls.py | 29 +++ app/posts/importer.py | 29 +++ app/posts/migrations/0001_initial.py | 65 +++++++ app/posts/migrations/0002_auto_20190917_2029.py | 22 +++ app/posts/migrations/0003_auto_20190918_1230.py | 54 ++++++ app/posts/migrations/0004_auto_20190918_1241.py | 19 ++ app/posts/migrations/0005_auto_20190918_1244.py | 19 ++ app/posts/migrations/__init__.py | 0 app/posts/models.py | 200 +++++++++++++++++++++ app/posts/review_urls.py | 29 +++ app/posts/templates/horizontal_select.html | 17 ++ app/posts/templates/posts/entry_detail.txt | 8 + app/posts/templates/posts/essay_detail.html | 176 ++++++++++++++++++ app/posts/templates/posts/essay_list.html | 28 +++ app/posts/templates/posts/post_detail.html | 176 ++++++++++++++++++ app/posts/templates/posts/post_detail.txt | 8 + app/posts/templates/posts/post_list.html | 40 +++++ app/posts/urls.py | 24 +++ app/posts/views.py | 75 ++++++++ 48 files changed, 1258 insertions(+), 749 deletions(-) delete mode 100644 app/guides/__init__.py delete mode 100644 app/guides/admin.py delete mode 100644 app/guides/build.py delete mode 100644 app/guides/guide_urls.py delete mode 100644 app/guides/migrations/0001_initial.py delete mode 100644 app/guides/migrations/0002_remove_guide_category.py delete mode 100644 app/guides/migrations/0003_guide_category.py delete mode 100644 app/guides/migrations/0004_auto_20190914_0646.py delete mode 100644 app/guides/migrations/0005_remove_guide_category.py delete mode 100644 app/guides/migrations/__init__.py delete mode 100644 app/guides/models.py delete mode 100644 app/guides/review_urls.py delete mode 100644 app/guides/templates/guides/guide_detail.html delete mode 100644 app/guides/templates/guides/guide_detail.txt delete mode 100644 app/guides/templates/guides/guide_list.html delete mode 100644 app/guides/urls.py delete mode 100644 app/guides/views.py create mode 100644 app/jrnl/migrations/0044_auto_20190917_1703.py create mode 100644 app/normalize/__init__.py create mode 100644 app/normalize/migrations/0001_initial.py create mode 100644 app/normalize/migrations/__init__.py create mode 100644 app/normalize/models.py create mode 100644 app/posts/__init__.py create mode 100644 app/posts/admin.py create mode 100644 app/posts/build.py create mode 100644 app/posts/essay_urls.py create mode 100644 app/posts/guide_urls.py create mode 100644 app/posts/importer.py create mode 100644 app/posts/migrations/0001_initial.py create mode 100644 app/posts/migrations/0002_auto_20190917_2029.py create mode 100644 app/posts/migrations/0003_auto_20190918_1230.py create mode 100644 app/posts/migrations/0004_auto_20190918_1241.py create mode 100644 app/posts/migrations/0005_auto_20190918_1244.py create mode 100644 app/posts/migrations/__init__.py create mode 100644 app/posts/models.py create mode 100644 app/posts/review_urls.py create mode 100644 app/posts/templates/horizontal_select.html create mode 100644 app/posts/templates/posts/entry_detail.txt create mode 100644 app/posts/templates/posts/essay_detail.html create mode 100644 app/posts/templates/posts/essay_list.html create mode 100644 app/posts/templates/posts/post_detail.html create mode 100644 app/posts/templates/posts/post_detail.txt create mode 100644 app/posts/templates/posts/post_list.html create mode 100644 app/posts/urls.py create mode 100644 app/posts/views.py (limited to 'app') diff --git a/app/builder/views.py b/app/builder/views.py index ca4a876..2333704 100644 --- a/app/builder/views.py +++ b/app/builder/views.py @@ -12,6 +12,7 @@ from pages.build import builder as page_builder from fieldnotes.build import builder as fieldnotes_builder from photos.build import dailybuilder from essays.build import essaybuilder +from posts.build import posts_builder options = { 'writing': BuildWriting, @@ -79,6 +80,9 @@ def do_build(request): elif section == 'essays': context = {'message': 'Writing Essays to Disk'} essaybuilder() + elif section == 'buildposts': + context = {'message': 'Writing Posts to Disk'} + posts_builder() else: options[section]().build() context = {'message': 'Writing %s to Disk' % section} diff --git a/app/guides/__init__.py b/app/guides/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/guides/admin.py b/app/guides/admin.py deleted file mode 100644 index 7895aba..0000000 --- a/app/guides/admin.py +++ /dev/null @@ -1,67 +0,0 @@ -from django.contrib import admin -from django.contrib.gis.admin import OSMGeoAdmin - -from utils.widgets import LGEntryForm -from utils.util import get_latlon - -from .models import Guide - - -@admin.register(Guide) -class GuideAdmin(OSMGeoAdmin): - form = LGEntryForm - list_display = ('title', 'pub_date', 'enable_comments', 'status', 'post_type') - list_filter = ('pub_date', 'enable_comments', 'status') - prepopulated_fields = {"slug": ('title',)} - fieldsets = ( - ('Entry', { - 'fields': ( - 'title', - 'sub_title', - 'body_markdown', - ('pub_date', 'status', 'post_type', 'disclaimer'), - 'meta_description', - 'featured_image', - 'dek', - 'tags', - 'prologue_markdown', - 'epilogue_markdown', - 'has_video', - ('slug', 'enable_comments'), - 'point', - ), - 'classes': ( - 'show', - 'extrapretty', - 'wide' - ) - }), - ('meta', { - 'fields': ( - ('field_notes', 'books','jrnl'), - ), - 'classes': ( - 'hide', - 'extrapretty', - 'wide' - ) - }), - ) - - # options for OSM map Using custom ESRI topo map - lat, lon = get_latlon() - default_lon = lon - default_lat = lat - default_zoom = 10 - units = True - scrollable = False - map_width = 700 - map_height = 425 - map_template = 'gis/admin/osm.html' - openlayers_url = '/static/admin/js/OpenLayers.js' - - class Media: - js = ('image-loader.js', 'next-prev-links.js') - css = { - "all": ("my_styles.css",) - } diff --git a/app/guides/build.py b/app/guides/build.py deleted file mode 100644 index 392e991..0000000 --- a/app/guides/build.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -from builder.base import BuildNew -from django.urls import reverse -from . import models - - -class BuildEssays(BuildNew): - - def build(self): - self.build_list_view() - self.build_detail_view() - # These are the unique classes for this model: - #self.build_feed("src:feed") - - def build_list_view(self): - response = self.client.get('/essays/') - self.write_file('essays/', response.content) - - -def essaybuilder(): - j = BuildEssays("essays", "essay") - j.build() diff --git a/app/guides/guide_urls.py b/app/guides/guide_urls.py deleted file mode 100644 index ad67061..0000000 --- a/app/guides/guide_urls.py +++ /dev/null @@ -1,18 +0,0 @@ -from django.urls import path, re_path - -from . import views - -app_name = "guide" - -urlpatterns = [ - path( - r'', - views.GuideDetailView.as_view(), - name="guide-detail" - ), - path( - r'.txt', - views.GuideDetailViewTXT.as_view(), - name="guide-detail-txt" - ), -] diff --git a/app/guides/migrations/0001_initial.py b/app/guides/migrations/0001_initial.py deleted file mode 100644 index 833dfbe..0000000 --- a/app/guides/migrations/0001_initial.py +++ /dev/null @@ -1,60 +0,0 @@ -# Generated by Django 2.1.7 on 2019-07-04 09:03 - -import django.contrib.gis.db.models.fields -from django.db import migrations, models -import django.db.models.deletion -import taggit.managers - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('jrnl', '0043_auto_20190704_0903'), - ('books', '0009_book_afflink'), - ('photos', '0019_auto_20190704_0903'), - ('fieldnotes', '0002_auto_20190303_1222'), - ('locations', '0018_auto_20190414_2124'), - ('essays', '0010_essay_field_notes'), - ('taxonomy', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='Guide', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=200)), - ('sub_title', models.CharField(blank=True, max_length=200)), - ('dek', models.TextField(blank=True)), - ('preamble_markdown', models.TextField(blank=True)), - ('preamble_html', models.TextField(blank=True)), - ('slug', models.SlugField(unique_for_date='pub_date')), - ('body_html', models.TextField(blank=True)), - ('body_markdown', models.TextField()), - ('pub_date', models.DateTimeField(verbose_name='Date published')), - ('last_updated', models.DateTimeField(auto_now=True)), - ('enable_comments', models.BooleanField(default=False)), - ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), - ('meta_description', models.CharField(blank=True, max_length=256, null=True)), - ('has_video', models.BooleanField(blank=True, default=False)), - ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), - ('afterword', models.TextField(blank=True)), - ('afterword_html', models.TextField(blank=True)), - ('books', models.ManyToManyField(blank=True, to='books.Book')), - ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='taxonomy.Category')), - ('essays', models.ManyToManyField(blank=True, to='essays.Essay')), - ('featured_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage')), - ('field_notes', models.ManyToManyField(blank=True, to='fieldnotes.FieldNote')), - ('jrnl', models.ManyToManyField(blank=True, to='jrnl.Entry')), - ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), - ('tags', taggit.managers.TaggableManager(blank=True, help_text='Topics Covered', through='taxonomy.TaggedItems', to='taxonomy.LuxTag', verbose_name='Tags')), - ], - options={ - 'verbose_name_plural': 'Guides', - 'ordering': ('-pub_date',), - 'get_latest_by': 'pub_date', - }, - ), - ] diff --git a/app/guides/migrations/0002_remove_guide_category.py b/app/guides/migrations/0002_remove_guide_category.py deleted file mode 100644 index 76eefa6..0000000 --- a/app/guides/migrations/0002_remove_guide_category.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.1.7 on 2019-07-04 12:05 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('guides', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='guide', - name='category', - ), - ] diff --git a/app/guides/migrations/0003_guide_category.py b/app/guides/migrations/0003_guide_category.py deleted file mode 100644 index 82d03ac..0000000 --- a/app/guides/migrations/0003_guide_category.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 2.1.7 on 2019-09-08 17:45 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('taxonomy', '0001_initial'), - ('guides', '0002_remove_guide_category'), - ] - - operations = [ - migrations.AddField( - model_name='guide', - name='category', - field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='taxonomy.Category'), - preserve_default=False, - ), - ] diff --git a/app/guides/migrations/0004_auto_20190914_0646.py b/app/guides/migrations/0004_auto_20190914_0646.py deleted file mode 100644 index ccd79a5..0000000 --- a/app/guides/migrations/0004_auto_20190914_0646.py +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Django 2.1.7 on 2019-09-14 06:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('guides', '0003_guide_category'), - ] - - operations = [ - migrations.RenameField( - model_name='guide', - old_name='afterword', - new_name='epilogue_html', - ), - migrations.RenameField( - model_name='guide', - old_name='afterword_html', - new_name='epilogue_markdown', - ), - migrations.RenameField( - model_name='guide', - old_name='preamble_html', - new_name='prologue_html', - ), - migrations.RenameField( - model_name='guide', - old_name='preamble_markdown', - new_name='prologue_markdown', - ), - migrations.RemoveField( - model_name='guide', - name='essays', - ), - migrations.AddField( - model_name='guide', - name='disclaimer', - field=models.BooleanField(blank=True, default=False), - ), - migrations.AddField( - model_name='guide', - name='post_type', - field=models.IntegerField(choices=[(0, 'guide'), (1, 'review')], default=0), - ), - ] diff --git a/app/guides/migrations/0005_remove_guide_category.py b/app/guides/migrations/0005_remove_guide_category.py deleted file mode 100644 index 71d0280..0000000 --- a/app/guides/migrations/0005_remove_guide_category.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.1.7 on 2019-09-14 07:08 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('guides', '0004_auto_20190914_0646'), - ] - - operations = [ - migrations.RemoveField( - model_name='guide', - name='category', - ), - ] diff --git a/app/guides/migrations/__init__.py b/app/guides/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/guides/models.py b/app/guides/models.py deleted file mode 100644 index 8704887..0000000 --- a/app/guides/models.py +++ /dev/null @@ -1,136 +0,0 @@ -from django.contrib.gis.db import models -from django.urls import reverse -from django.contrib.sitemaps import Sitemap -import datetime -from itertools import chain - -from taggit.managers import TaggableManager - -from taxonomy.models import TaggedItems, Category -from utils.util import render_images, markdown_to_html -from fieldnotes.models import FieldNote -from books.models import Book -from locations.models import Location -from photos.models import LuxImage -from essays.models import Essay -from jrnl.models import Entry - - -class Guide(models.Model): - title = models.CharField(max_length=200) - sub_title = models.CharField(max_length=200, blank=True) - dek = models.TextField(blank=True) - prologue_markdown = models.TextField(blank=True) - prologue_html = models.TextField(blank=True) - body_markdown = models.TextField() - body_html = models.TextField(blank=True) - epilogue_markdown = models.TextField(blank=True) - epilogue_html = models.TextField(blank=True) - slug = models.SlugField(unique_for_date='pub_date') - pub_date = models.DateTimeField('Date published') - last_updated = models.DateTimeField(auto_now=True) - enable_comments = models.BooleanField(default=False) - PUB_STATUS = ( - (0, 'Draft'), - (1, 'Published'), - ) - status = models.IntegerField(choices=PUB_STATUS, default=0) - POST_TYPE = ( - (0, 'guide'), - (1, 'review'), - ) - post_type = models.IntegerField(choices=POST_TYPE, default=0) - meta_description = models.CharField(max_length=256, null=True, blank=True) - tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') - featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) - point = models.PointField(null=True, blank=True) - location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True) - has_video = models.BooleanField(blank=True, default=False) - disclaimer = models.BooleanField(blank=True, default=False) - field_notes = models.ManyToManyField(FieldNote, blank=True) - books = models.ManyToManyField(Book, blank=True) - jrnl = models.ManyToManyField(Entry, blank=True) - - class Meta: - ordering = ('-pub_date',) - get_latest_by = 'pub_date' - verbose_name_plural = 'Guides' - - def __str__(self): - return self.title - - def get_absolute_url(self): - if self.post_type == 0: - return reverse('guide:guide-detail', kwargs={"slug": self.slug}) - if self.post_type == 1: - return reverse('review:review-detail', kwargs={"slug": self.slug}) - - def comment_period_open(self): - return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date - - @property - def get_previous_published(self): - return self.get_previous_by_pub_date(status__exact=1) - - @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_published(self): - return self.get_next_by_pub_date(status__exact=1) - - @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 '' - - @property - def longitude(self): - '''Get the site's longitude.''' - return self.point.x - - @property - def latitude(self): - '''Get the site's latitude.''' - return self.point.y - - def save(self, *args, **kwargs): - created = self.pk is None - if not created: - md = render_images(self.body_markdown) - self.body_html = markdown_to_html(md) - self.prologue_html = markdown_to_html(self.prologue_markdown) - self.epilogue_html = markdown_to_html(self.epilogue_markdown) - self.has_video = parse_video(self.body_html) - if self.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 created and not self.featured_image: - self.featured_image = LuxImage.objects.latest() - old = type(self).objects.get(pk=self.pk) if self.pk else None - if old and old.featured_image != self.featured_image: # Field has changed - s = LuxImageSize.objects.get(name="featured_jrnl") - ss = LuxImageSize.objects.get(name="picwide-med") - self.featured_image.sizes.add(s) - self.featured_image.sizes.add(ss) - self.featured_image.save() - super(Guide, self).save(*args, **kwargs) - - -class GuideSitemap(Sitemap): - changefreq = "never" - priority = 1.0 - protocol = "https" - - def items(self): - return Guide.objects.filter(status=1) - - def lastmod(self, obj): - return obj.pub_date diff --git a/app/guides/review_urls.py b/app/guides/review_urls.py deleted file mode 100644 index 7048065..0000000 --- a/app/guides/review_urls.py +++ /dev/null @@ -1,18 +0,0 @@ -from django.urls import path, re_path - -from . import views - -app_name = "review" - -urlpatterns = [ - path( - r'', - views.GuideDetailView.as_view(), - name="review-detail" - ), - path( - r'.txt', - views.GuideDetailViewTXT.as_view(), - name="review-detail-txt" - ), -] diff --git a/app/guides/templates/guides/guide_detail.html b/app/guides/templates/guides/guide_detail.html deleted file mode 100644 index 1ef602a..0000000 --- a/app/guides/templates/guides/guide_detail.html +++ /dev/null @@ -1,176 +0,0 @@ -{% 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 %} - - - - - - - - - - - - - - - {% if object.featured_image %} - {%endif%} - -{%endblock%} - -{%block bodyid %}{% if object.get_post_type_display == 'tools' %}class="src"{% endif %}{%endblock%} - -{% block primary %} -
-
-
-

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

-

{{object.sub_title|smartypants|safe}}

-
- {% if object.originally_published_by %}

Originally Published By: {{object.originally_published_by}}

{%endif%} - {% if object.location %}
-

{% if object.location.country_name == "United States" %}{{object.location.name|smartypants|safe}}, {{object.location.state_name|safe}}, U.S.{%else%}{{object.location.name|smartypants|safe}}, {{object.location.country_name|safe}}{%endif%}

- – Map -
{%endif%} - - -
-
-
- {% if object.preamble %}
- {{object.preamble_html|smartypants|safe}} -
{%endif%} - {{object.body_html|safe|smartypants}} -
- {% if object.afterword_html %}
-

Afterward

- {{object.afterword_html|smartypants|safe}} -
{%endif%} - {%if wildlife or object.field_notes.all or object.books.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 %} - -{%endblock%} diff --git a/app/guides/templates/guides/guide_detail.txt b/app/guides/templates/guides/guide_detail.txt deleted file mode 100644 index 547ce79..0000000 --- a/app/guides/templates/guides/guide_detail.txt +++ /dev/null @@ -1,8 +0,0 @@ -{{object.title|safe}} -{% for letter in object.title %}={%endfor%} - - by Scott Gilbertson - <{{SITE_URL}}{{object.get_absolute_url}}> - {{object.pub_date|date:"l, d F Y"}} - -{{object.body_markdown|safe}} diff --git a/app/guides/templates/guides/guide_list.html b/app/guides/templates/guides/guide_list.html deleted file mode 100644 index a264a11..0000000 --- a/app/guides/templates/guides/guide_list.html +++ /dev/null @@ -1,40 +0,0 @@ -{% extends 'base.html' %} -{% load typogrify_tags %} -{% load html5_datetime %} -{% load pagination_tags %} -{% block pagetitle %}Guides for the Perplexed{% endblock %} -{% block metadescription %}Guides for fellow travelers: tools, tips, and tricks to make life on the road easier.{% endblock %} - -{% block primary %} -
-
-

Guides for fellow travelers

-

The less stuff you travel with the better off you will be, up to a point. But where is that point? What's enough? What's too much? That point is what I'm trying to discover here.

-

What do you really need? What's worth having? What's not?

-

Topics include {% for topic in topic_list %}{{topic}}, {% endfor %}travel, cooking, photography, writing, simplicity, and once, coffee.

-
-

Guides

- {% autopaginate object_list 30 %} - -
-{%endblock%} diff --git a/app/guides/urls.py b/app/guides/urls.py deleted file mode 100644 index c91a5b5..0000000 --- a/app/guides/urls.py +++ /dev/null @@ -1,34 +0,0 @@ -from django.urls import path, re_path - -from . import views - -app_name = "guides" - -urlpatterns = [ - path( - r'', - views.GuideListView.as_view(), - {'page': 1}, - name="list" - ), - path( - r'/', - views.GuideListView.as_view(), - name="list" - ), - path( - r'/', - views.GuideDetailView.as_view(), - name="detail" - ), - path( - r'/', - views.GuideDetailViewTXT.as_view(), - name="detail-txt" - ), - path( - r'', - views.GuideCatListView.as_view(), - name="list-cat" - ), -] diff --git a/app/guides/views.py b/app/guides/views.py deleted file mode 100644 index 01dc974..0000000 --- a/app/guides/views.py +++ /dev/null @@ -1,62 +0,0 @@ -from django.views.generic import ListView -from django.views.generic.detail import DetailView -from django.contrib.syndication.views import Feed - -from utils.views import PaginatedListView - -from .models import Guide - - -class GuideListView(PaginatedListView): - model = Guide - - def get_queryset(self, **kwargs): - qs = Guide.objects.filter(status=1) - return qs - - def get_context_data(self, **kwargs): - # Call the base implementation first to get a context - context = super(GuideListView, self).get_context_data(**kwargs) - context['topic_list'] = Guide.tags.all() - return context - - -class GuideCatListView(GuideListView): - model = Guide - - def get_queryset(self, **kwargs): - cat = Category.objects.get(slug=self.kwargs['slug']) - qs = Guide.objects.filter(status=1, tags=cat) - return qs - -class GuideDetailView(DetailView): - model = Guide - - -class GuideDetailViewTXT(GuideDetailView): - template_name = "essays/entry_detail.txt" - - -''' -class TopicListView(ListView): - template_name = 'archives/src_home.html' - - def queryset(self): - return Post.objects.filter(topics__slug=self.kwargs['slug']) - - def get_context_data(self, **kwargs): - # Call the base implementation first to get a context - context = super(TopicListView, self).get_context_data(**kwargs) - context['topic'] = Topic.objects.get(slug__exact=self.kwargs['slug']) - return context - - -class SrcRSSFeedView(Feed): - title = "luxagraf:src Code and Technology" - link = "/src/" - description = "Latest postings to luxagraf.net/src" - description_template = 'feeds/blog_description.html' - - def items(self): - return Post.objects.filter(status__exact=1).order_by('-pub_date')[:10] -''' diff --git a/app/jrnl/admin.py b/app/jrnl/admin.py index d800f34..78a2630 100644 --- a/app/jrnl/admin.py +++ b/app/jrnl/admin.py @@ -4,16 +4,16 @@ from django.contrib.gis.admin import OSMGeoAdmin from django.contrib.contenttypes.admin import GenericStackedInline from utils.widgets import AdminImageWidget, LGEntryForm -from .models import Entry, HomepageCurrator, Home, RelatedPost +from .models import Entry, HomepageCurrator, Home #, RelatedPost from photos.forms import GalleryForm from photos.models import LuxImage from utils.util import get_latlon -@admin.register(RelatedPost) -class RelatedPostAdmin(admin.ModelAdmin): - pass +#@admin.register(RelatedPost) +#class RelatedPostAdmin(admin.ModelAdmin): +# pass @admin.register(Entry) diff --git a/app/jrnl/migrations/0044_auto_20190917_1703.py b/app/jrnl/migrations/0044_auto_20190917_1703.py new file mode 100644 index 0000000..c6e5d6c --- /dev/null +++ b/app/jrnl/migrations/0044_auto_20190917_1703.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-09-17 17:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('jrnl', '0043_auto_20190704_0903'), + ] + + operations = [ + migrations.RenameModel( + old_name='RelatedPost', + new_name='OldRelatedPost', + ), + ] diff --git a/app/jrnl/models.py b/app/jrnl/models.py index a88e79a..8e8e606 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -3,6 +3,7 @@ import os from django.dispatch import receiver from django.contrib.gis.db import models +from django.db.models.signals import post_save from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.urls import reverse @@ -24,6 +25,7 @@ from photos.models import PhotoGallery, LuxImage, LuxImageSize from locations.models import Location from books.models import Book from fieldnotes.models import FieldNote +from normalize.models import RelatedPost from utils.util import render_images, parse_video, markdown_to_html @@ -37,7 +39,7 @@ def image_url_replace(s): return s -class RelatedPost(models.Model): +class OldRelatedPost(models.Model): post_model = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL) slug = models.SlugField() @@ -77,7 +79,7 @@ class Entry(models.Model): has_video = models.BooleanField(blank=True, default=False) field_notes = models.ManyToManyField(FieldNote, blank=True) books = models.ManyToManyField(Book, blank=True) - related = models.ManyToManyField(RelatedPost, blank=True) + related = models.ManyToManyField(OldRelatedPost, blank=True) class Meta: ordering = ('-pub_date',) @@ -174,6 +176,9 @@ class Entry(models.Model): def get_image_ext(self): return self.image.url[-3:] + def get_content_type(self): + return ContentType.objects.get(app_label="jrnl", model="entry") + def save(self, *args, **kwargs): created = self.pk is None if not created: @@ -266,6 +271,16 @@ def cache_gravatar(sender, comment, **kwargs): local_grav = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) 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) + # from django_comments.signals import comment_will_be_posted # from django_comments import akismet diff --git a/app/normalize/__init__.py b/app/normalize/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/normalize/migrations/0001_initial.py b/app/normalize/migrations/0001_initial.py new file mode 100644 index 0000000..8dda080 --- /dev/null +++ b/app/normalize/migrations/0001_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 2.1.7 on 2019-09-17 17:54 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ] + + operations = [ + migrations.CreateModel( + name='RelatedPost', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('entry_id', models.IntegerField()), + ('title', models.CharField(max_length=200)), + ('slug', models.CharField(max_length=50)), + ('model_name', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='contenttypes.ContentType')), + ], + ), + ] diff --git a/app/normalize/migrations/__init__.py b/app/normalize/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/normalize/models.py b/app/normalize/models.py new file mode 100644 index 0000000..ac36512 --- /dev/null +++ b/app/normalize/models.py @@ -0,0 +1,12 @@ +from django.db import models +from django.contrib.contenttypes.models import ContentType + + +class RelatedPost(models.Model): + model_name = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL) + entry_id = models.IntegerField() + title = models.CharField(max_length=200) + slug = models.CharField(max_length=50) + + def __str__(self): + return self.title diff --git a/app/posts/__init__.py b/app/posts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/posts/admin.py b/app/posts/admin.py new file mode 100644 index 0000000..ad8f509 --- /dev/null +++ b/app/posts/admin.py @@ -0,0 +1,103 @@ +from django.contrib import admin +from django import forms +from django.contrib.gis.admin import OSMGeoAdmin +from django.contrib.contenttypes.admin import GenericStackedInline + +from utils.widgets import AdminImageWidget, LGEntryForm +from .models import Post + +from photos.forms import GalleryForm +from photos.models import LuxImage +from utils.util import get_latlon + + +@admin.register(Post) +class EntryAdmin(OSMGeoAdmin): + form = LGEntryForm + + def get_queryset(self, request): + test_model_qs = super(EntryAdmin, self).get_queryset(request) + test_model_qs = test_model_qs.prefetch_related('related').prefetch_related('books') + + return test_model_qs + + def render_change_form(self, request, context, *args, **kwargs): + #context['adminform'].form.fields['featured_image'].queryset = LuxImage.objects.all()[:200] + return super(EntryAdmin, self).render_change_form(request, context, *args, **kwargs) + + def formfield_for_dbfield(self, db_field, **kwargs): + if db_field.name == 'thumbnail' or db_field.name == 'image': + field = forms.FileField(widget=AdminImageWidget) + elif db_field.name == 'meta_description': + field = forms.CharField(widget=forms.Textarea(attrs={'rows': 4, 'cols': 75})) + field.required = False + else: + field = super(EntryAdmin, self).formfield_for_dbfield(db_field, **kwargs) + return field + + list_display = ('title', 'post_type', 'pub_date', 'template_name', 'status', 'category') + search_fields = ['title', 'body_markdown'] + prepopulated_fields = {"slug": ('title',)} + list_filter = ('pub_date', 'enable_comments', 'status', 'category') + filter_horizontal = ('related',) + fieldsets = ( + ('Entry', { + 'fields': ( + 'title', + 'subtitle', + 'body_markdown', + ('pub_date', 'status', 'post_type', 'old_id',), + 'slug', + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ('Metadata', { + 'fields': ( + 'point', + 'dek', + 'meta_description', + ('category', 'tags'), + 'template_name', + 'enable_comments', + 'featured_image', + 'related', + ('has_video', 'disclaimer',), + ), + }), + ('Extras', { + 'fields': ( + 'books', + 'field_notes', + 'jrnl', + 'prologue_markdown', + 'epilogue_markdown', + 'originally_published_by', + 'originally_published_by_url', + ), + }), + ) + # options for OSM map Using custom ESRI topo map + lat, lon = get_latlon() + default_lon = lon + default_lat = lat + default_zoom = 10 + units = True + scrollable = False + map_width = 700 + map_height = 425 + map_template = 'gis/admin/osm.html' + openlayers_url = '/static/admin/js/OpenLayers.js' + + class Media: + js = ('image-loader.js', 'next-prev-links.js') + css = { + "all": ("my_styles.css",) + } + + + diff --git a/app/posts/build.py b/app/posts/build.py new file mode 100644 index 0000000..5cf552b --- /dev/null +++ b/app/posts/build.py @@ -0,0 +1,27 @@ +from django.urls import reverse +from django.apps import apps +from builder.base import BuildNew +from itertools import chain + +from django.conf import settings + + +class BuildPosts(BuildNew): + + def build(self): + self.build_list_view( + base_path=reverse("essay-list:list"), + paginate_by=50 + ) + self.build_list_view( + base_path=reverse("guide-list:list"), + paginate_by=50 + ) + self.build_detail_view() + + + + +def posts_builder(): + j = BuildPosts("posts", "post") + j.build() diff --git a/app/posts/essay_urls.py b/app/posts/essay_urls.py new file mode 100644 index 0000000..ea7777d --- /dev/null +++ b/app/posts/essay_urls.py @@ -0,0 +1,29 @@ +from django.urls import path, re_path + +from . import views + +app_name = "essays" + +urlpatterns = [ + path( + r'', + views.PostDetailView.as_view(), + name="detail" + ), + path( + r'.txt', + views.PostDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'/', + views.EssayListView.as_view(), + name="list" + ), + path( + r'', + views.EssayListView.as_view(), + {'page':1}, + name="list" + ), +] diff --git a/app/posts/guide_urls.py b/app/posts/guide_urls.py new file mode 100644 index 0000000..d43d76a --- /dev/null +++ b/app/posts/guide_urls.py @@ -0,0 +1,29 @@ +from django.urls import path, re_path + +from . import views + +app_name = "guides" + +urlpatterns = [ + path( + r'', + views.PostDetailView.as_view(), + name="detail" + ), + path( + r'.txt', + views.PostDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'/', + views.GuidesListView.as_view(), + name="list" + ), + path( + r'', + views.GuidesListView.as_view(), + {'page':1}, + name="list" + ), +] diff --git a/app/posts/importer.py b/app/posts/importer.py new file mode 100644 index 0000000..53a84aa --- /dev/null +++ b/app/posts/importer.py @@ -0,0 +1,29 @@ +for e in essaysold: + if e.featured_image: + feat = e.featured_image + else: + feat = None + if e.meta_description: + meta = e.meta_description + else: + meta = "need meta" + new, created = Post.objects.get_or_create( + old_id=e.pk, + post_type=2, + title=e.title, + subtitle=e.sub_title, + dek=e.dek, + slug=e.slug, + prologue_markdown=e.preamble, + body_markdown=e.body_markdown, + pub_date=e.pub_date, + enable_comments=e.enable_comments, + status=e.status, + meta_description=meta, + originally_published_by=e.originally_published_by, + originally_published_by_url=e.originally_published_by_url, + featured_image=feat, + has_video=e.has_video, + epilogue_markdown=e.afterword, + ) + print(created) diff --git a/app/posts/migrations/0001_initial.py b/app/posts/migrations/0001_initial.py new file mode 100644 index 0000000..e853a06 --- /dev/null +++ b/app/posts/migrations/0001_initial.py @@ -0,0 +1,65 @@ +# Generated by Django 2.1.7 on 2019-09-17 17:53 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion +import taggit.managers + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('jrnl', '0044_auto_20190917_1703'), + ('books', '0009_book_afflink'), + ('normalize', '__first__'), + ('taxonomy', '0001_initial'), + ('locations', '0018_auto_20190414_2124'), + ('fieldnotes', '0002_auto_20190303_1222'), + ('photos', '0019_auto_20190704_0903'), + ] + + operations = [ + migrations.CreateModel( + name='Post', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('subtitle', models.CharField(blank=True, max_length=200)), + ('slug', models.SlugField(unique_for_date='pub_date')), + ('prologue_markdown', models.TextField(blank=True)), + ('prologue_html', models.TextField(blank=True)), + ('body_markdown', models.TextField()), + ('body_html', models.TextField(blank=True)), + ('epilogue_markdown', models.TextField(blank=True)), + ('epilogue_html', models.TextField(blank=True)), + ('dek', models.TextField(blank=True, null=True)), + ('meta_description', models.CharField(blank=True, max_length=256, null=True)), + ('pub_date', models.DateTimeField(verbose_name='Date published')), + ('last_updated', models.DateTimeField(auto_now=True)), + ('enable_comments', models.BooleanField(default=False)), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), + ('post_type', models.IntegerField(choices=[(0, 'guide'), (1, 'review'), (2, 'essay')], default=0)), + ('template_name', models.IntegerField(choices=[(0, 'single')], default=0)), + ('has_video', models.BooleanField(blank=True, default=False)), + ('disclaimer', models.BooleanField(blank=True, default=True)), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), + ('originally_published_by', models.CharField(blank=True, max_length=400)), + ('originally_published_by_url', models.CharField(blank=True, max_length=400)), + ('books', models.ManyToManyField(blank=True, to='books.Book')), + ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='taxonomy.Category')), + ('featured_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage')), + ('field_notes', models.ManyToManyField(blank=True, to='fieldnotes.FieldNote')), + ('jrnl', models.ManyToManyField(blank=True, to='jrnl.Entry')), + ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ('related', models.ManyToManyField(blank=True, to='normalize.RelatedPost')), + ('tags', taggit.managers.TaggableManager(blank=True, help_text='Topics Covered', through='taxonomy.TaggedItems', to='taxonomy.LuxTag', verbose_name='Tags')), + ], + options={ + 'ordering': ('-pub_date',), + 'get_latest_by': 'pub_date', + 'verbose_name_plural': 'entries', + }, + ), + ] diff --git a/app/posts/migrations/0002_auto_20190917_2029.py b/app/posts/migrations/0002_auto_20190917_2029.py new file mode 100644 index 0000000..c6f77eb --- /dev/null +++ b/app/posts/migrations/0002_auto_20190917_2029.py @@ -0,0 +1,22 @@ +# Generated by Django 2.1.7 on 2019-09-17 20:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='post', + options={'get_latest_by': 'pub_date', 'ordering': ('-pub_date',)}, + ), + migrations.AddField( + model_name='post', + name='old_id', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/app/posts/migrations/0003_auto_20190918_1230.py b/app/posts/migrations/0003_auto_20190918_1230.py new file mode 100644 index 0000000..d7c89a8 --- /dev/null +++ b/app/posts/migrations/0003_auto_20190918_1230.py @@ -0,0 +1,54 @@ +# Generated by Django 2.1.7 on 2019-09-18 12:30 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0002_auto_20190917_2029'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='epilogue_html', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='post', + name='epilogue_markdown', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='post', + name='featured_image', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage'), + ), + migrations.AlterField( + model_name='post', + name='meta_description', + field=models.CharField(blank=True, max_length=256), + ), + migrations.AlterField( + model_name='post', + name='originally_published_by', + field=models.CharField(blank=True, max_length=400, null=True), + ), + migrations.AlterField( + model_name='post', + name='originally_published_by_url', + field=models.CharField(blank=True, max_length=400, null=True), + ), + migrations.AlterField( + model_name='post', + name='prologue_html', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='post', + name='prologue_markdown', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/app/posts/migrations/0004_auto_20190918_1241.py b/app/posts/migrations/0004_auto_20190918_1241.py new file mode 100644 index 0000000..da829ad --- /dev/null +++ b/app/posts/migrations/0004_auto_20190918_1241.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.7 on 2019-09-18 12:41 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0003_auto_20190918_1230'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='featured_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage'), + ), + ] diff --git a/app/posts/migrations/0005_auto_20190918_1244.py b/app/posts/migrations/0005_auto_20190918_1244.py new file mode 100644 index 0000000..0cc59a8 --- /dev/null +++ b/app/posts/migrations/0005_auto_20190918_1244.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.7 on 2019-09-18 12:44 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('posts', '0004_auto_20190918_1241'), + ] + + operations = [ + migrations.AlterField( + model_name='post', + name='category', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='taxonomy.Category'), + ), + ] diff --git a/app/posts/migrations/__init__.py b/app/posts/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/posts/models.py b/app/posts/models.py new file mode 100644 index 0000000..1e1da1e --- /dev/null +++ b/app/posts/models.py @@ -0,0 +1,200 @@ +import datetime +import os + +from django.dispatch import receiver +from django.contrib.gis.db import models +from django.db.models.signals import post_save +from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey +from django.contrib.contenttypes.models import ContentType +from django.urls import reverse +from django.utils.functional import cached_property +from django.apps import apps +from django.conf import settings +from django.contrib.sitemaps import Sitemap +from django import forms + +import urllib.request +import urllib.parse +import urllib.error +from django_gravatar.helpers import get_gravatar_url, has_gravatar, calculate_gravatar_hash +from django_comments.signals import comment_was_posted +from django_comments.models import Comment +from django_comments.moderation import CommentModerator, moderator + +from taggit.managers import TaggableManager + +from normalize.models import RelatedPost +from photos.models import LuxImage, LuxImageSize +from locations.models import Location +from books.models import Book +from fieldnotes.models import FieldNote +from taxonomy.models import TaggedItems, Category +from jrnl.models import Entry +from utils.util import render_images, parse_video, markdown_to_html + + +class Post(models.Model): + old_id = models.IntegerField(blank=True, null=True) + title = models.CharField(max_length=200) + subtitle = models.CharField(max_length=200, blank=True) + slug = models.SlugField(unique_for_date='pub_date') + prologue_markdown = models.TextField(blank=True, null=True) + prologue_html = models.TextField(blank=True, null=True) + body_markdown = models.TextField() + body_html = models.TextField(blank=True) + epilogue_markdown = models.TextField(blank=True, null=True) + epilogue_html = models.TextField(blank=True, null=True) + dek = models.TextField(null=True, blank=True) + meta_description = models.CharField(max_length=256, blank=True) + pub_date = models.DateTimeField('Date published') + last_updated = models.DateTimeField(auto_now=True) + enable_comments = models.BooleanField(default=False) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) + TEMPLATES = ( + (0, 'single'), + ) + POST_TYPE = ( + (0, 'guide'), + (1, 'review'), + (2, 'essay'), + ) + post_type = models.IntegerField(choices=POST_TYPE, default=0) + template_name = models.IntegerField(choices=TEMPLATES, default=0) + has_video = models.BooleanField(blank=True, default=False) + disclaimer = models.BooleanField(blank=True, default=True) + books = models.ManyToManyField(Book, blank=True) + field_notes = models.ManyToManyField(FieldNote, blank=True) + related = models.ManyToManyField(RelatedPost, blank=True) + tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') + category = models.ForeignKey(Category, on_delete=models.CASCADE, null=True, blank=True) + point = models.PointField(null=True, blank=True) + location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True) + originally_published_by = models.CharField(max_length=400, null=True, blank=True) + originally_published_by_url = models.CharField(max_length=400, null=True, blank=True) + field_notes = models.ManyToManyField(FieldNote, blank=True) + books = models.ManyToManyField(Book, blank=True) + jrnl = models.ManyToManyField(Entry, blank=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + + def __str__(self): + return self.title + + def get_absolute_url(self): + if self.post_type == 0: + return reverse('guides:detail', kwargs={"slug": self.slug}) + if self.post_type == 1: + return reverse('reviews:detail', kwargs={"slug": self.slug}) + if self.post_type == 2: + return reverse('essays:detail', kwargs={"slug": self.slug}) + + def comment_period_open(self): + return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date + + def get_featured_image_thumb(self): + return self.featured_image.get_image_by_size("tn") + + def get_content_type(self): + return ContentType.objects.get(app_label="posts", model="post") + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @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_published(self): + return self.get_next_by_pub_date(status__exact=1) + + @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 '' + + @property + def longitude(self): + '''Get the site's longitude.''' + return self.point.x + + @property + def latitude(self): + '''Get the site's latitude.''' + return self.point.y + + def save(self, *args, **kwargs): + created = self.pk is None + if not created: + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) + self.epilogue_html = markdown_to_html(self.epilogue_markdown) + self.prologue_html = markdown_to_html(self.prologue_markdown) + self.has_video = parse_video(self.body_html) + if self.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 created and not self.featured_image: + self.featured_image = LuxImage.objects.latest() + old = type(self).objects.get(pk=self.pk) if self.pk else None + if old and old.featured_image != self.featured_image: # Field has changed + s = LuxImageSize.objects.get(name="featured_jrnl") + ss = LuxImageSize.objects.get(name="picwide-med") + self.featured_image.sizes.add(s) + self.featured_image.sizes.add(ss) + self.featured_image.save() + super(Post, self).save(*args, **kwargs) + + +class PostModerator(CommentModerator): + ''' + Moderate everything except people with multiple approvals + ''' + email_notification = True + + def moderate(self, comment, content_object, request): + previous_approvals = Comment.objects.filter(user_email=comment.email, is_public=True) + for approval in previous_approvals: + if approval.submit_date <= datetime.datetime.today() - datetime.timedelta(21): + approve = True + if previous_approvals.count() > 2 and approve: + return False + # do entry build right here so it goes to live site + return True +moderator.register(Post, PostModerator) + + +@receiver(comment_was_posted, sender=Comment) +def cache_gravatar(sender, comment, **kwargs): + gravatar_exists = has_gravatar(comment.email) + grav_dir = settings.IMAGES_ROOT + '/gravcache/' + if gravatar_exists: + url = get_gravatar_url(comment.email, size=60) + if not os.path.isdir(grav_dir): + os.makedirs(grav_dir) + local_grav = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) + urllib.request.urlretrieve(url, local_grav) + + +@receiver(post_save, sender=Post) +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=Post) + instance.save() + post_save.connect(post_save_events, sender=Post) diff --git a/app/posts/review_urls.py b/app/posts/review_urls.py new file mode 100644 index 0000000..f6a3908 --- /dev/null +++ b/app/posts/review_urls.py @@ -0,0 +1,29 @@ +from django.urls import path, re_path + +from . import views + +app_name = "reviews" + +urlpatterns = [ + path( + r'', + views.PostDetailView.as_view(), + name="review-detail" + ), + path( + r'.txt', + views.PostDetailViewTXT.as_view(), + name="review-detail-txt" + ), + path( + r'/', + views.GuidesListView.as_view(), + name="review-list" + ), + path( + r'', + views.GuidesListView.as_view(), + {'page':1}, + name="review-list" + ), +] diff --git a/app/posts/templates/horizontal_select.html b/app/posts/templates/horizontal_select.html new file mode 100644 index 0000000..61dcfd8 --- /dev/null +++ b/app/posts/templates/horizontal_select.html @@ -0,0 +1,17 @@ +{% with id=widget.attrs.id %} + + {% for group, options, index in widget.optgroups %} + {% if group %} +
  • {{ group }} + + {% endif %} + {% for option in options %} +
  • {% include option.template_name with widget=option %}
  • + {% endfor %} + {% if group %} + + + {% endif %} + {% endfor %} + +{% endwith %} diff --git a/app/posts/templates/posts/entry_detail.txt b/app/posts/templates/posts/entry_detail.txt new file mode 100644 index 0000000..547ce79 --- /dev/null +++ b/app/posts/templates/posts/entry_detail.txt @@ -0,0 +1,8 @@ +{{object.title|safe}} +{% for letter in object.title %}={%endfor%} + + by Scott Gilbertson + <{{SITE_URL}}{{object.get_absolute_url}}> + {{object.pub_date|date:"l, d F Y"}} + +{{object.body_markdown|safe}} diff --git a/app/posts/templates/posts/essay_detail.html b/app/posts/templates/posts/essay_detail.html new file mode 100644 index 0000000..1ef602a --- /dev/null +++ b/app/posts/templates/posts/essay_detail.html @@ -0,0 +1,176 @@ +{% 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 %} + + + + + + + + + + + + + + + {% if object.featured_image %} + {%endif%} + +{%endblock%} + +{%block bodyid %}{% if object.get_post_type_display == 'tools' %}class="src"{% endif %}{%endblock%} + +{% block primary %} +
    +
    +
    +

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

    +

    {{object.sub_title|smartypants|safe}}

    +
    + {% if object.originally_published_by %}

    Originally Published By: {{object.originally_published_by}}

    {%endif%} + {% if object.location %}
    +

    {% if object.location.country_name == "United States" %}{{object.location.name|smartypants|safe}}, {{object.location.state_name|safe}}, U.S.{%else%}{{object.location.name|smartypants|safe}}, {{object.location.country_name|safe}}{%endif%}

    + – Map +
    {%endif%} + + +
    +
    +
    + {% if object.preamble %}
    + {{object.preamble_html|smartypants|safe}} +
    {%endif%} + {{object.body_html|safe|smartypants}} +
    + {% if object.afterword_html %}
    +

    Afterward

    + {{object.afterword_html|smartypants|safe}} +
    {%endif%} + {%if wildlife or object.field_notes.all or object.books.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 %} + +{%endblock%} diff --git a/app/posts/templates/posts/essay_list.html b/app/posts/templates/posts/essay_list.html new file mode 100644 index 0000000..271f83f --- /dev/null +++ b/app/posts/templates/posts/essay_list.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} + +{% 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 %} +
    +
    +

    My various articles and essays collected in one spot.

    +

    Topics include travel, writing, photography, free software, culture, and once, Del Taco.

    +

    Many essays below were previously published in: WIRED, Budget Travel, Ars Technica, Longshot Magazine, The Cost of Paper and elsewhere.

    +
    +

    Essays

    + +
    +{%endblock%} diff --git a/app/posts/templates/posts/post_detail.html b/app/posts/templates/posts/post_detail.html new file mode 100644 index 0000000..1ef602a --- /dev/null +++ b/app/posts/templates/posts/post_detail.html @@ -0,0 +1,176 @@ +{% 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 %} + + + + + + + + + + + + + + + {% if object.featured_image %} + {%endif%} + +{%endblock%} + +{%block bodyid %}{% if object.get_post_type_display == 'tools' %}class="src"{% endif %}{%endblock%} + +{% block primary %} +
    +
    +
    +

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

    +

    {{object.sub_title|smartypants|safe}}

    +
    + {% if object.originally_published_by %}

    Originally Published By: {{object.originally_published_by}}

    {%endif%} + {% if object.location %}
    +

    {% if object.location.country_name == "United States" %}{{object.location.name|smartypants|safe}}, {{object.location.state_name|safe}}, U.S.{%else%}{{object.location.name|smartypants|safe}}, {{object.location.country_name|safe}}{%endif%}

    + – Map +
    {%endif%} + + +
    +
    +
    + {% if object.preamble %}
    + {{object.preamble_html|smartypants|safe}} +
    {%endif%} + {{object.body_html|safe|smartypants}} +
    + {% if object.afterword_html %}
    +

    Afterward

    + {{object.afterword_html|smartypants|safe}} +
    {%endif%} + {%if wildlife or object.field_notes.all or object.books.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 %} + +{%endblock%} diff --git a/app/posts/templates/posts/post_detail.txt b/app/posts/templates/posts/post_detail.txt new file mode 100644 index 0000000..547ce79 --- /dev/null +++ b/app/posts/templates/posts/post_detail.txt @@ -0,0 +1,8 @@ +{{object.title|safe}} +{% for letter in object.title %}={%endfor%} + + by Scott Gilbertson + <{{SITE_URL}}{{object.get_absolute_url}}> + {{object.pub_date|date:"l, d F Y"}} + +{{object.body_markdown|safe}} diff --git a/app/posts/templates/posts/post_list.html b/app/posts/templates/posts/post_list.html new file mode 100644 index 0000000..a264a11 --- /dev/null +++ b/app/posts/templates/posts/post_list.html @@ -0,0 +1,40 @@ +{% extends 'base.html' %} +{% load typogrify_tags %} +{% load html5_datetime %} +{% load pagination_tags %} +{% block pagetitle %}Guides for the Perplexed{% endblock %} +{% block metadescription %}Guides for fellow travelers: tools, tips, and tricks to make life on the road easier.{% endblock %} + +{% block primary %} +
    +
    +

    Guides for fellow travelers

    +

    The less stuff you travel with the better off you will be, up to a point. But where is that point? What's enough? What's too much? That point is what I'm trying to discover here.

    +

    What do you really need? What's worth having? What's not?

    +

    Topics include {% for topic in topic_list %}{{topic}}, {% endfor %}travel, cooking, photography, writing, simplicity, and once, coffee.

    +
    +

    Guides

    + {% autopaginate object_list 30 %} + +
    +{%endblock%} diff --git a/app/posts/urls.py b/app/posts/urls.py new file mode 100644 index 0000000..322e5ad --- /dev/null +++ b/app/posts/urls.py @@ -0,0 +1,24 @@ +from django.urls import path, re_path +from django.views.generic.base import RedirectView + +from . import views + +app_name = "posts" + +urlpatterns = [ + path( + r'.txt', + views.EntryDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'', + views.EntryDetailView.as_view(), + name="detail" + ), + re_path( + r'/', + views.EntryList.as_view(), + name="list" + ), +] diff --git a/app/posts/views.py b/app/posts/views.py new file mode 100644 index 0000000..0324d16 --- /dev/null +++ b/app/posts/views.py @@ -0,0 +1,75 @@ +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 + +from .models import Post +from taxonomy.models import Category + + +class PostList(PaginatedListView): + """ + Return a list of Entries in reverse chronological order + """ + model = Post + + def get_queryset(self): + queryset = super(PostList, self).get_queryset() + return queryset.filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + + +class GuidesListView(PostList): + + def get_queryset(self): + queryset = super(GuidesListView, self).get_queryset() + return queryset.filter(post_type__in=[0,1]).filter(status__exact=1).order_by('-pub_date').prefetch_related('location').prefetch_related('featured_image') + + +class EssayListView(PostList): + template_name = "posts/essay_list.html" + + def get_queryset(self): + 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') + + +class PostDetailView(DetailView): + model = Post + slug_field = "slug" + + def get_queryset(self): + queryset = super(PostDetailView, self).get_queryset() + return queryset.select_related('location').prefetch_related('field_notes') + + def get_context_data(self, **kwargs): + context = super(PostDetailView, self).get_context_data(**kwargs) + related = [] + for obj in self.object.related.all(): + model = apps.get_model(obj.post_model.app_label, obj.post_model.model) + related.append(model.objects.get(slug=obj.slug)) + context['related'] = related + return context + + +class PostDetailViewTXT(PostDetailView): + template_name = "posts/entry_detail.txt" + + +class PostsRSSFeedView(Feed): + title = "VanLifeReviews.com: " + link = "/" + description = "Latest reviews, stories and guides" + description_template = 'feeds/blog_description.html' + + def items(self): + return Post.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + def item_pubdate(self, item): + """ + Takes an item, as returned by items(), and returns the item's + pubdate. + """ + return item.pub_date -- cgit v1.2.3-70-g09d2