Exemple #1
0
 def contains(self, value):
     if isinstance(value, dict):
         expression = SqlExpression(self.field, "@>", value)
     elif isinstance(value, (list, tuple)):
         expression = SqlExpression(self.field, "?&", value)
     elif isinstance(value, basestring):
         expression = SqlExpression(self.field, "?", value)
     else:
         raise ValueError("Invalid value")
     return expression
    def test_join_lookup_with_expression_03(self):
        node1 = Node.objects.create(name="master1")
        node2 = Node.objects.create(name="master2")
        node3 = Node.objects.create(name="child1", parent=node1)
        node4 = Node.objects.create(name="child2", parent=node2)

        expr = OR(SqlExpression("parent__name", "=", "master1"),
                  SqlExpression("name", "=", "child1"))

        queryset = Node.objects.where(expr)
        self.assertEqual(queryset.count(), 1)
Exemple #3
0
    def test_overlap(self):
        obj1 = IntModel.objects.create(lista=[1, 2, 3])
        obj2 = IntModel.objects.create(lista=[2, 4, 5])
        obj3 = IntModel.objects.create(lista=[5, 33, 21])

        queryset = IntModel.objects.where(
            SqlExpression("lista", "&&", [1, 2, 3]))
        self.assertEqual(queryset.count(), 2)

        queryset = IntModel.objects.where(
            SqlExpression("lista", "&&", [1, 2, 3]))
        self.assertEqual(queryset.count(), 2)
Exemple #4
0
    def test_string_sample_statement(self):
        obj = Person.objects.create(name="jose")

        queryset = Person.objects.where(
            SqlExpression(BitLength("name"), "=", 32)
        )
        self.assertEqual(queryset.count(), 1)
    def test_join_lookup_with_expression_01(self):
        person = Person.objects.create(name="jose")
        profile = Profile.objects.create(person=person)

        queryset = Profile.objects.where(
            SqlExpression(BitLength("person__name"), "=", 32))
        self.assertEqual(queryset.count(), 1)
Exemple #6
0
    def test_contains_unicode(self):
        obj = TextModel.objects\
            .create(lista=[u"Fóö", u"Пример", u"test"])

        queryset = TextModel.objects.where(
            SqlExpression("lista", "@>", [u"Пример"]))
        self.assertEqual(queryset.count(), 1)
Exemple #7
0
    def get_results(self):
        news = News.objects.filter(
            subject__icontains=self.cleaned_data['query']).order_by('-created_at')

        query_string_args = self.cleaned_data['query'].split(':')

        if query_string_args[0] == 'tags':
            tags = map(lambda t: t.strip(), flatten(map(lambda t: t.split(','), query_string_args[1:])))
            events = Event.objects.where(SqlExpression("tags", "@>", tags))
        else:
            events = Event.objects.filter(
                title__icontains=self.cleaned_data['query']).order_by('-date')

        return news, events
Exemple #8
0
    def test_join_overlap_circle(self):
        c_instance_0 = CircleObjectModel.objects.create(
            carea=Circle([1, 1], 5))
        c_instance_1 = CircleObjectModel.objects.create(
            carea=Circle([-2, -2], 1))

        BoxObjectModel.objects.bulk_create([
            BoxObjectModel(barea=Box([1, 1], [3, 2]), other=c_instance_0),
            BoxObjectModel(barea=Box([2, 2], [4, 7]), other=c_instance_0),
            BoxObjectModel(barea=Box([10, 10], [20, 20]), other=c_instance_1)
        ])

        qs = BoxObjectModel.objects.where(
            SqlExpression("other__carea", "&&", Circle([2, 2], 2)))
        self.assertEqual(qs.count(), 2)
        """
Exemple #9
0
    def test_simple_contains(self):
        SomeObject.objects.bulk_create([
            SomeObject(pos=Point(1, 1)),
            SomeObject(pos=Point(2, 2)),
            SomeObject(pos=Point(1, 5)),
            SomeObject(pos=Point(3, 4)),
        ])

        # simple sql expresion.
        qs = SomeObject.objects.where(
            SqlExpression("pos", "<@", Box([1, 1], [4, 4])))
        self.assertEqual(qs.count(), 3)

        # builtin helper
        qs = SomeObject.objects.where(
            GeoExpression("pos").contained_on(Box([1, 1], [4, 4])))
        self.assertEqual(qs.count(), 3)
Exemple #10
0
    def test_simple_overlap(self):
        BoxObjectModel.objects.bulk_create([
            BoxObjectModel(barea=Box([1, 1], [3, 2])),
            BoxObjectModel(barea=Box([2, 2], [4, 7])),
            BoxObjectModel(barea=Box([10, 10], [20, 20])),
            BoxObjectModel(barea=Box([-1, -4], [-5, -2])),
        ])

        # simple sql expression
        qs = BoxObjectModel.objects.where(
            SqlExpression("barea", "&&", Box([2, 0], [5, 3])))
        self.assertEqual(qs.count(), 2)

        # builtin helper
        qs = BoxObjectModel.objects.where(
            GeoExpression("barea").overlaps(Box([2, 0], [5, 3])))
        self.assertEqual(qs.count(), 2)
Exemple #11
0
 def same_as(self, value):
     return SqlExpression(self.field, "~=", value)
Exemple #12
0
 def is_parallel_to(self, value):
     return SqlExpression(self.field, "?||", value)
Exemple #13
0
 def is_perpendicular_to(self, value):
     return SqlExpression(self.field, "?-|", value)
Exemple #14
0
 def is_vertical_aligned(self):
     return SqlExpression(self.field, "?|", value)
Exemple #15
0
 def is_horizontal_aligned(self, value):
     return SqlExpression(self.field, "?-", value)
Exemple #16
0
 def contained_on(self, value):
     return SqlExpression(self.field, "<@", value)
Exemple #17
0
 def is_strictly_left_of(self, value):
     return SqlExpression(self.field, "<<", value)
Exemple #18
0
 def intersects_with(self, value):
     return SqlExpression(self.field, "?#", value)
Exemple #19
0
 def does_not_extend_left(self, value):
     return SqlExpression(self.field, "&>", value)
Exemple #20
0
 def does_not_extend_right(self, value):
     return SqlExpression(self.field, "&<", value)
Exemple #21
0
 def does_not_extend_above(self, value):
     return SqlExpression(self.field, "&<|", value)
Exemple #22
0
 def is_strictly_right_of(self, value):
     return SqlExpression(self.field, ">>", value)
Exemple #23
0
 def exact(self, value):
     return SqlExpression(self.field, "=", value)
Exemple #24
0
 def contains(self, value):
     return SqlExpression(self.field, "@>", value)
Exemple #25
0
 def does_not_extend_below(self, value):
     return SqlExpression(self.field, "|&>", value)
Exemple #26
0
 def overlaps(self, value):
     return SqlExpression(self.field, "&&", value)