Skip to content

Commit

Permalink
When getting all thumbs in the admin for display, only grab those tha…
Browse files Browse the repository at this point in the history
…t have been created - not crop on request ones
  • Loading branch information
ortsed committed Apr 6, 2012
1 parent 1172dbd commit babbe3c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cropduster/models.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cropduster/templates/admin/inline.html
Expand Up @@ -53,7 +53,7 @@

<div class="cropduster_thumbs">
{% if image %}
{% for size in image.size_set.get_size_by_ratio() %}
{% for size in image.size_set.get_size_by_ratio(created=True) %}
<img src="{{ image.thumbnail_url(size.slug) }}" />
{% endfor %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion cropduster/views.py
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cropduster/widgets.py
Expand Up @@ -27,13 +27,13 @@ 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,
"cropduster_url": cropduster_url,
"input": input,
"attrs": attrs,
})
return t.render(c)
return template.render(context)

0 comments on commit babbe3c

Please sign in to comment.