diff options
Diffstat (limited to 'app/jrnl')
-rw-r--r-- | app/jrnl/admin.py | 11 | ||||
-rw-r--r-- | app/jrnl/models.py | 31 | ||||
-rw-r--r-- | app/jrnl/templates/horizontal_select.html | 17 |
3 files changed, 50 insertions, 9 deletions
diff --git a/app/jrnl/admin.py b/app/jrnl/admin.py index c3b0c81..2d843b9 100644 --- a/app/jrnl/admin.py +++ b/app/jrnl/admin.py @@ -6,6 +6,7 @@ from utils.widgets import AdminImageWidget, LGEntryForm from .models import Entry, HomepageCurrator from photos.forms import GalleryForm +from photos.models import LuxImage from utils.util import get_latlon @@ -13,6 +14,10 @@ from utils.util import get_latlon class EntryAdmin(OSMGeoAdmin): form = LGEntryForm + def render_change_form(self, request, context, *args, **kwargs): + context['adminform'].form.fields['featured_image'].queryset = LuxImage.objects.all()[:50] + 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) @@ -46,7 +51,7 @@ class EntryAdmin(OSMGeoAdmin): 'fields': ( 'dek', 'meta_description', - ('image', 'thumbnail'), + 'image', 'template_name', 'enable_comments', ), @@ -55,6 +60,7 @@ class EntryAdmin(OSMGeoAdmin): 'fields': ( 'field_notes', 'books', + 'featured_image', ), 'classes': ( 'collapse', @@ -77,6 +83,9 @@ class EntryAdmin(OSMGeoAdmin): class Media: js = ('image-loader.js', 'next-prev-links.js') + css = { + "all": ("my_styles.css",) + } @admin.register(HomepageCurrator) diff --git a/app/jrnl/models.py b/app/jrnl/models.py index bcfd0b8..19f5417 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -1,6 +1,9 @@ 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.contrib.gis.db import models from django.utils.html import format_html @@ -18,7 +21,8 @@ from django.template.defaultfilters import slugify import markdown from bs4 import BeautifulSoup -from photos.models import PhotoGallery, LuxImage +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 @@ -73,7 +77,7 @@ 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, null=True, 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") + #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'), @@ -108,7 +112,7 @@ class Entry(models.Model): return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date def get_thumbnail_url(self): - image_dir, img = self.thumbnail.url.split('post-thumbnail/')[1].split('/') + image_dir, img = self.image.url.split('post-thumbnail/')[1].split('/') return '%spost-thumbnail/%s/%s' % (settings.IMAGES_URL, image_dir, img) def get_image_url(self): @@ -175,8 +179,15 @@ class Entry(models.Model): except model.DoesNotExist: return '' - def save(self): - if self.pk: + def get_image_name(self): + return self.image.url.split("post-images/")[1][5:-4] + + def get_image_ext(self): + return self.image.url[-3:] + + 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.has_video = parse_video(self.body_html) @@ -184,9 +195,13 @@ class Entry(models.Model): 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)) - - super(Entry, self).save() - + old = type(self).objects.get(pk=self.pk) if self.pk else None + print("self.image.path: ", self.image.path) + if old and old.featured_image != self.featured_image or created: # Field has changed + s = LuxImageSize.objects.get(name="featured_jrnl") + self.featured_image.sizes.add(s) + self.featured_image.save() + super(Entry, self).save(*args, **kwargs) class HomepageCurrator(models.Model): diff --git a/app/jrnl/templates/horizontal_select.html b/app/jrnl/templates/horizontal_select.html new file mode 100644 index 0000000..4b0a2a1 --- /dev/null +++ b/app/jrnl/templates/horizontal_select.html @@ -0,0 +1,17 @@ +{% with id=widget.attrs.id %} + <ul{% if id %} id="{{ id }}"{% endif %}{% if widget.attrs.class %} class="{{ widget.attrs.class }}"{% endif %}> + {% for group, options, index in widget.optgroups %} + {% if group %} + <li>{{ group }} + <ul{% if id %} id="{{ id }}_{{ index }}"{% endif %}> + {% endif %} + {% for option in options %} + <li data-imageid="{{option.value}}">{% include option.template_name with widget=option %}</li> + {% endfor %} + {% if group %} + </ul> + </li> + {% endif %} + {% endfor %} + </ul> +{% endwith %} |