Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

trying to make some sense of this

  • Loading branch information...
commit 449862a301f1a2c4b2e9cf67a0ad7654ec228859 1 parent 7865bc3
@ojii authored
Showing with 26 additions and 1 deletion.
  1. +11 −1 nani/manager.py
  2. +15 −0 nani/tests/query.py
View
12 nani/manager.py
@@ -238,7 +238,17 @@ def __getitem__(self, k):
Therefore the check for _language_code must be done here.
"""
if not self._language_code:
- return self.language().__getitem__(k)
+ """
+ Do NOT call language(). Because language calls filter which calls
+ _filter_or_exclude which calls _clone. __getitem__ should NOT clone
+ the query. Therefore we emulate _filter_or_exclude by adding a Q
+ object to the query of THIS queryset (instead of cloning the
+ queryset, and adding the Q object to the cloned queryset, which is
+ what happens in language()).
+ """
+ #return self.language().__getitem__(k)
+ self._language_code = get_language()
+ self.query.add_q(Q(language_code=self._language_code))
return super(TranslationQueryset, self).__getitem__(k)
def create(self, **kwargs):
View
15 nani/tests/query.py
@@ -50,6 +50,21 @@ def test_iter_unique_reply(self):
# Make sure .all() only returns unique rows
with LanguageOverride('en'):
self.assertEqual(len(Normal.objects.all()), len(Normal.objects.untranslated()))
+
+ def test_getitem(self):
+ with LanguageOverride('en'):
+ qs = Normal.objects.using_translations()
+ count = qs.count()
+ listqs = list(qs)
+ self.assertEqual(len(listqs), count)
+
+ def test_getitem_reversed(self):
+ with LanguageOverride('en'):
+ qs = Normal.objects.using_translations()
+ listqs = list(qs)
+ count = qs.count()
+ self.assertEqual(len(listqs), count)
+
class UpdateTests(NaniTestCase, TwoTranslatedNormalMixin):
def test_update_shared(self):
Please sign in to comment.
Something went wrong with that request. Please try again.