Пример #1
0
 def test_field_query_not_is_monoargument(self):
     parser = ParseSQ()
     query = parser.parse("NOT one two", ["fullname", "username"])
     self.assertEqual(
         clean(query),
         "(AND: (NOT (AND: (OR: ('fullname', 'one'), ('username', 'one')))), (OR: ('fullname', 'two'), ('username', 'two')))"
     )
Пример #2
0
 def test_field_query_or(self):
     parser = ParseSQ()
     query = parser.parse("one OR two", ["fullname", "username"])
     self.assertEqual(
         clean(query),
         "(OR: ('fullname', 'one'), ('username', 'one'), ('fullname', 'two'), ('username', 'two'))"
     )
Пример #3
0
def searchResource(querytext, request, pagenum=1, maxresults=30, staff=False, scope=None, orderby=('-creation_date',)):
    sqs = SearchQuerySet().models(CatalogueResource).all()

    if len(querytext) > 0:
        parser = ParseSQ()
        query = parser.parse(querytext, CONTENT_FIELDS)
        # If there's any query
        if len(query) > 0:
            sqs = sqs.filter(query)

    sqs = sqs.order_by(*orderby).group_by("group_field", order_by='-version_sortable')

    # Filter resource type
    if scope is not None and len(scope) > 0:
        q = Q(type='_%s_' % scope.pop())
        for s in scope:
            q |= Q(type='_%s_' % s)
        sqs = sqs.filter(q)

    # Filter available only
    if not staff:
        q = Q(public=True) | Q(users=request.user.id)

        # Add group filters
        for group in request.user.groups.values_list('id', flat=True):
            q |= Q(groups=group)
        sqs = sqs.filter(q)

    # Build response data
    return buildSearchResults(sqs, pagenum, maxresults, cleanResults, request)
Пример #4
0
 def test_field_query_single_quotes(self):
     parser = ParseSQ()
     query = parser.parse("'several words whitespace'",
                          ["fullname", "username"])
     self.assertEqual(
         clean(query),
         "(AND: ('content__exact', 'several words whitespace'))")
Пример #5
0
def searchResource(querytext, request, pagenum=1, maxresults=30, staff=False, scope=None, orderby=('-creation_date',)):
    sqs = SearchQuerySet().models(CatalogueResource).all()

    if len(querytext) > 0:
        parser = ParseSQ()
        query = parser.parse(querytext, CONTENT_FIELDS)
        # If there's any query
        if len(query) > 0:
            sqs = sqs.filter(query)

    sqs = sqs.order_by(*orderby).group_by("group_field", order_by='-version_sortable')

    # Filter resource type
    if scope is not None and len(scope) > 0:
        q = Q(type='_%s_' % scope.pop())
        for s in scope:
            q |= Q(type='_%s_' % s)
        sqs = sqs.filter(q)

    # Filter available only
    if not staff:
        q = Q(public=True) | Q(users=request.user.id)

        # Add group filters
        for group in request.user.groups.values_list('id', flat=True):
            q |= Q(groups=group)
        sqs = sqs.filter(q)

    # Build response data
    return buildSearchResults(sqs, pagenum, maxresults, cleanResults, request)
Пример #6
0
 def test_field_query_multiple_word(self):
     parser = ParseSQ()
     query = parser.parse("one two", ["fullname", "username"])
     self.assertEqual(
         clean(query),
         "(AND: (OR: ('fullname', 'one'), ('username', 'one')), (OR: ('fullname', 'two'), ('username', 'two')))"
     )
Пример #7
0
def searchWorkspace(request, querytext, pagenum, maxresults, orderby=None):
    sqs = SearchQuerySet().models(Workspace).all()

    # Only searchable results
    sqs = sqs.filter(searchable=1)

    if len(querytext) > 0:
        parser = ParseSQ()
        query = parser.parse(querytext, CONTENT_FIELDS)

        # If there's any query
        if len(query) > 0:
            sqs = sqs.filter(query)

    q = Q(public=True)
    if request.user.is_authenticated():
        q |= Q(users=request.user.username)

        for group in request.user.groups.values_list("name", flat=True):
            q |= Q(groups=group)
    sqs = sqs.filter(q)

    if orderby is not None:
        sqs = sqs.order_by(*orderby)

    # Build response data
    return buildSearchResults(sqs, pagenum, maxresults, cleanResults)
Пример #8
0
 def test_field_query_nested_brakets(self):
     parser = ParseSQ()
     query = parser.parse("(one OR (two AND NOT four)) AND three",
                          ["fullname", "username"])
     self.assertEqual(
         clean(query),
         "(AND: (OR: ('fullname', 'one'), ('username', 'one'), (AND: (OR: ('fullname', 'two'), ('username', 'two')), (NOT (AND: (OR: ('fullname', 'four'), ('username', 'four')))))), (OR: ('fullname', 'three'), ('username', 'three')))"
     )
Пример #9
0
    def test_field_query_unbalanced_braket(self):
        parser = ParseSQ()
        with self.assertRaises(NoMatchingBracketsFound) as cm:
            parser.parse("(one OR two AND three", ["fullname", "username"])

        self.assertEqual(
            "%s" % cm.exception,
            "Matching brackets were not found: (one OR two AND three")
Пример #10
0
def searchGroup(request, querytext, pagenum, maxresults, orderby=None):
    sqs = SearchQuerySet().models(Group).all()
    if len(querytext) > 0:
        parser = ParseSQ()
        sqs = sqs.filter(parser.parse(querytext, GROUP_CONTENT_FIELDS))

    if orderby is not None:
        sqs = sqs.order_by(*orderby)

    return buildSearchResults(sqs, pagenum, maxresults, cleanGroupResults)
Пример #11
0
def searchGroup(request, querytext, pagenum, maxresults, orderby=None):
    sqs = SearchQuerySet().models(Group).all()
    if len(querytext) > 0:
        parser = ParseSQ()
        sqs = sqs.filter(parser.parse(querytext, GROUP_CONTENT_FIELDS))

    if orderby is not None:
        sqs = sqs.order_by(*orderby)

    return buildSearchResults(sqs, pagenum, maxresults, cleanGroupResults)
Пример #12
0
def searchWorkspace(request, querytext, pagenum, maxresults, orderby=None):
    sqs = SearchQuerySet().models(Workspace).all()

    # Only searchable results
    sqs = sqs.filter(searchable=1)

    if len(querytext) > 0:
        parser = ParseSQ()
        query = parser.parse(querytext, CONTENT_FIELDS)

        # If there's any query
        if len(query) > 0:
            sqs = sqs.filter(query)

    q = Q(public=True) | Q(users=request.user.username)
    for group in request.user.groups.values_list("name", flat=True):
        q |= Q(groups=group)
    sqs = sqs.filter(q)

    if orderby is not None:
        sqs = sqs.order_by(*orderby)

    # Build response data
    return buildSearchResults(sqs, pagenum, maxresults, cleanResults)
Пример #13
0
 def test_field_query_nested_brakets(self):
     parser = ParseSQ()
     query = parser.parse("(one OR (two AND NOT four)) AND three", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: (OR: ('fullname', 'one'), ('username', 'one'), (AND: (OR: ('fullname', 'two'), ('username', 'two')), (NOT (AND: (OR: ('fullname', 'four'), ('username', 'four')))))), (OR: ('fullname', 'three'), ('username', 'three')))")
Пример #14
0
 def test_field_query_multiple_word(self):
     parser = ParseSQ()
     query = parser.parse("one two", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: (OR: ('fullname', 'one'), ('username', 'one')), (OR: ('fullname', 'two'), ('username', 'two')))")
Пример #15
0
 def test_field_query_or(self):
     parser = ParseSQ()
     query = parser.parse("one OR two", ["fullname", "username"])
     self.assertEqual(clean(query), "(OR: ('fullname', 'one'), ('username', 'one'), ('fullname', 'two'), ('username', 'two'))")
Пример #16
0
 def test_field_query_not_is_monoargument(self):
     parser = ParseSQ()
     query = parser.parse("NOT one two", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: (NOT (AND: (OR: ('fullname', 'one'), ('username', 'one')))), (OR: ('fullname', 'two'), ('username', 'two')))")
Пример #17
0
 def test_field_query_single_quotes(self):
     parser = ParseSQ()
     query = parser.parse("'several words whitespace'", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('content__exact', 'several words whitespace'))")
Пример #18
0
 def test_field_query_exact_single_quotes(self):
     parser = ParseSQ()
     query = parser.parse("fullname:'normal'", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('fullname__exact', 'normal'))")
Пример #19
0
 def test_field_query_exact(self):
     parser = ParseSQ()
     query = parser.parse('fullname:"normal"', ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('fullname__exact', 'normal'))")
Пример #20
0
 def test_field_query(self):
     parser = ParseSQ()
     query = parser.parse("fullname:normal", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('fullname', 'normal'))")
Пример #21
0
 def test_normal_query(self):
     parser = ParseSQ()
     query = parser.parse("normal", ["fullname", "username"])
     self.assertEqual(clean(query), "(OR: ('fullname', 'normal'), ('username', 'normal'))")
Пример #22
0
 def test_searchUser_emptyquery(self):
     parser = ParseSQ()
     query = parser.parse("", ["fullname", "username"])
Пример #23
0
 def test_normal_query(self):
     parser = ParseSQ()
     query = parser.parse("normal", ["fullname", "username"])
     self.assertEqual(
         clean(query),
         "(OR: ('fullname', 'normal'), ('username', 'normal'))")
Пример #24
0
 def test_searchUser_emptyquery(self):
     parser = ParseSQ()
     query = parser.parse("", ["fullname", "username"])
Пример #25
0
 def test_field_query(self):
     parser = ParseSQ()
     query = parser.parse("fullname:normal", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('fullname', 'normal'))")
Пример #26
0
    def test_field_query_unbalanced_braket(self):
        parser = ParseSQ()
        with self.assertRaises(NoMatchingBracketsFound) as cm:
            parser.parse("(one OR two AND three", ["fullname", "username"])

        self.assertEqual("%s" % cm.exception, "Matching brackets were not found: (one OR two AND three")
Пример #27
0
 def test_field_query_exact(self):
     parser = ParseSQ()
     query = parser.parse('fullname:"normal"', ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('fullname__exact', 'normal'))")
Пример #28
0
 def test_field_query_exact_single_quotes(self):
     parser = ParseSQ()
     query = parser.parse("fullname:'normal'", ["fullname", "username"])
     self.assertEqual(clean(query), "(AND: ('fullname__exact', 'normal'))")