Permalink
Browse files

Add "latest" and "all" to jsonp outputs.

  • Loading branch information...
spladug committed Apr 26, 2012
1 parent 319247d commit d6b769847448d0fcb4f58f4462f3c1ec84178c37
Showing with 27 additions and 12 deletions.
  1. +27 −12 postcards/lib/utils.py
View
@@ -153,21 +153,36 @@ def generate_jsonp():
db.session.commit()
# write out the chunks
+ all_postcards = []
+ newest_chunk = sorted(chunks.keys(), reverse=True)[0]
for chunk_id, chunk in chunks.iteritems():
# generate the images if necessary
postcards = []
- data = dict(total_postcard_count=total_postcard_count,
- postcards=postcards)
for postcard in chunk:
- postcards.append(dict(id=postcard.id,
- date=str(postcard.date),
- country=postcard.country,
- latitude=str(postcard.latitude),
- longitude=str(postcard.longitude),
- images=image_info))
-
- json_data = "postcardsCallback%d(%s)" % (chunk_id,
- json.dumps(data))
+ data = dict(id=postcard.id,
+ date=str(postcard.date),
+ country=postcard.country,
+ latitude=str(postcard.latitude),
+ longitude=str(postcard.longitude),
+ images=image_info)
+ postcards.append(data)
+ all_postcards.append(data)
+
+ json_data = json.dumps(data)
upload_to_s3('postcards%d.js' % chunk_id,
- json_data, 'application/javascript')
+ 'postcardCallback%d(%s)' % (chunk_id, json_data),
+ 'application/javascript')
+
+ if chunk_id == newest_chunk:
+ upload_to_s3('postcards-latest.js',
+ 'postcardCallback(%s)' % json_data,
+ 'application/javascript')
+
+
+ data = dict(total_postcard_count=total_postcard_count,
+ postcards=all_postcards)
+ json_data = json.dumps(data)
+ upload_to_s3('postcards-all.js',
+ 'postcardCallback(%s)' % json_data,
+ 'application/javascript')

0 comments on commit d6b7698

Please sign in to comment.