#NEWLINE# @ register . simple_tag #NEWLINE# def gravatar( email , size = 50 , rating = 'g' , default = None ) : #NEWLINE# #INDENT# '\n    Returns a gravatar url.\n\n    Example tag usage: {% gravatar user.email 80 "g" %}\n\n    :Parameters:\n       - `email`: the email to send to gravatar.\n       - `size`: optional YxY size for the image.\n       - `rating`: optional rating (g, pg, r, or x) of the image.\n       - `default`: optional default image url or hosted image like wavatar.\n    ' #NEWLINE# rating = rating . lower ( ) #NEWLINE# ratings = [ 'g' , 'pg' , 'r' , 'x' ] #NEWLINE# if ( rating not in ratings ) : #NEWLINE# #INDENT# raise template . TemplateSyntaxError ( ( 'rating must be %s' % ', ' . join ( ratings ) ) ) #NEWLINE# #UNINDENT# hash = md5 ( email ) . hexdigest ( ) #NEWLINE# url = ( 'http://www.gravatar.com/avatar/%s?s=%s&r=%s' % ( hash , size , default ) ) #NEWLINE# if default : #NEWLINE# #INDENT# url = ( '%s&d=%s' % ( url , default ) ) #NEWLINE# #UNINDENT# return url