def test_translation_bool(): t = lambda s: Translation(localized_string=s) assert bool(t('text')) is True assert bool(t(' ')) is False assert bool(t('')) is False assert bool(t(None)) is False
def get_trans(items): if not items: return model = items[0].__class__ # FIXME: if we knew which db the queryset we are transforming used, we # could make sure we are re-using the same one. dbname = router.db_for_read(model) connection = connections[dbname] sql, params = build_query(model, connection) item_dict = dict((item.pk, item) for item in items) ids = ','.join(map(str, item_dict.keys())) cursor = connection.cursor() cursor.execute(sql.format(ids='(%s)' % ids), tuple(params)) step = len(trans_fields) for row in cursor.fetchall(): # We put the item's pk as the first selected field. item = item_dict[row[0]] for index, field in enumerate(model._meta.translated_fields): start = 1 + step * index t = Translation(*row[start:start + step]) if t.id is not None and t.localized_string is not None: setattr(item, field.name, t)
def test_comparison_with_lazy(): x = Translation(localized_string='xxx') lazy_u = lazy(lambda x: x, unicode) x == lazy_u('xxx') lazy_u('xxx') == x
def t(s): return Translation(localized_string=s)
def test_whitespace(self): t = Translation(localized_string=' khaaaaaan! ', id=999) t.save() eq_('khaaaaaan!', t.localized_string)
def test_translation_unicode(): t = lambda s: Translation(localized_string=s) eq_(unicode(t('hello')), 'hello') eq_(unicode(t(None)), '')