コード例 #1
0
 def _query(request):
     """
     Return formatted query from the submitted filters.
     :param request:
     :return:
     """
     return queryutil.query(request)
コード例 #2
0
ファイル: session.py プロジェクト: voutilad/udacity-project4
    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))
コード例 #3
0
ファイル: session.py プロジェクト: voutilad/udacity-project4
    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))
コード例 #4
0
    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]
        )
コード例 #5
0
    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])
コード例 #6
0
ファイル: session.py プロジェクト: voutilad/udacity-project4
    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))
コード例 #7
0
ファイル: session.py プロジェクト: voutilad/udacity-project4
    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))