def _query(request): """ Return formatted query from the submitted filters. :param request: :return: """ return queryutil.query(request)
def query(self, request): """ Queries Session objects in datastore :param request: :return: """ ancestor = None if request.ancestorWebSafeKey: ancestor = ndb.Key(urlsafe=request.ancestorWebSafeKey) sessions = queryutil.query(request, ancestor=ancestor) return SessionForms(items=self.populate_forms(sessions))
def query(self, request): """ Query Conferences in Datastore :param request: ConferenceQueryForms with one or many ConferenceQueryForm's :return: ConferenceForms with matching ConferenceForm's, if any """ # convert message types for now until we fix the js client side logic query_filters = [ queryutil.QueryFilter( field=f.field, operator=queryutil.QueryOperator.lookup_by_name(f.operator), value=f.value) for f in request.filters] query_form = queryutil.QueryForm( target=queryutil.QueryTarget.CONFERENCE, filters=query_filters) conferences = queryutil.query(query_form) # need to fetch organiser displayName from profiles # get all keys and use get_multi for speed organisers = [(ndb.Key(Profile, conf.organizerUserId)) for conf in conferences] profiles = ndb.get_multi(organisers) if not profiles or profiles == [None]: # bootstrapping issue as the user hasn't created their profile obj profiles = [Profile(key=org) for org in organisers] # put display names in a dict for easier fetching names = {} for profile in profiles: if hasattr(profile, 'displayName'): names[profile.key.id()] = getattr(profile, 'displayName') else: # Chances are someone wasn't forced to set their displayName yet names[profile.key.id()] = '' # return individual ConferenceForm object per Conference return ConferenceForms( items=[conf.to_form(names[conf.organizerUserId]) for conf in conferences] )
def filter_playground(self, request): """ Filter Playground method :param request: :return: """ if not isinstance(request, message_types.VoidMessage): raise endpoints.BadRequestException() form = queryutil.QueryForm() form.target = queryutil.QueryTarget.CONFERENCE qfilter = queryutil.QueryFilter( field='CITY', operator=queryutil.QueryOperator.EQ, value='London' ) form.filters = [qfilter] q = queryutil.query(form) return ConferenceForms(items=[conf.to_form() for conf in q])
def query_demo(self, request): """ Queries Session objects in datastore :param request: :return: """ if not isinstance(request, VoidMessage): raise endpoints.BadRequestException() query_form = queryutil.QueryForm(target=queryutil.QueryTarget.SESSION) query_form.filters.append( queryutil.QueryFilter(field='TYPE', operator=queryutil.QueryOperator.NE, value='WORKSHOP')) query_form.filters.append( queryutil.QueryFilter(field='START_TIME', operator=queryutil.QueryOperator.LT, value='19:00')) sessions = queryutil.query(query_form) return SessionForms(items=self.populate_forms(sessions))
def query_demo(self, request): """ Queries Session objects in datastore :param request: :return: """ if not isinstance(request, VoidMessage): raise endpoints.BadRequestException() query_form = queryutil.QueryForm(target=queryutil.QueryTarget.SESSION) query_form.filters.append(queryutil.QueryFilter( field='TYPE', operator=queryutil.QueryOperator.NE, value='WORKSHOP' )) query_form.filters.append(queryutil.QueryFilter( field='START_TIME', operator=queryutil.QueryOperator.LT, value='19:00' )) sessions = queryutil.query(query_form) return SessionForms(items=self.populate_forms(sessions))