当前位置: 首页>>代码示例>>Python>>正文


Python where.WhereNode类代码示例

本文整理汇总了Python中django.db.models.sql.where.WhereNode的典型用法代码示例。如果您正苦于以下问题:Python WhereNode类的具体用法?Python WhereNode怎么用?Python WhereNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WhereNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_or

 def test_or(self):
     where = WhereNode()
     where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND)
     where.add((Constraint("givenName", "givenName", CharField()), 'exact',
                "bar"), OR)
     self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(givenName=bar))",
                                              []))
开发者ID:KayoticSully,项目名称:django-ldapdb,代码行数:7,代码来源:tests.py

示例2: as_sql

    def as_sql(self, compiler, connection):
        if isinstance(self.lhs, MultiColSource):
            # For multicolumn lookups we need to build a multicolumn where clause.
            # This clause is either a SubqueryConstraint (for values that need to be compiled to
            # SQL) or a OR-combined list of (col1 = val1 AND col2 = val2 AND ...) clauses.
            from django.db.models.sql.where import WhereNode, SubqueryConstraint, AND, OR

            root_constraint = WhereNode(connector=OR)
            if self.rhs_is_direct_value():
                values = [get_normalized_value(value, self.lhs) for value in self.rhs]
                for value in values:
                    value_constraint = WhereNode()
                    for source, target, val in zip(self.lhs.sources, self.lhs.targets, value):
                        lookup_class = target.get_lookup('exact')
                        lookup = lookup_class(target.get_col(self.lhs.alias, source), val)
                        value_constraint.add(lookup, AND)
                    root_constraint.add(value_constraint, OR)
            else:
                root_constraint.add(
                    SubqueryConstraint(
                        self.lhs.alias, [target.column for target in self.lhs.targets],
                        [source.name for source in self.lhs.sources], self.rhs),
                    AND)
            return root_constraint.as_sql(compiler, connection)
        else:
            return super(RelatedIn, self).as_sql(compiler, connection)
开发者ID:nbsky,项目名称:django,代码行数:26,代码来源:related_lookups.py

示例3: as_sql

 def as_sql(self, compiler, connection):
     if isinstance(self.lhs, MultiColSource):
         assert self.rhs_is_direct_value()
         self.rhs = get_normalized_value(self.rhs, self.lhs)
         from django.db.models.sql.where import WhereNode, AND
         root_constraint = WhereNode()
         for target, source, val in zip(self.lhs.targets, self.lhs.sources, self.rhs):
             lookup_class = target.get_lookup(self.lookup_name)
             root_constraint.add(
                 lookup_class(target.get_col(self.lhs.alias, source), val), AND)
         return root_constraint.as_sql(compiler, connection)
     return super().as_sql(compiler, connection)
开发者ID:100448facens,项目名称:django-example-jn,代码行数:12,代码来源:related_lookups.py

示例4: test_float_field

    def test_float_field(self):
        where = WhereNode()
        where.add((Constraint("uid", "uid", FloatField()), 'exact', 1.2), AND)
        self.assertEquals(where_as_ldap(where), ("(uid=1.2)", []))

        where = WhereNode()
        where.add((Constraint("uid", "uid", FloatField()), 'gte', 1.2), AND)
        self.assertEquals(where_as_ldap(where), ("(uid>=1.2)", []))

        where = WhereNode()
        where.add((Constraint("uid", "uid", FloatField()), 'lte', 1.2), AND)
        self.assertEquals(where_as_ldap(where), ("(uid<=1.2)", []))
开发者ID:KayoticSully,项目名称:django-ldapdb,代码行数:12,代码来源:tests.py

示例5: test_integer_field

    def test_integer_field(self):
        where = WhereNode()
        where.add(self._build_lookup("uid", 'exact', 1, field=IntegerField), AND)
        self.assertEqual(where_as_ldap(where), "(uid=1)")

        where = WhereNode()
        where.add(self._build_lookup("uid", 'gte', 1, field=IntegerField), AND)
        self.assertEqual(where_as_ldap(where), "(uid>=1)")

        where = WhereNode()
        where.add(self._build_lookup("uid", 'lte', 1, field=IntegerField), AND)
        self.assertEqual(where_as_ldap(where), "(uid<=1)")
开发者ID:remche,项目名称:django-ldapdb,代码行数:12,代码来源:tests.py

示例6: test_integer_field

    def test_integer_field(self):
        where = WhereNode()
        where.add((Constraint("uid", "uid", IntegerField()), 'exact', 1), AND)
        self.assertEquals(where_as_ldap(where), ("(uid=1)", []))

        where = WhereNode()
        where.add((Constraint("uid", "uid", IntegerField()), 'gte', 1), AND)
        self.assertEquals(where_as_ldap(where), ("(uid>=1)", []))

        where = WhereNode()
        where.add((Constraint("uid", "uid", IntegerField()), 'lte', 1), AND)
        self.assertEquals(where_as_ldap(where), ("(uid<=1)", []))
开发者ID:KayoticSully,项目名称:django-ldapdb,代码行数:12,代码来源:tests.py

示例7: test_float_field

    def test_float_field(self):
        where = WhereNode()
        where.add(self._build_lookup("uid", 'exact', 1.2, field=FloatField), AND)
        self.assertEqual(where_as_ldap(where), "(uid=1.2)")

        where = WhereNode()
        where.add(self._build_lookup("uid", 'gte', 1.2, field=FloatField), AND)
        self.assertEqual(where_as_ldap(where), "(uid>=1.2)")

        where = WhereNode()
        where.add(self._build_lookup("uid", 'lte', 1.2, field=FloatField), AND)
        self.assertEqual(where_as_ldap(where), "(uid<=1.2)")
开发者ID:remche,项目名称:django-ldapdb,代码行数:12,代码来源:tests.py

示例8: test_datetime_field

    def test_datetime_field(self):
        dt = datetime.datetime(2018, 6, 25, 20, 21, 22, tzinfo=UTC)

        where = WhereNode()
        where.add(self._build_lookup("modifyTimestamp", 'exact', dt, field=fields.DateTimeField,), AND)
        self.assertEqual(self._where_as_ldap(where), "(modifyTimestamp=20180625202122.000000Z)")

        where = WhereNode()
        where.add(self._build_lookup("modifyTimestamp", 'lte', dt, field=fields.DateTimeField,), AND)
        self.assertEqual(self._where_as_ldap(where), "(modifyTimestamp<=20180625202122.000000Z)")

        where = WhereNode()
        where.add(self._build_lookup("modifyTimestamp", 'gte', dt, field=fields.DateTimeField,), AND)
        self.assertEqual(self._where_as_ldap(where), "(modifyTimestamp>=20180625202122.000000Z)")
开发者ID:rbarrois,项目名称:django-ldapdb,代码行数:14,代码来源:tests.py

示例9: test_char_field_contains

    def test_char_field_contains(self):
        where = WhereNode()
        where.add(self._build_lookup("cn", 'contains', "test"), AND)
        self.assertEqual(where_as_ldap(where), "(cn=*test*)")

        where = WhereNode()
        where.add(self._build_lookup("cn", 'contains', "te*st"), AND)
        self.assertEqual(where_as_ldap(where), "(cn=*te\\2ast*)")
开发者ID:remche,项目名称:django-ldapdb,代码行数:8,代码来源:tests.py

示例10: test_char_field_in

    def test_char_field_in(self):
        where = WhereNode()
        where.add(self._build_lookup("cn", 'in', ["foo", "bar"]), AND)
        self.assertEqual(where_as_ldap(where), "(|(cn=foo)(cn=bar))")

        where = WhereNode()
        where.add(self._build_lookup("cn", 'in', ["(foo)", "(bar)"]), AND)
        self.assertEqual(where_as_ldap(where), "(|(cn=\\28foo\\29)(cn=\\28bar\\29))")
开发者ID:remche,项目名称:django-ldapdb,代码行数:8,代码来源:tests.py

示例11: test_char_field_endswith

    def test_char_field_endswith(self):
        where = WhereNode()
        where.add(self._build_lookup("cn", 'endswith', "test"), AND)
        self.assertEqual(where_as_ldap(where), "(cn=*test)")

        where = WhereNode()
        where.add(self._build_lookup("cn", 'endswith', "te*st"), AND)
        self.assertEqual(where_as_ldap(where), "(cn=*te\\2ast)")
开发者ID:remche,项目名称:django-ldapdb,代码行数:8,代码来源:tests.py

示例12: test_list_field_contains

    def test_list_field_contains(self):
        where = WhereNode()
        where.add(self._build_lookup("memberUid", 'contains', 'foouser', field=ListField), AND)
        self.assertEqual(where_as_ldap(where), "(memberUid=foouser)")

        where = WhereNode()
        where.add(self._build_lookup("memberUid", 'contains', '(foouser)', field=ListField), AND)
        self.assertEqual(where_as_ldap(where), "(memberUid=\\28foouser\\29)")
开发者ID:remche,项目名称:django-ldapdb,代码行数:8,代码来源:tests.py

示例13: test_char_field_exact

    def test_char_field_exact(self):
        where = WhereNode()
        where.add(self._build_lookup('cn', 'exact', "test"), AND)
        self.assertEqual(where_as_ldap(where), "(cn=test)")

        where = WhereNode()
        where.add(self._build_lookup('cn', 'exact', "(test)"), AND)
        self.assertEqual(where_as_ldap(where), "(cn=\\28test\\29)")
开发者ID:remche,项目名称:django-ldapdb,代码行数:8,代码来源:tests.py

示例14: test_list_field_startswith

    def test_list_field_startswith(self):
        where = WhereNode()
        where.add((Constraint("cn", "cn", ListField()), 'startswith', "test"), AND)
        self.assertEquals(where_as_ldap(where), ("(cn=test*)", []))

        where = WhereNode()
        where.add((Constraint("cn", "cn", ListField()), 'startswith', "te*st"), AND)
        self.assertEquals(where_as_ldap(where), ("(cn=te\\2ast*)", []))
开发者ID:unistra,项目名称:django-ldapdb,代码行数:8,代码来源:tests.py

示例15: test_list_field_contains

    def test_list_field_contains(self):
        where = WhereNode()
        where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', 'foouser'), AND)
        self.assertEquals(where_as_ldap(where), ("(memberUid=foouser)", []))

        where = WhereNode()
        where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', '(foouser)'), AND)
        self.assertEquals(where_as_ldap(where), ("(memberUid=\\28foouser\\29)", []))
开发者ID:Ozzee,项目名称:password-safe-django,代码行数:8,代码来源:tests.py


注:本文中的django.db.models.sql.where.WhereNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。