def get_attending(self, request): """ Get Conferences the calling user is attending (i.e. registered for) :param request: :return: ConferenceForms """ if not isinstance(request, message_types.VoidMessage): raise endpoints.BadRequestException() prof = ProfileApi.profile_from_user() # get user Profile conf_keys = prof.conferencesToAttend # Changed from original code if len(conf_keys) == 0: # user hasn't registered for anything, so bail out of this method return ConferenceForms() conferences = ndb.get_multi(conf_keys) # get organizers organisers = [ndb.Key(Profile, conf.organizerUserId) for conf in conferences] profiles = ndb.get_multi(organisers) # put display names in a dict for easier fetching names = {} for profile in profiles: names[profile.key.id()] = profile.displayName # return set of ConferenceForm objects per Conference return ConferenceForms(items=[conf.to_form(names[conf.organizerUserId]) for conf in conferences] )
def getConferencesToAttend(self, request): """Get list of conferences that user has registered for.""" profile = self._getProfileFromUser() conference_keys = profile.conferenceKeysToAttend array_of_keys = [] for key in conference_keys: array_of_keys.append(ndb.Key(urlsafe=key)) conferences = ndb.get_multi(array_of_keys) # TODO: # step 1: get user profile # step 2: get conferenceKeysToAttend from profile. # to make a ndb key from websafe key you can use: # ndb.Key(urlsafe=my_websafe_key_string) # step 3: fetch conferences from datastore. # Use get_multi(array_of_keys) to fetch all keys at once. # Do not fetch them one by one! # return set of ConferenceForm objects per Conference return ConferenceForms(items=[self._copyConferenceToForm(conf, "")\ for conf in conferences] )
def returnAllConferences(self, request): """Returns all Conferences""" q = Conference.query() q.fetch() return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q] )
def filterPlayground(self, request): q = Conference.query() # simple filter usage: # q = q.filter(Conference.city == "Paris") # advanced filter building and usage field = "city" operator = "=" value = "London" f = ndb.query.FilterNode(field, operator, value) q = q.filter(f) field = "topics" operator = "=" value = "Medical Innovations" f = ndb.query.FilterNode(field, operator, value) q = q.filter(f) # TODO # add 2 filters: # 1: city equals to London # 2: topic equals "Medical Innovations" return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q] )
def getConferencesToAttend(self, request): """ Get list of conferences that user has registered for. """ # get user Profile prof = self._getProfileFromUser() # get conferenceKeysToAttend from profile. conf_keys = [ ndb.Key(urlsafe=wsck) for wsck in prof.conferenceKeysToAttend ] conferences = ndb.get_multi(conf_keys) # get organizers organisers = [ ndb.Key(Profile, conf.organizerUserId) for conf in conferences ] profiles = ndb.get_multi(organisers) # put display names in a dict for easier fetching names = {} for profile in profiles: names[profile.key.id()] = profile.displayName # return set of ConferenceForm objects per Conference return ConferenceForms(items=[self._copyConferenceToForm(conf, names[conf.organizerUserId])\ for conf in conferences] )
def getConferencesToAttend(self, request): """Get list of conferences that user has registered for.""" # TODO: # step 1: get user profile # step 2: get conferenceKeysToAttend from profile. # to make a ndb key from websafe key you can use: # ndb.Key(urlsafe=my_websafe_key_string) # step 3: fetch conferences from datastore. # Use get_multi(array_of_keys) to fetch all keys at once. # Do not fetch them one by one! prof = self._getProfileFromUser() conf_keys = [ ndb.Key(urlsafe=wsck) for wsck in prof.conferenceKeysToAttend ] conferences = ndb.get_multi(conf_keys) profiles = ndb.get_multi( [ndb.Key(Profile, conf.organizerUserId) for conf in conferences]) # put display names in a dict for easier fetching names = {} for profile in profiles: names[profile.key.id()] = profile.displayName # return set of ConferenceForm objects per Conference return ConferenceForms(items=[self._copyConferenceToForm(conf, names[conf.organizerUserId])\ for conf in conferences] )
def querySimilarConferences(self, request): """Query for similar conferences by the same creator.""" # get conference object from Datastore conf = self._getDataStoreObject(request.websafeConferenceKey) # get parent's profile prof = conf.key.parent().get() # use ancestor query to get conferences by same creator, # then filter out the conference user provided conferences = Conference.query(ancestor=prof.key).filter( Conference.key != conf.key) # Create filterNode and perform search if all fields are provided if (request.field and request.operator and request.value): node = ndb.query.FilterNode(request.field, OPERATORS[request.operator], request.value) conferences = conferences.filter(node) # Raise error if user didn't provide all 3 fields, # otherwise return current query result without further filtering elif (request.field or request.operator or request.value): raise endpoints.BadRequestException( "You need to define field, operator, and value") return ConferenceForms( items=[ self._copyConferenceToForm(conf, prof.mainEmail ) for conf in conferences] )
def getConferencesToAttend(self, request): """Get list of conferences that user has registered for.""" # TODO: # step 1: get user profile prof = self._getProfileFromUser() # get user Profile # step 2: get conferenceKeysToAttend from profile. # to make a ndb key from websafe key you can use: # ndb.Key(urlsafe=my_websafe_key_string) #wsck = request.websafeConferenceKey #conf = ndb.Key(urlsafe=wsck).get() my_websafe_key_string = prof.key.urlsafe() conf = ndb.Key(urlsafe=my_websafe_key_string).get() if not conf: raise endpoints.NotFoundException( 'No conference found with key: %s' % my_websafe_key_string) conferenceKeysToAttend = prof.conferenceKeysToAttend # step 3: fetch conferences from datastore. # Use get_multi(array_of_keys) to fetch all keys at once. # Do not fetch them one by one! conferences = ndb.get_multi(conferenceKeysToAttend) # return set of ConferenceForm objects per Conference return ConferenceForms(items=[self._copyConferenceToForm(conf, "")\ for conf in conferences] )
def get_conferences_to_attend(self, request): """Get list of conferences that user has registered for.""" # Get conferences form profile profile = self._get_profile_from_user() ndb_keys = [ ndb.Key(urlsafe=ws_key) for ws_key in profile.conferenceKeysToAttend ] conferences = ndb.get_multi(ndb_keys) # Get organizers from conferences organisers = [ ndb.Key(Profile, conf.organizerUserId) for conf in conferences ] profiles = ndb.get_multi(organisers) # Get display names names = {} for profile in profiles: names[profile.key.id()] = profile.displayName # Return set of ConferenceForm objects per Conference return ConferenceForms(items=[ self._copy_conference_to_form(conf, "") for conf in conferences ])
def filterPlayground(self, request): q = Conference.query() #q = Conference.query(Conference.city == "London") q = ndb.gql("SELECT * FROM Conference WHERE city < 'London' AND maxAttendees > 5 ORDER BY city DESC") # simple filter usage: # advanced filter building and usage #f = ndb.query.FilterNode('maxAttendees', '>', 0) #q = q.filter(f) #q = Conference.query(Conference.city != 'London') #q = Conference.query(ndb.OR(Conference.city < 'London', Conference.city > 'London')) #q = q.order(Conference.description) q = q.order(-Conference.city) #q = q.fetch(limit=3, projection=[Conference.maxAttendees]) q = q.fetch(limit=7) # TODO # add 2 filters: # 1: city equals to Chicago # 2: topic equals "Medical Innovations" # q = q.filter(Conference.topics=="Medical Innovations") return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q] )
def getNotRegisteredWishlist(self, request): """Returns all sesssions on a users wishlist where the user is not registered for the conference.""" prof = self._getProfileFromUser() wishlist = prof.wishList wishlist_keys = [ndb.Key(urlsafe=wish) for wish in wishlist] # Get conferences attending. attending_wsk = prof.conferenceKeysToAttend attending_keys = [ndb.Key(urlsafe=wsk) for wsk in attending_wsk] # Get the parent conferenes of all sessions in the query. conf_keys = [session_key.parent() for session_key in wishlist_keys] # Query confreences with wishlist session as child. q = Conference.query() q = q.filter(Conference.key.IN([key for key in conf_keys])) # Query conferences that do not include those being attended. for key in attending_keys: q = q.filter(Conference.key != key) return ConferenceForms(items=[ self._copyConferenceToForm(conference, "") for conference in q ])
def getConferencesToAttend(self, request): """Get list of conferences that user has registered for.""" # TODO: # step 1: get user profile user = endpoints.get_current_user() if not user: raise endpoints.UnauthorizedException('Authorization required') # make profile key p_key = ndb.Key(Profile, getUserId(user)) # get the user profile prof = p_key.get() # step 2: get conferenceKeysToAttend from profile. # to make a ndb key from websafe key you can use: # ndb.Key(urlsafe=my_websafe_key_string) conf_keys_to_attend = getattr(prof, 'conferenceKeysToAttend') conf_ndb_keys = [ndb.Key(urlsafe=key) for key in conf_keys_to_attend] # step 3: fetch conferences from datastore. # Use get_multi(array_of_keys) to fetch all keys at once. # Do not fetch them one by one! conferences = ndb.get_multi(conf_ndb_keys) # return set of ConferenceForm objects per Conference return ConferenceForms(items=[self._copyConferenceToForm(conf, "")\ for conf in conferences] )
def filterPlayground(self, request): q = Conference.query() # simple filter usage: #q = q.filter(Conference.city == "London") #q = q.filter(Conference.topics == "Medical Innovations") # advanced filter building and usage # field = "topics" # operator = "=" # value = "Medical Innovations" # f = ndb.query.FilterNode(field, operator, value) # q = q.filter(f) # TODO # add 2 filters: # 1: city equals to London q = q.filter(Conference.city == "London") # 2: topic equals "Medical Innovations" q = q.filter(Conference.topics == "Medical Innovations") # 3: order by conference name q = q.order(Conference.name) # 4: filter for big conferences q = q.filter(Conference.maxAttendees > 10) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q] )
def queryConferences(self, request): """Query for conferences.""" conferences = self._getQuery(request) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in conferences] )
def filterTester(self, request): """Playground for testing queries. """ user = endpoints.get_current_user() if not user: raise endpoints.UnauthorizedException( 'Authorization required') p_key = ndb.Key(Profile, getUserId(user)) field = "city" operator = "<=" value = "Paris" filters = ndb.query.FilterNode(field, operator, value) q = Conference.query() conferences = q.filter(filters) conferences = q.order(Conference.name) conferences = q.filter(Conference.month == 6) prof = p_key.get() displayName = getattr(prof, 'displayName') return ConferenceForms( items=[self._copyConferenceToForm(conf, "") \ for conf in conferences])
def filterPlayground(self, request): q = Conference.query() # simple filter usage: #q = q.filter(Conference.city == "London") # advanced filter building and usage # field = "city" # operator = "=" # value = "London" # f = ndb.query.FilterNode(field, operator, value) # q = q.filter(f) # TODO # add 2 filters: # 1: city equals to London # 2: topic equals "Medical Innovations" f1 = ndb.query.FilterNode("city", "=", "London") f2 = ndb.query.FilterNode("topics", "=", "Medical Innovations") q = q.filter(f1) q = q.filter(f2) q = q.order(Conference.name) q = q.filter(Conference.month == 6) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q])
def populateApp(self, request): """Populate and reutrn conference""" confs = [ConferenceForm( name= u'aa', description= u'Uno', topics= [u'Medical Innovations'], city= u'Chicago', maxAttendees= 10, startDate= u'2016-11-25T05:00:00.000Z', endDate= u'2016-12-03T05:00:00.000Z'), ConferenceForm( name= u'bb', description= u'Dos', topics= [u'Programming Languages'], city= u'London', maxAttendees= 20, startDate= u'2016-10-15T05:00:00.000Z', endDate= u'2016-10-03T05:00:00.000Z'), ConferenceForm( name= u'cc', description= u'Tres', topics= [u'Web Technologies'], city= u'Paris', maxAttendees= 30, startDate= u'2016-10-15T05:00:00.000Z', endDate= u'2016-10-25T05:00:00.000Z'), ConferenceForm( name= u'dd', description= u'Cuatro', topics= [u'Movie Making'], city= u'Tokyo', maxAttendees= 40, startDate= u'2016-10-31T05:00:00.000Z', endDate= u'2016-11-05T05:00:00.000Z'), ConferenceForm( name= u'ee', description= u'Cinco', topics= [u'Health and Nutrition'], city= u'Chicago', maxAttendees= 50, startDate= u'2016-11-15T05:00:00.000Z', endDate= u'2016-12-03T05:00:00.000Z'), ConferenceForm( name= u'ff', description= u'Seis', topics= [u'Medical Innovations', u'Movie Making'], city= u'London', maxAttendees= 60, startDate= u'2016-11-28T05:00:00.000Z', endDate= u'2016-12-05T05:00:00.000Z'), ConferenceForm( name= u'gg', description= u'Siete', topics= [u'Health and Nutrition', u'Programming Languages'], city= u'Paris', maxAttendees= 70, startDate= u'2016-12-08T05:00:00.000Z', endDate= u'2016-12-25T05:00:00.000Z') ] for conf in confs: self._createConferenceObject(conf) conferences = Conference.query() # return set of ConferenceForm objects per Conference return ConferenceForms( items=[self._copyConferenceToForm(conf, None) for conf in conferences] )
def getConferenceByTopic(self, request): """Given a speaker, return all sessions given by this particular speaker, across all conferences""" conferences = Conference.query() conferences = conferences.filter(Conference.topics.IN([request.topic])) # return individual ConferenceForm object per Conference return ConferenceForms(items=[ self._copyConferenceToForm(conf, "") for conf in conferences ])
def filterPlayground(self, request): q = Conference.query() query = q.filter( ndb.AND(Conference.city == 'London', Conference.topics.IN(('Medical Innovations', )))) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in query])
def getConferencesToAttend(self, request): """Get list of conferences that user has registered for.""" profile = self._getProfileFromUser() wsck = profile.conferenceKeysToAttend conferenceKeys = [ndb.Key(urlsafe = wkey) for wkey in wsck] conferences = ndb.get_multi(conferenceKeys) return ConferenceForms(items=[self._copyConferenceToForm(conf, "")\ for conf in conferences])
def queryConferences(self, request): """Query for conferences.""" conferences = self._getQuery(request) # return individual ConferenceForm object per Conference return ConferenceForms(items=[ self._copyConferenceToForm(conf, "") for conf in conferences ])
def getConferencesWithSeats(self, request): """Return conferences that have available seats.""" # we want conferences with registered attendees < max# attendees confs = Conference.query().filter(Conference.seatsAvailable > 0) # return set of ConferenceForm objects per Conference return ConferenceForms( items=[self._copyConferenceToForm(conf) for conf in confs])
def filterPlayground(self, request): q = Conference.query() # simple filter usage: q = q.filter(Conference.city == "London") q = q.filter(Conference.topics == "Medical Innovations") return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q] )
def filterPlayground(self, request): q = Conference.query() q = q.filter(Conference.city == "London") q = q.filter(Conference.topic == "Medical Innovations") q = q.order(Conference.name) q = q.filter(Conference.month == 6) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q])
def filterPlayground3(self, request): """Filter Experimentation #3 - Get Conferences in certain city""" q = Conference.query() q = q.order(Conference.city) q = q.filter(Conference.city == request.city) return ConferenceForms( items=[self._copyConferenceToForm(i, "") for i in q] )
def filterPlayground(self, request): """Queries all conferences in LOndon with 'Medical Innovations' as the topic and a maximum attendance greater than ten.""" q = Conference.query() q = q.filter(Conference.city == 'London') q = q.filter(Conference.topics == 'Medical Innovations') q = q.order(Conference.name) q = q.filter(Conference.maxAttendees > 10) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q])
def queryConferences(self, request): """Query for conferences.""" conferences = self._getQuery(request) # for every conference in Conference Kind, copy the properties into # conferene form and store all forms into ConferenceForms return ConferenceForms( items=[self._copyConferenceToForm(conf, "") \ for conf in conferences] )
def filterPlayground(self, request): f = ndb.query.FilterNode("city", "=", "London") f2 = ndb.query.FilterNode("topics", "=", "Medical Innovations") q = Conference.query().filter(f) \ .filter(f2) \ .filter(Conference.maxAttendees > 10) \ .order(Conference.name) return ConferenceForms( items=[self._copyConferenceToForm(conf, "") for conf in q])
def getConferencesCreated(self, request): user = endpoints.get_current_user() if not user: raise endpoints.UnauthorizedException('Authorization required') user_id = getUserId(user) confs = Conference.query(ancestor=ndb.Key(Profile, user_id)) prof = p_key.get() displayName = getattr(prof, 'displayName') return ConferenceForms( items=[self._copyConferenceToForm(conf, displayName) for conf in confs] )
def queryConferences(self, request): """ Query for conferences. """ conferences = self._getQuery(request) names = self._getConferenceOrganisers(conferences) # return individual ConferenceForm object per Conference return ConferenceForms(items=[ self._copyConferenceToForm(conf, names[conf.organizerUserId]) for conf in conferences ])