#NEWLINE# def bake_obi_image( self , request = None ) : #NEWLINE# #INDENT# "Bake the OBI JSON badge award assertion into a copy of the original\n        badge's image, if one exists." #NEWLINE# if request : #NEWLINE# #INDENT# base_url = request . build_absolute_uri ( '/' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# base_url = ( 'http://%s' % ( Site . objects . get_current ( ) . domain , ) ) #NEWLINE# #UNINDENT# if base_url . badge . image : #NEWLINE# #INDENT# self . badge . image . open ( ) #NEWLINE# img_copy_fh = StringIO ( self . badge . image . file . read ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# img_copy_fh = StringIO ( open ( DEFAULT_BADGE_IMAGE , 'rb' ) . read ( ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# img = Image . open ( img_copy_fh ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# from PIL import PngImagePlugin #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# import PngImagePlugin #NEWLINE# #UNINDENT# meta = PngImagePlugin . PngInfo ( ) #NEWLINE# hosted_assertion_url = ( '%s%s' % ( base_url , reverse ( 'badger.award_detail_json' , args = ( self . badge . slug , self . id ) ) ) ) #NEWLINE# meta . add_text ( 'openbadges' , hosted_assertion_url ) #NEWLINE# new_img = StringIO ( ) #NEWLINE# img . save ( new_img , 'PNG' , pnginfo = meta ) #NEWLINE# img_data = new_img . getvalue ( ) #NEWLINE# name_before = self . image . name #NEWLINE# self . image . save ( '' , ContentFile ( img_data ) , False ) #NEWLINE# if self . image . storage . exists ( name_before ) : #NEWLINE# #INDENT# self . image . storage . delete ( name_before ) #NEWLINE# #UNINDENT# Award . objects . filter ( pk = self . pk ) . update ( image = self . image ) #NEWLINE# return True