Пример #1
0
    def get_search(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        # Do the query.
        q = request.GET.get('q', '')
        mod = request.GET.get('mod', 'default')
        sqs = SearchQuerySet().models(Model).load_all().filter(text=Raw(convert_free_search(q, mod)))
        sqs = filter(None, sqs)
        paginator = Paginator(sqs, 20)

        try:
            page = paginator.page(int(request.GET.get('page', 1)))
        except InvalidPage:
            raise Http404("Sorry, no results on that page.")

        objects = []

        for result in page.object_list:
            bundle = self.build_bundle(obj=result.object, request=request)
            bundle = self.full_dehydrate(bundle)
            objects.append(bundle)

        object_list = {
            'objects': objects,
            'meta': {'total_count': len(sqs)}
        }

        self.log_throttled_access(request)
        return self.create_response(request, object_list)
Пример #2
0
 def get_results(self):
     q = self.request.GET.get('q')
     if q is not None:
         search_term = convert_free_search(q)
         return SearchQuerySet().models(Person, Organization).filter(
             SQ(text=Raw(search_term)) | SQ(name=Raw(search_term))
             | SQ(address=Raw(search_term)) | SQ(contact=Raw(search_term))
             | SQ(ldap_username=Raw(search_term)))
     return []
Пример #3
0
 def get_results(self):
     q = self.request.GET.get('q')
     if q is not None:
         search_term = convert_free_search(q)
         return SearchQuerySet().models(Person, Organization).filter(
             SQ(text=Raw(search_term)) |
             SQ(name=Raw(search_term)) |
             SQ(address=Raw(search_term)) |
             SQ(contact=Raw(search_term)) |
             SQ(ldap_username=Raw(search_term))
         )
     return []