#NEWLINE# def award_to( self , awardee = None , email = None , awarder = None , description = '' , raise_already_awarded = False ) : #NEWLINE# #INDENT# "Award this badge to the awardee on the awarder's behalf" #NEWLINE# if ( not awarder ) : #NEWLINE# #INDENT# awarder = self . creator #NEWLINE# #UNINDENT# if ( not self . allows_award_to ( awarder ) ) : #NEWLINE# #INDENT# raise BadgeAwardNotAllowedException ( ) #NEWLINE# #UNINDENT# if ( email and ( not awardee ) ) : #NEWLINE# #INDENT# qs = User . objects . filter ( email = email ) #NEWLINE# if ( not qs ) : #NEWLINE# #INDENT# if ( self . unique and DeferredAward . objects . filter ( badge = self , email = email ) . exists ( ) ) : #NEWLINE# #INDENT# raise BadgeAlreadyAwardedException ( ) #NEWLINE# #UNINDENT# da = DeferredAward ( badge = self , email = email ) #NEWLINE# da . save ( ) #NEWLINE# return da #NEWLINE# #UNINDENT# awardee = qs . latest ( 'date_joined' ) #NEWLINE# #UNINDENT# if ( self . unique and self . is_awarded_to ( awardee ) ) : #NEWLINE# #INDENT# if raise_already_awarded : #NEWLINE# #INDENT# raise BadgeAlreadyAwardedException ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return Award . objects . filter ( user = awardee , badge = self ) [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# return Award . objects . create ( user = awardee , badge = self , creator = awarder , description = description )