From babbe3cb695587c73488dee6aed5ac7ee636cbde Mon Sep 17 00:00:00 2001 From: Llewellyn Hinkes-Jones Date: Fri, 6 Apr 2012 10:47:52 -0400 Subject: [PATCH] When getting all thumbs in the admin for display, only grab those that have been created - not crop on request ones --- cropduster/models.py | 7 ++++++- cropduster/templates/admin/inline.html | 2 +- cropduster/views.py | 2 +- cropduster/widgets.py | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cropduster/models.py b/cropduster/models.py index afa745b3..5079a67f 100644 --- a/cropduster/models.py +++ b/cropduster/models.py @@ -34,12 +34,17 @@ class SizeSet(CachingMixin, models.Model): def __unicode__(self): return u"%s" % self.name - def get_size_by_ratio(self): + def get_size_by_ratio(self, created=False): """ Shorthand to get all the unique ratios for display in the admin, rather than show every possible thumbnail """ size_query = Size.objects.all().filter(size_set__id=self.id) + + # Whether to only get the image sizes that have been created + if created: + size_query = size_query.filter(create_on_request=False) + size_query.query.group_by = ["aspect_ratio"] try: return size_query diff --git a/cropduster/templates/admin/inline.html b/cropduster/templates/admin/inline.html index 00132982..62fe2792 100644 --- a/cropduster/templates/admin/inline.html +++ b/cropduster/templates/admin/inline.html @@ -53,7 +53,7 @@
{% if image %} - {% for size in image.size_set.get_size_by_ratio() %} + {% for size in image.size_set.get_size_by_ratio(created=True) %} {% endfor %} {% endif %} diff --git a/cropduster/views.py b/cropduster/views.py index a60f7ac4..ff68c9d5 100644 --- a/cropduster/views.py +++ b/cropduster/views.py @@ -219,7 +219,7 @@ def upload(request): # No more cropping to be done, close out else : - image_thumbs = [image.thumbnail_url(size.slug) for size in image.size_set.get_size_by_ratio()] + image_thumbs = [image.thumbnail_url(size.slug) for size in image.size_set.get_size_by_ratio(created=True)] context = { "image": image, diff --git a/cropduster/widgets.py b/cropduster/widgets.py index 3f32f81c..58412491 100644 --- a/cropduster/widgets.py +++ b/cropduster/widgets.py @@ -27,8 +27,8 @@ def render(self, name, value, attrs=None): image = None - t = loader.get_template(self.template) - c = Context({ + template = loader.get_template(self.template) + context = Context({ "image": image, "size_set": self.size_set, "static_url": settings.STATIC_URL, @@ -36,4 +36,4 @@ def render(self, name, value, attrs=None): "input": input, "attrs": attrs, }) - return t.render(c) \ No newline at end of file + return template.render(context) \ No newline at end of file