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


Python WhereNode.add方法代码示例

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


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

示例1: test_or

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
 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,代码行数:9,代码来源:tests.py

示例2: test_char_field_in

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    def test_char_field_in(self):
        where = WhereNode()
        where.add((Constraint("cn", "cn", CharField()), 'in', ["foo", "bar"]), AND)
        self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(cn=bar))", []))

        where = WhereNode()
        where.add((Constraint("cn", "cn", CharField()), 'in', ["(foo)", "(bar)"]), AND)
        self.assertEquals(where_as_ldap(where), ("(|(cn=\\28foo\\29)(cn=\\28bar\\29))", []))
开发者ID:Ozzee,项目名称:password-safe-django,代码行数:10,代码来源:tests.py

示例3: test_char_field_exact

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    def test_char_field_exact(self):
        where = WhereNode()
        where.add((Constraint("cn", "cn", CharField()), 'exact', "test"), AND)
        self.assertEquals(where_as_ldap(where), ("(cn=test)", []))

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

示例4: test_list_field_contains

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例5: test_char_field_contains

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    def test_char_field_contains(self):
        where = WhereNode()
        where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND)
        self.assertEquals(where_as_ldap(where), ("(cn=*test*)", []))

        where = WhereNode()
        where.add((Constraint("cn", "cn", CharField()), 'contains', "te*st"), AND)
        self.assertEquals(where_as_ldap(where), ("(cn=*te\\2ast*)", []))
开发者ID:Ozzee,项目名称:password-safe-django,代码行数:10,代码来源:tests.py

示例6: test_list_field_contains

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例7: test_char_field_in

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例8: test_char_field_contains

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例9: test_char_field_exact

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例10: test_list_field_startswith

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例11: test_char_field_endswith

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:10,代码来源:tests.py

示例12: test_char_field_endswith

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    def test_char_field_endswith(self):
        where = WhereNode()
        where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"),
                  AND)
        self.assertEqual(where_as_ldap(where), ("(cn=*test)", []))

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

示例13: as_sql

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
 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,代码行数:14,代码来源:related_lookups.py

示例14: as_sql

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    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,代码行数:28,代码来源:related_lookups.py

示例15: test_integer_field

# 需要导入模块: from django.db.models.sql.where import WhereNode [as 别名]
# 或者: from django.db.models.sql.where.WhereNode import add [as 别名]
    def test_integer_field(self):
        where = WhereNode()
        where.add(self._build_lookup("uid", 'exact', 1, field=fields.IntegerField), AND)
        self.assertEqual(self._where_as_ldap(where), "(uid=1)")

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

        where = WhereNode()
        where.add(self._build_lookup("uid", 'lte', 1, field=fields.IntegerField), AND)
        self.assertEqual(self._where_as_ldap(where), "(uid<=1)")

        where = WhereNode()
        where.add(self._build_lookup("uid", 'in', [1, 2], field=fields.IntegerField), AND)
        self.assertEqual(self._where_as_ldap(where), "(|(uid=1)(uid=2))")
开发者ID:rbarrois,项目名称:django-ldapdb,代码行数:18,代码来源:tests.py


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