Esempio n. 1
0
 def test_query_bit(self):
     INPUT = 'normal__shared_field__exact'
     query_string, joins = translate(INPUT, Related)
     self.assertEqual(query_string, INPUT)
     self.assertEqual(joins, ['normal__translations__language_code'])
     INPUT = 'normal__translated_field__exact'
     query_string, joins = translate(INPUT, Related)
     self.assertEqual(query_string, 'normal__translations__translated_field__exact')
     self.assertEqual(joins, ['normal__translations__language_code'])
 def test_query_bit(self):
     INPUT = 'normal__shared_field__exact'
     query_string, joins = translate(INPUT, Related)
     self.assertEqual(query_string, INPUT)
     self.assertEqual(joins, ['normal__translations__language_code'])
     INPUT = 'normal__translated_field__exact'
     query_string, joins = translate(INPUT, Related)
     self.assertEqual(query_string,
                      'normal__translations__translated_field__exact')
     self.assertEqual(joins, ['normal__translations__language_code'])
Esempio n. 3
0
 def _translate_fieldnames(self, fields):
     self.language(self._language_code)
     newfields = []
     extra_filters = Q()
     language_joins = []
     for field in fields:
         newfield, langjoins = translate(field, self.model)
         newfields.append(newfield)
         for langjoin in langjoins:
             if langjoin not in language_joins:
                 language_joins.append(langjoin)
     for langjoin in language_joins:
         extra_filters &= Q(**{langjoin: self._language_code})
     return newfields, extra_filters
Esempio n. 4
0
 def _translate_fieldnames(self, fields):
     self.language(self._language_code)
     newfields = []
     extra_filters = Q()
     language_joins = []
     for field in fields:
         newfield, langjoins = translate(field, self.model)
         newfields.append(newfield)
         for langjoin in langjoins:
             if langjoin not in language_joins:
                 language_joins.append(langjoin)
     for langjoin in language_joins:
         extra_filters &= Q(**{langjoin: self._language_code})
     return newfields, extra_filters
Esempio n. 5
0
 def _recurse_q(self, q):
     newchildren = []
     language_joins = []
     for child in q.children:
         if isinstance(child, Q):
             newq = self._recurse_q(child)
             newchildren.append(self._recurse_q(newq))
         else:
             key, value = child
             newkey, langjoins = translate(key, self.model)
             newchildren.append((newkey, value))
             for langjoin in langjoins:
                 if langjoin not in language_joins:
                     language_joins.append(langjoin)
     q.children = newchildren
     return q, language_joins
Esempio n. 6
0
 def _recurse_q(self, q):
     newchildren =  []
     language_joins = []
     for child in q.children:
         if isinstance(child, Q):
             newq = self._recurse_q(child)
             newchildren.append(self._recurse_q(newq))
         else:
             key, value = child
             newkey, langjoins =translate(key, self.model)
             newchildren.append((newkey, value))
             for langjoin in langjoins:
                 if langjoin not in language_joins:
                     language_joins.append(langjoin)
     q.children = newchildren
     return q, language_joins
Esempio n. 7
0
 def _translate_args_kwargs(self, *args, **kwargs):
     self.language(self._language_code)
     language_joins = []
     newkwargs = {}
     extra_filters = Q()
     for key, value in kwargs.items():
         newkey, langjoins = translate(key, self.model)
         for langjoin in langjoins:
             if langjoin not in language_joins:
                 language_joins.append(langjoin)
         newkwargs[newkey] = value
     newargs = []
     for q in args:
         new_q, langjoins = self._recurse_q(q)
         newargs.append(new_q)
         for langjoin in langjoins:
             if langjoin not in language_joins:
                 language_joins.append(langjoin)
     for langjoin in language_joins:
         extra_filters &= Q(**{langjoin: self._language_code})
     return newargs, newkwargs, extra_filters
Esempio n. 8
0
 def _translate_args_kwargs(self, *args, **kwargs):
     self.language(self._language_code)
     language_joins = []
     newkwargs = {}
     extra_filters = Q()
     for key, value in kwargs.items():
         newkey, langjoins = translate(key, self.model)
         for langjoin in langjoins:
             if langjoin not in language_joins:
                 language_joins.append(langjoin)
         newkwargs[newkey] = value
     newargs = []
     for q in args:
         new_q, langjoins = self._recurse_q(q)
         newargs.append(new_q)
         for langjoin in langjoins:
             if langjoin not in language_joins:
                 language_joins.append(langjoin)
     for langjoin in language_joins:
         extra_filters &= Q(**{langjoin: self._language_code})
     return newargs, newkwargs, extra_filters
Esempio n. 9
0
 def test_simple(self):
     INPUT = 'normal__shared_field'
     query_string, joins = translate(INPUT, Related)
     self.assertEqual(query_string, INPUT)
     self.assertEqual(joins, ['normal__translations__language_code'])
Esempio n. 10
0
 def latest(self, field_name=None):
     extra_filters = Q()
     if field_name:
         field_name, extra_filters = translate(self, field_name)
     return self._filter_extra(extra_filters).latest(field_name)
Esempio n. 11
0
 def latest(self, field_name=None):
     extra_filters = Q()
     if field_name:
         field_name, extra_filters = translate(self, field_name)
     return self._filter_extra(extra_filters).latest(field_name)
Esempio n. 12
0
 def test_simple(self):
     INPUT = 'normal__shared_field'
     query_string, joins = translate(INPUT, Related)
     self.assertEqual(query_string, INPUT)
     self.assertEqual(joins, ['normal__translations__language_code'])