def getListData(self): if lists.getListIndex(self.data.request) != 0: return None query = profile_logic.queryAllMentorsForProgram(self.data.program.key()) starter = lists.keyStarter # TODO(daniel): enable prefetching from ndb models # ('mentor_for', 'org_admin_for') prefetcher = None response_builder = lists.RawQueryContentResponseBuilder( self.data.request, self._list_config, query, starter, prefetcher=prefetcher) return response_builder.buildNDB()
def getListData(self): if lists.getListIndex(self.data.request) != 0: return None query = profile_logic.queryAllMentorsForProgram(self.data.program.key()) import logging logging.error(query.fetch(1000)) starter = lists.keyStarter # TODO(daniel): enable prefetching for the list (mentor_for, admin_for) prefetcher = None response_builder = lists.RawQueryContentResponseBuilder( self.data.request, self._list_config, query, starter, prefetcher=prefetcher) return response_builder.build()
def getListData(self): if lists.getListIndex(self.data.request) != 0: return None query = profile_logic.queryAllMentorsForProgram( self.data.program.key()) starter = lists.keyStarter # TODO(daniel): enable prefetching from ndb models # ('mentor_for', 'org_admin_for') prefetcher = None response_builder = lists.RawQueryContentResponseBuilder( self.data.request, self._list_config, query, starter, prefetcher=prefetcher) return response_builder.buildNDB()
def getListData(self): if lists.getListIndex(self.data.request) != 0: return None query = profile_logic.queryAllMentorsForProgram( self.data.program.key()) import logging logging.error(query.fetch(1000)) starter = lists.keyStarter # TODO(daniel): enable prefetching for the list (mentor_for, admin_for) prefetcher = None response_builder = lists.RawQueryContentResponseBuilder( self.data.request, self._list_config, query, starter, prefetcher=prefetcher) return response_builder.build()
def refreshConversationParticipants(conversation): """Creates/deletes GCIConversationUser entities depending on the converation's criteria. The conversation's owner is always included in the conversation. If the conversation's recipients_type is 'User', this function will not do anything because it is expected that the GCIConversationUser will be managed elsewhere. Args: conversation: Key (ndb) of GCIConversation. """ conv = conversation.get() def addProfile(profile): addUserToConversation( conversation=conversation, user=profile.key.parent()) def deleteConvUserIfDoesntBelong(conv_user): if not doesConversationUserBelong(conversation_user=conv_user.key): conv_user.key.delete() # Remove any users included who no longer fit the criteria if conv.recipients_type != conversation_model.USER: conv_user_query = queryConversationUserForConversation(conversation) map(deleteConvUserIfDoesntBelong, conv_user_query) # Make sure users who fit the criteria are included if conv.recipients_type == conversation_model.PROGRAM: if conv.include_admins: query = profile_model.Profile.query( profile_model.Profile.program == conv.program, profile_model.Profile.is_admin == True) map(addProfile, query) if conv.include_mentors: query = profile_logic.queryAllMentorsForProgram(conv.program.to_old_key()) map(addProfile, query) if conv.include_students: query = profile_model.Profile.query( profile_model.Profile.program == conv.program, profile_model.Profile.is_student == True) map(addProfile, query) if conv.include_winners: query = profile_model.Profile.query( profile_model.Profile.program == conv.program, profile_model.Profile.student_data.is_winner == True) map(addProfile, query) elif conv.recipients_type == conversation_model.ORGANIZATION: if conv.include_admins: org_admins = profile_logic.getOrgAdmins(conv.organization) map(addProfile, org_admins) if conv.include_mentors: query = profile_model.Profile.query( profile_model.Profile.mentor_for == conv.organization, profile_model.Profile.status == profile_model.Status.ACTIVE) map(addProfile, query) if conv.include_winners: query = profile_model.Profile.query( profile_model.Profile.student_data.winner_for == conv.organization, profile_model.Profile.status == profile_model.Status.ACTIVE) map(addProfile, query) # Make sure conversation's creator is included if conv.creator is not None: addUserToConversation(conversation=conversation, user=conv.creator)
def testAllMentorsForProgramFetched(self): """Tests that the returned query fetches all mentors for the program.""" query = profile_logic.queryAllMentorsForProgram(self.program_one.key()) result = query.fetch(1000) self.assertEqual(self.mentor_keys, set(mentor.key for mentor in result))
def refreshConversationParticipants(conversation): """Creates/deletes GCIConversationUser entities depending on the converation's criteria. The conversation's owner is always included in the conversation. If the conversation's recipients_type is 'User', this function will not do anything because it is expected that the GCIConversationUser will be managed elsewhere. Args: conversation: Key (ndb) of GCIConversation. """ conv = conversation.get() def addProfile(profile): addUserToConversation(conversation=conversation, user=profile.key.parent()) def deleteConvUserIfDoesntBelong(conv_user): if not doesConversationUserBelong(conversation_user=conv_user.key): conv_user.key.delete() # Remove any users included who no longer fit the criteria if conv.recipients_type != conversation_model.USER: conv_user_query = queryConversationUserForConversation(conversation) map(deleteConvUserIfDoesntBelong, conv_user_query) # Make sure users who fit the criteria are included if conv.recipients_type == conversation_model.PROGRAM: if conv.include_admins: query = profile_model.Profile.query( profile_model.Profile.program == conv.program, profile_model.Profile.is_admin == True) map(addProfile, query) if conv.include_mentors: query = profile_logic.queryAllMentorsForProgram( conv.program.to_old_key()) map(addProfile, query) if conv.include_students: query = profile_model.Profile.query( profile_model.Profile.program == conv.program, profile_model.Profile.is_student == True) map(addProfile, query) if conv.include_winners: query = profile_model.Profile.query( profile_model.Profile.program == conv.program, profile_model.Profile.student_data.is_winner == True) map(addProfile, query) elif conv.recipients_type == conversation_model.ORGANIZATION: if conv.include_admins: org_admins = profile_logic.getOrgAdmins(conv.organization) map(addProfile, org_admins) if conv.include_mentors: query = profile_model.Profile.query( profile_model.Profile.mentor_for == conv.organization, profile_model.Profile.status == profile_model.Status.ACTIVE) map(addProfile, query) if conv.include_winners: query = profile_model.Profile.query( profile_model.Profile.student_data.winner_for == conv.organization, profile_model.Profile.status == profile_model.Status.ACTIVE) map(addProfile, query) # Make sure conversation's creator is included if conv.creator is not None: addUserToConversation(conversation=conversation, user=conv.creator)