Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Commit

Permalink
Move larger thumbnailing to the thumbnail cron.
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed May 10, 2012
1 parent 87d871c commit 209c848
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions postcards/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def submit_link_to_postcard(postcard_id):

@processed_asynchronously
def generate_thumbnails(postcard_id, width=70, height=70):
dimensions = dict(small=(215, 215),
full=(800, 800))

postcard = Postcard._byID(postcard_id)

if postcard.front:
Expand All @@ -95,6 +98,23 @@ def generate_thumbnails(postcard_id, width=70, height=70):
if postcard.back:
postcard.back_thumb, _ = make_smaller_version_of_image(postcard.back)

image_info = {}
for size in ('small', 'full'):
image_info[size] = {}

for side in ('front', 'back'):
full_image_url = getattr(postcard, side)
if not full_image_url:
continue

img_data = make_smaller_version_of_image(full_image_url,
dimensions[size])
filename, (width, height) = img_data
image_info[size][side] = dict(filename=filename,
width=width,
height=height)
postcard.json_image_info = json.dumps(image_info)

postcard._commit()


Expand Down Expand Up @@ -123,36 +143,15 @@ def chunks(l, n):

@processed_asynchronously
def generate_jsonp():
dimensions = dict(small=(215, 215),
full=(800, 800))

query = Postcard.query.filter_by(published=True, deleted=False).order_by(db.asc(Postcard.id))
all_postcards = []
for postcard in query:
# make sure the images are in place
if not postcard.json_image_info:
image_info = {}

for size in ('small', 'full'):
image_info[size] = {}

for side in ('front', 'back'):
full_image_url = getattr(postcard, side)
if not full_image_url:
continue

img_data = make_smaller_version_of_image(full_image_url,
dimensions[size])
filename, (width, height) = img_data
image_info[size][side] = dict(filename=filename,
width=width,
height=height)

postcard.json_image_info = json.dumps(image_info)
else:
image_info = json.loads(postcard.json_image_info)
continue

# add the postcard data
image_info = json.loads(postcard.json_image_info)
data = dict(id=postcard.id,
date=str(postcard.date),
country=postcard.country,
Expand Down

0 comments on commit 209c848

Please sign in to comment.