summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/media/models.py33
-rw-r--r--app/posts/templates/posts/jrnl_detail.html1
-rw-r--r--design/templates/lib/img_archive.html5
3 files changed, 21 insertions, 18 deletions
diff --git a/app/media/models.py b/app/media/models.py
index 883d4df..bc27758 100644
--- a/app/media/models.py
+++ b/app/media/models.py
@@ -148,16 +148,15 @@ class LuxImage(models.Model):
return self.image.url
else:
luximagesize = LuxImageSize.objects.get(name=size)
- if luximagesize not in self.get_sizes:
- print("new size is "+luximagesize.name)
- self.sizes.add(luximagesize)
+ #if luximagesize not in self.get_sizes:
+ #self.sizes.add(luximagesize)
return "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.image_name, luximagesize.slug, self.image_ext)
def get_image_path_by_size(self, size="original"):
if size == "original":
return self.image.path
else:
- luximagesize = LuxImageSize.objects.get(name=size)
+ luximagesize = LuxImageSize.objects.get(slug=size)
return "%s%s/%s_%s.%s" % (settings.IMAGES_ROOT, self.pub_date.strftime("%Y"), self.image_name, luximagesize.slug, self.image_ext)
def get_thumbnail_url(self):
@@ -167,7 +166,7 @@ class LuxImage(models.Model):
return format_html('<a href="%s"><img src="%s"></a>' % (self.get_image_url_by_size(), self.get_image_url_by_size("admin-thumbnail")))
admin_thumbnail.short_description = 'Thumbnail'
- @cached_property
+ @property
def get_sizes(self):
return self.sizes_cache.split(",")
@@ -202,7 +201,7 @@ class LuxImage(models.Model):
def save(self, *args, **kwargs):
created = self.pk is None
if created:
- self.sizes.add(LuxImageSize.objects.get(name="admin-thumbnail"))
+ self.sizes.add(LuxImageSize.objects.get(name="tn"))
img = Image.open(self.image.path)
self.height = img.height
self.width = img.width
@@ -346,32 +345,34 @@ def update_photo_sizes(sender, instance, **kwargs):
# update the local cache of sizes
instance.sizes_cache = ",".join(s.slug for s in instance.sizes.all())
instance.save()
- for size in instance.sizes.all():
+ print(instance.get_sizes)
+ for size in instance.get_sizes:
# check each size and see if there's an image there already
- my_file = Path(instance.get_image_path_by_size(size.name))
+ my_file = Path(instance.get_image_path_by_size(size))
if not my_file.is_file():
print("creating new image file")
#file doesn't exist, so create it
- if size.width:
+ new_size = LuxImageSize.objects.get(slug=size)
+ if new_size.width:
img = Image.open(instance.image.path)
try:
- if size.width <= img.width:
- resize_image(img, size.width, None, size.quality, instance.get_image_path_by_size(size.name))
+ if new_size.width <= img.width:
+ resize_image(img, new_size.width, None, new_size.quality, instance.get_image_path_by_size(size))
else:
raise ValidationError({'items': ["Size is larger than source image"]})
except ImageSizeError:
m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through)
- instance.sizes.remove(size)
+ instance.sizes.remove(new_size)
m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through)
- if size.height:
+ if new_size.height:
try:
- if size.height <= img.height:
- resize_image(img, None, size.height, size.quality, instance.get_image_path_by_size(size.name))
+ if new_size.height <= img.height:
+ resize_image(img, None, new_size.height, new_size.quality, instance.get_image_path_by_size(size))
else:
pass
except ImageSizeError:
m2m_changed.disconnect(update_photo_sizes, sender=LuxImage.sizes.through)
- instance.sizes.remove(size)
+ instance.sizes.remove(new_size)
m2m_changed.connect(update_photo_sizes, sender=LuxImage.sizes.through)
else:
# file exists, might add something here to force it to do the above when I want
diff --git a/app/posts/templates/posts/jrnl_detail.html b/app/posts/templates/posts/jrnl_detail.html
index 9480732..7801f6a 100644
--- a/app/posts/templates/posts/jrnl_detail.html
+++ b/app/posts/templates/posts/jrnl_detail.html
@@ -126,6 +126,7 @@ class="detail {%if t == 1 or t == 3 or t == 5 %}double{%else%}single{%endif%}{%i
<div class="post-image post-mini-image">
{% if object.featured_image %}
{% include "lib/img_archive.html" with image=object.featured_image nolightbox=True %}
+ {%endif%}
</div>
<h4 class="p-name entry-title post-title" itemprop="headline">{% if object.title %}{{object.title|safe|smartypants|widont}}{% else %}{{object.common_name}}{%endif%}</h4>
<p class="p-author author hide" itemprop="author"><span class="byline-author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Scott Gilbertson</span></span></p>
diff --git a/design/templates/lib/img_archive.html b/design/templates/lib/img_archive.html
index 561f48c..4ff8e8a 100644
--- a/design/templates/lib/img_archive.html
+++ b/design/templates/lib/img_archive.html
@@ -1,6 +1,7 @@
{% load get_image_by_size %}
+{% get_image_by_size image 'featured_jrnl' as featured %}
<img sizes="(max-width: 728px) 100vw, (min-width: 729px) 520px"
- srcset="{%get_image_by_size image 'featured_jrnl'%} 520w, {%get_image_by_size image 'picwide-sm'%} 720w"
- src="{%get_image_by_size image 'featured_jrnl'%}"
+ srcset="{{featured}} 520w, {%get_image_by_size image 'picwide-sm'%} 720w"
+ src="{{featured}}"
alt="{{image.alt}} photographed by {% if image.photo_credit_source %}{{image.photo_credit_source}}{%else%}luxagraf{%endif%}"
{% if not nolightbox %}data-jslghtbx="{{image.get_image_by_size}}" data-jslghtbx-group="group" {% if caption%}data-jslghtbx-caption="{{image.caption}}"{%endif%}{%endif%}>