#NEWLINE# @ register . simple_tag ( takes_context = True ) #NEWLINE# def photos_box( context ) : #NEWLINE# #INDENT# flickr_set_id = context [ 'event' ] . flickr_set_id #NEWLINE# if ( not flickr_set_id ) : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# jsonresp = api . flickr_call ( method = 'flickr.photosets.getPhotos' , photoset_id = flickr_set_id , format = 'json' , nojsoncallback = 1 ) #NEWLINE# #UNINDENT# except urllib2 . URLError : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# images = [ ] #NEWLINE# r = json . loads ( jsonresp ) #NEWLINE# if ( r . get ( 'stat' , 'error' ) == 'ok' ) : #NEWLINE# #INDENT# for image in r [ 'photoset' ] [ 'photo' ] : #NEWLINE# #INDENT# image [ 'thumb_url' ] = ( settings . PHOTOS_FLICKR_IMAGE_URL_S % image ) #NEWLINE# image [ 'url' ] = ( settings . PHOTOS_FLICKR_IMAGE_URL % image ) #NEWLINE# image [ 'title' ] = image . get ( 'title' , '' ) #NEWLINE# images . append ( image ) #NEWLINE# #UNINDENT# t = loader . get_template ( 'gallery/photos_box.html' ) #NEWLINE# context [ 'images' ] = images #NEWLINE# return t . render ( context ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . error ( 'Could not fetch images from Flickr' , exc_info = True , extra = locals ( ) ) #NEWLINE# return ''