#NEWLINE# def render( self , name , value , attrs = None ) : #NEWLINE# #INDENT# import re #NEWLINE# EMBED_HTML = '<div><iframe src="http://www.youtube.com/embed/%s?rel=0"\n                        width="400" height="200" frameborder></iframe></div>\n                     ' #NEWLINE# youtube_id_pattern = re . compile ( '^.*((youtu.be\\/)|(v\\/)|(\\/u\\/\\w\\/)|(embed\\/)|(watch\\?))\\??v?=?([0-9a-zA-Z\\-_]+).*$' ) #NEWLINE# output = [ ] #NEWLINE# if value : #NEWLINE# #INDENT# match_obj = youtube_id_pattern . search ( str ( value ) ) #NEWLINE# if ( match_obj . group ( 7 ) is not None ) : #NEWLINE# #INDENT# youtube_id = match_obj . group ( 7 ) #NEWLINE# output . append ( ( EMBED_HTML % youtube_id ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output . append ( ( '<b>%s</b>' % _ ( 'This is not a valid youtube link' ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# output . append ( super ( AdminTextInputWidget , self ) . render ( name , value , attrs ) ) #NEWLINE# return mark_safe ( '' . join ( output ) )