Loading django/utils/tree.py +5 −6 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ ORM. import copy from django.utils.encoding import force_str, force_text class Node(object): """ Loading Loading @@ -42,14 +44,11 @@ class Node(object): return obj def __str__(self): if self.negated: return '(NOT (%s: %s))' % (self.connector, ', '.join(str(c) for c in self.children)) return '(%s: %s)' % (self.connector, ', '.join(str(c) for c in self.children)) template = '(NOT (%s: %s))' if self.negated else '(%s: %s)' return force_str(template % (self.connector, ', '.join(force_text(c) for c in self.children))) def __repr__(self): return "<%s: %s>" % (self.__class__.__name__, self) return str("<%s: %s>") % (self.__class__.__name__, self) def __deepcopy__(self, memodict): """ Loading tests/or_lookups/tests.py +8 −0 Original line number Diff line number Diff line # -*- encoding: utf-8 -*- from __future__ import unicode_literals from datetime import datetime Loading @@ -5,6 +6,7 @@ from operator import attrgetter from django.db.models import Q from django.test import TestCase from django.utils.encoding import force_str from .models import Article Loading Loading @@ -123,6 +125,12 @@ class OrLookupsTests(TestCase): attrgetter("headline"), ) def test_q_repr(self): or_expr = Q(baz=Article(headline="Foö")) self.assertEqual(repr(or_expr), force_str("<Q: (AND: ('baz', <Article: Foö>))>")) negated_or = ~Q(baz=Article(headline="Foö")) self.assertEqual(repr(negated_or), force_str("<Q: (NOT (AND: ('baz', <Article: Foö>)))>")) def test_q_negated(self): # Q objects can be negated self.assertQuerysetEqual( Loading Loading
django/utils/tree.py +5 −6 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ ORM. import copy from django.utils.encoding import force_str, force_text class Node(object): """ Loading Loading @@ -42,14 +44,11 @@ class Node(object): return obj def __str__(self): if self.negated: return '(NOT (%s: %s))' % (self.connector, ', '.join(str(c) for c in self.children)) return '(%s: %s)' % (self.connector, ', '.join(str(c) for c in self.children)) template = '(NOT (%s: %s))' if self.negated else '(%s: %s)' return force_str(template % (self.connector, ', '.join(force_text(c) for c in self.children))) def __repr__(self): return "<%s: %s>" % (self.__class__.__name__, self) return str("<%s: %s>") % (self.__class__.__name__, self) def __deepcopy__(self, memodict): """ Loading
tests/or_lookups/tests.py +8 −0 Original line number Diff line number Diff line # -*- encoding: utf-8 -*- from __future__ import unicode_literals from datetime import datetime Loading @@ -5,6 +6,7 @@ from operator import attrgetter from django.db.models import Q from django.test import TestCase from django.utils.encoding import force_str from .models import Article Loading Loading @@ -123,6 +125,12 @@ class OrLookupsTests(TestCase): attrgetter("headline"), ) def test_q_repr(self): or_expr = Q(baz=Article(headline="Foö")) self.assertEqual(repr(or_expr), force_str("<Q: (AND: ('baz', <Article: Foö>))>")) negated_or = ~Q(baz=Article(headline="Foö")) self.assertEqual(repr(negated_or), force_str("<Q: (NOT (AND: ('baz', <Article: Foö>)))>")) def test_q_negated(self): # Q objects can be negated self.assertQuerysetEqual( Loading