#NEWLINE# @ flush_transaction #NEWLINE# def add_member( self , requester , user_or_group , reason , status = 'pending' , expiration = None , role = 'member' ) : #NEWLINE# #INDENT# ' Add a member (User or Group) to this group.\n\n            Arguments:\n                requester: A User object of the person requesting the addition\n                user_or_group: A User/Group object of the member\n                reason: A comment on why this member should exist\n                status: pending/actioned, whether the request needs approval\n                        or should be immediate\n                expiration: datetime object when membership should expire.\n                role: member/manager/owner/np-owner of the Group.\n        ' #NEWLINE# now = datetime . utcnow ( ) #NEWLINE# member_type = user_or_group . member_type #NEWLINE# if ( member_type == 1 ) : #NEWLINE# #INDENT# role = 'member' #NEWLINE# #UNINDENT# logging . debug ( 'Adding member (%s) to %s' , user_or_group . name , self . groupname ) #NEWLINE# ( edge , new ) = GroupEdge . get_or_create ( self . session , group_id = self . id , member_type = member_type , member_pk = user_or_group . id ) #NEWLINE# edge . _role = GROUP_EDGE_ROLES . index ( role ) #NEWLINE# self . session . flush ( ) #NEWLINE# request = Request ( requester_id = requester . id , requesting_id = self . id , on_behalf_obj_type = member_type , on_behalf_obj_pk = user_or_group . id , requested_at = now , edge_id = edge . id , status = status , changes = build_changes ( edge , role = role , expiration = expiration , active = True ) ) . add ( self . session ) #NEWLINE# self . session . flush ( ) #NEWLINE# request_status_change = RequestStatusChange ( request = request , user_id = requester . id , to_status = status , change_at = now ) . add ( self . session ) #NEWLINE# self . session . flush ( ) #NEWLINE# Comment ( obj_type = 3 , obj_pk = request_status_change . id , user_id = requester . id , comment = reason , created_on = now ) . add ( self . session ) #NEWLINE# if ( member_type == 'actioned' ) : #NEWLINE# #INDENT# edge . apply_changes ( request ) #NEWLINE# self . session . flush ( ) #NEWLINE# #UNINDENT# Counter . incr ( self . session , 'updates' )