+class StringProperty(object):
+ def __init__(self, cls, stringclass, colname):
+ self.cls = cls
+ self.colname = colname
+ self.stringclass = stringclass
+
+ def __get__(self, instance, cls):
+ if instance:
+ return dict(
+ (l, getattr(t, self.colname))
+ for l, t
+ in getattr(instance, self.stringclass._attrname).items()
+ )
+ else:
+ return self
+
+ def __getitem__(self, lang):
+ return StringExpression(self, lang)
+
+ def __str__(self):
+ return '<StringDict %s.%s>' % (self.cls, self.colname)
+
+class StringExpression(ColumnOperators):
+ def __init__(self, prop, lang):
+ self.prop = prop
+ self.column = getattr(prop.stringclass, prop.colname)
+ self.lang_column = prop.stringclass._language_identifier
+ if isinstance(lang, basestring):
+ self.lang = lang
+ else:
+ self.lang = lang.identifier
+
+ def operate(self, op, *values, **kwargs):
+ return getattr(self.prop.cls, self.prop.stringclass._attrname).any(and_(
+ self.lang_column == self.lang,
+ op(self.column, *values, **kwargs),
+ ))
+
+class DefaultLangProperty(object):
+ def __init__(self, colname):
+ self.colname = colname
+
+ def __get__(self, instance, cls):
+ if instance:
+ return getattr(instance, self.colname)[default_lang]
+ else:
+ return getattr(cls, self.colname)[default_lang]
+