#NEWLINE# def my_members( self ) : #NEWLINE# #INDENT# 'Returns a dictionary from ("User"|"Group", "name") tuples to records.' #NEWLINE# parent = aliased ( Group ) #NEWLINE# group_member = aliased ( Group ) #NEWLINE# user_member = aliased ( User ) #NEWLINE# now = datetime . utcnow ( ) #NEWLINE# users = self . session . query ( label ( 'id' , user_member . id ) , label ( 'type' , literal ( 'User' ) ) , label ( 'name' , user_member . username ) , label ( 'role' , GroupEdge . _role ) , label ( 'edge_id' , GroupEdge . id ) , label ( 'expiration' , GroupEdge . expiration ) ) . filter ( ( parent . id == self . id ) , ( parent . id == GroupEdge . group_id ) , ( user_member . id == GroupEdge . member_pk ) , ( GroupEdge . active == True ) , ( parent . enabled == True ) , ( user_member . enabled == True ) , or_ ( ( GroupEdge . expiration > now ) , ( GroupEdge . expiration == None ) ) , ( GroupEdge . member_type == 0 ) ) . group_by ( 'type' , 'name' ) . subquery ( ) #NEWLINE# groups = self . session . query ( label ( 'id' , group_member . id ) , label ( 'type' , literal ( 'Group' ) ) , label ( 'name' , group_member . groupname ) , label ( 'role' , GroupEdge . _role ) , label ( 'edge_id' , GroupEdge . id ) , label ( 'expiration' , GroupEdge . expiration ) ) . filter ( ( parent . id == self . id ) , ( parent . id == GroupEdge . group_id ) , ( group_member . id == GroupEdge . member_pk ) , ( GroupEdge . active == True ) , ( parent . enabled == True ) , ( group_member . enabled == True ) , or_ ( ( GroupEdge . expiration > now ) , ( GroupEdge . expiration == None ) ) , ( GroupEdge . member_type == 1 ) ) . subquery ( ) #NEWLINE# query = self . session . query ( 'id' , 'type' , 'name' , 'role' , 'edge_id' , 'expiration' ) . select_entity_from ( union_all ( users . select ( ) , groups . select ( ) ) ) . order_by ( desc ( 'role' ) , desc ( 'type' ) ) #NEWLINE# return OrderedDict ( ( ( ( users . type , record . name ) , record ) for record in query . all ( ) ) )