diff options
author | luxagraf <sng@luxagraf.net> | 2018-07-07 20:41:09 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-07-07 20:41:09 -0400 |
commit | 6a2393e6819ea09aeb559354a69746750aa8cbdf (patch) | |
tree | 0ac9890740f9afcd9720ea9b550a3895d95ecb50 /app/jrnl | |
parent | fe13c3830c6b36fb8f78009a788650a992cb3070 (diff) |
added campsite model, refactored some code to avoid circular imports,
reorganized some auxilary functions and fixed broken build JS.
Diffstat (limited to 'app/jrnl')
-rw-r--r-- | app/jrnl/build.py | 5 | ||||
-rw-r--r-- | app/jrnl/migrations/0001_initial.py | 1 | ||||
-rw-r--r-- | app/jrnl/migrations/0001_squashed_0019_remove_entry_thumbnail.py | 86 | ||||
-rw-r--r-- | app/jrnl/migrations/0022_auto_20180707_0958.py | 19 | ||||
-rw-r--r-- | app/jrnl/models.py | 92 |
5 files changed, 139 insertions, 64 deletions
diff --git a/app/jrnl/build.py b/app/jrnl/build.py index 5b5d929..0b3826a 100644 --- a/app/jrnl/build.py +++ b/app/jrnl/build.py @@ -5,6 +5,7 @@ from itertools import chain from django.conf import settings + class BuildJrnl(BuildNew): def build(self): @@ -58,7 +59,7 @@ class BuildJrnl(BuildNew): def build_homepage(self): response = self.client.get('/') self.write_file('', response.content) - + def build_latest(self): response = self.client.get('/jrnl/latest/') self.write_file(reverse("jrnl:latest"), response.content) @@ -72,7 +73,6 @@ class BuildJrnl(BuildNew): self.write_file("media/js/mainmap", response.content, 'js', '') - def archive_builder(): j = BuildJrnl("jrnl", "entry") j.build_arc() @@ -93,6 +93,7 @@ def rss_builder(): j = BuildJrnl("jrnl", "entry") j.build_feed("jrnl:feed") + def map_builder(): j = BuildJrnl("jrnl", "entry") j.build_map() diff --git a/app/jrnl/migrations/0001_initial.py b/app/jrnl/migrations/0001_initial.py index 7938b94..a3660ab 100644 --- a/app/jrnl/migrations/0001_initial.py +++ b/app/jrnl/migrations/0001_initial.py @@ -32,7 +32,6 @@ class Migration(migrations.Migration): ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), ('image', models.FileField(blank=True, help_text='should be 205px high', null=True, upload_to=jrnl.models.get_upload_path)), - ('thumbnail', models.FileField(blank=True, help_text='should be 160 wide', null=True, upload_to=jrnl.models.get_tn_path)), ('meta_description', models.CharField(blank=True, max_length=256, null=True)), ('template_name', models.IntegerField(choices=[(0, 'single'), (1, 'double'), (2, 'single-dark'), (3, 'double-dark'), (4, 'bigimg'), (5, 'bigimg-dark')], default=0)), ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), diff --git a/app/jrnl/migrations/0001_squashed_0019_remove_entry_thumbnail.py b/app/jrnl/migrations/0001_squashed_0019_remove_entry_thumbnail.py new file mode 100644 index 0000000..1a16b24 --- /dev/null +++ b/app/jrnl/migrations/0001_squashed_0019_remove_entry_thumbnail.py @@ -0,0 +1,86 @@ +# Generated by Django 2.0.1 on 2018-07-07 15:30 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion +import jrnl.models + + +class Migration(migrations.Migration): + + replaces = [('jrnl', '0001_initial'), ('jrnl', '0002_entrytitlesong'), ('jrnl', '0003_auto_20160309_1018'), ('jrnl', '0004_auto_20160309_1031'), ('jrnl', '0005_auto_20160514_2151'), ('jrnl', '0006_auto_20160715_0703'), ('jrnl', '0007_delete_postimage'), ('jrnl', '0008_auto_20160906_0845'), ('jrnl', '0009_homepagecurrator_image_offset_vertical'), ('jrnl', '0010_auto_20161102_0916'), ('jrnl', '0011_auto_20161102_0925'), ('jrnl', '0012_auto_20161102_0930'), ('jrnl', '0013_entry_featured_image'), ('jrnl', '0014_homepagecurrator'), ('jrnl', '0015_entry_has_video'), ('jrnl', '0016_auto_20161219_1058'), ('jrnl', '0017_entry_field_notes'), ('jrnl', '0018_auto_20180303_1037'), ('jrnl', '0019_remove_entry_thumbnail')] + + initial = True + + dependencies = [ + ('photos', '0016_auto_20161022_1411'), + ('sketches', '0002_auto_20180208_0743'), + ('books', '0005_auto_20171214_2239'), + ('photos', '0010_auto_20160517_0906'), + ('photos', '0003_luxgallery_caption_style'), + ] + + operations = [ + migrations.CreateModel( + name='Entry', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('slug', models.SlugField(unique_for_date='pub_date')), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField()), + ('dek', models.TextField(blank=True, null=True)), + ('pub_date', models.DateTimeField(verbose_name='Date published')), + ('enable_comments', models.BooleanField(default=False)), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), + ('image', models.FileField(blank=True, help_text='should be 205px high by 364px wide', null=True, upload_to=jrnl.models.get_upload_path)), + ('meta_description', models.CharField(blank=True, max_length=256, null=True)), + ('template_name', models.IntegerField(choices=[(0, 'single'), (1, 'double'), (2, 'single-dark'), (3, 'double-dark'), (4, 'single-black'), (5, 'double-black')], default=0)), + ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ('photo_gallery', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.PhotoGallery', verbose_name='photo set')), + ('featured_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='photos.LuxImage')), + ], + options={ + 'verbose_name_plural': 'entries', + 'get_latest_by': 'pub_date', + 'ordering': ('-pub_date',), + }, + ), + migrations.CreateModel( + name='HomepageCurrator', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('image_offset_vertical', models.CharField(help_text='add negative top margin to shift image (include css unit)', max_length=20)), + ('tag_line', models.CharField(max_length=200)), + ('template_name', models.CharField(help_text='full path', max_length=200)), + ('featured', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='banner', to='jrnl.Entry')), + ('images', models.ManyToManyField(to='photos.LuxImage')), + ('popular', models.ManyToManyField(to='jrnl.Entry')), + ], + ), + migrations.AddField( + model_name='entry', + name='has_video', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='entry', + name='image', + field=models.FileField(blank=True, help_text='should be 520 by 290', null=True, upload_to=jrnl.models.get_upload_path), + ), + migrations.AddField( + model_name='entry', + name='field_notes', + field=models.ManyToManyField(blank=True, to='sketches.Sketch'), + ), + migrations.AddField( + model_name='entry', + name='books', + field=models.ManyToManyField(blank=True, to='books.Book'), + ), + migrations.RemoveField( + model_name='entry', + name='thumbnail', + ), + ] diff --git a/app/jrnl/migrations/0022_auto_20180707_0958.py b/app/jrnl/migrations/0022_auto_20180707_0958.py new file mode 100644 index 0000000..809f562 --- /dev/null +++ b/app/jrnl/migrations/0022_auto_20180707_0958.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.1 on 2018-07-07 09:58 + +from django.db import migrations, models +import jrnl.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('jrnl', '0021_auto_20180606_1058'), + ] + + operations = [ + migrations.AlterField( + model_name='entry', + name='image', + field=models.FileField(blank=True, help_text='should be 520 by 290', upload_to=jrnl.models.get_upload_path), + ), + ] diff --git a/app/jrnl/models.py b/app/jrnl/models.py index 174b391..522764d 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -1,65 +1,39 @@ import datetime import os -import re -from PIL import Image -from django.db.models.signals import post_save -from django.dispatch import receiver +from django.dispatch import receiver from django.contrib.gis.db import models -from django.utils.html import format_html from django.urls import reverse from django.apps import apps -from django.template.loader import render_to_string from django.conf import settings -from django.template import Context -from django.contrib.syndication.views import Feed from django.contrib.sitemaps import Sitemap from django import forms -from django.template.defaultfilters import slugify -# http://freewisdom.org/projects/python-markdown/ -import markdown -from bs4 import BeautifulSoup +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 photos.models import PhotoGallery, LuxImage, LuxImageSize -from photos.utils import resize_image from locations.models import Location from sketches.models import Sketch from books.models import Book -from utils.widgets import parse_image, parse_video -from utils.widgets import markdown_to_html +from utils.util import render_images, parse_video, markdown_to_html def get_upload_path(self, filename): return "images/post-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) -def get_tn_path(self, filename): - return "images/post-thumbnail/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) - - def image_url_replace(s): s = s.replace('[[base_url]]', settings.IMAGES_URL) return s -def render_images(s): - s = re.sub('<img(.*)/>', parse_image, s) - return s - - -def extract_images(s): - soup = BeautifulSoup(s, "lxml") - imgs = [] - for img in soup.find_all('img'): - try: - imgs.append(img['src']) - except: - pass - return imgs - - class Entry(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique_for_date='pub_date') @@ -77,7 +51,6 @@ class Entry(models.Model): status = models.IntegerField(choices=PUB_STATUS, default=0) photo_gallery = models.ForeignKey(PhotoGallery, on_delete=models.CASCADE, blank=True, null=True, verbose_name='photo set') image = models.FileField(upload_to=get_upload_path, blank=True, help_text="should be 520 by 290") - #thumbnail = models.FileField(upload_to=get_tn_path, null=True, blank=True, help_text="should be 160 wide") meta_description = models.CharField(max_length=256, null=True, blank=True) TEMPLATES = ( (0, 'single'), @@ -136,8 +109,11 @@ class Entry(models.Model): img = os.path.splitext(img)[0] return '/media/images/home-images/hero%s_sm.jpg' % (img) - def get_images(self): - return extract_images(self.body_html) + def get_featured_image(self): + if self.featured_image: + return self.featured_image.image.url + else: + return self.image.url @property def state(self): @@ -164,7 +140,7 @@ class Entry(models.Model): @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() @@ -207,6 +183,10 @@ class Entry(models.Model): class HomepageCurrator(models.Model): + """ + simple model to control the featured article on the homepage + also allows me to fudge the "popular" section to be what I want + """ image_offset_vertical = models.CharField(max_length=20, help_text="add negative top margin to shift image (include css unit)") images = models.ManyToManyField(LuxImage) tag_line = models.CharField(max_length=200) @@ -227,16 +207,6 @@ class BlogSitemap(Sitemap): return obj.pub_date -import urllib.request -import urllib.parse -import urllib.error -from django_gravatar.helpers import get_gravatar_url, has_gravatar, calculate_gravatar_hash -from django.dispatch import receiver -from django_comments.signals import comment_was_posted -from django_comments.models import Comment -from django_comments.moderation import CommentModerator, moderator - - class EntryModerator(CommentModerator): ''' Moderate everything except people with multiple approvals @@ -255,6 +225,18 @@ class EntryModerator(CommentModerator): moderator.register(Entry, EntryModerator) + +@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) + # from django_comments.signals import comment_will_be_posted # from django_comments import akismet @@ -274,15 +256,3 @@ moderator.register(Entry, EntryModerator) # print('Something went wrong, allowing comment') # print(e.response, e.statuscode) # return True - - -@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) |