File: comparators.py

package info (click to toggle)
sqlalchemy-i18n 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 2,164; makefile: 157
file content (15 lines) | stat: -rw-r--r-- 509 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from sqlalchemy.orm.relationships import RelationshipProperty

from .exc import UnknownLocaleError


class TranslationComparator(RelationshipProperty.Comparator):
    def __getitem__(self, key):
        return getattr(self._parentmapper.class_, '_translation_%s' % key)

    def __getattr__(self, locale):
        class_ = self._parentmapper.class_
        try:
            return getattr(class_, '_translation_%s' % locale)
        except AttributeError:
            raise UnknownLocaleError(locale, class_)