Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenkoff committed Mar 5, 2014
1 parent 3510d25 commit 0fdea47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/test_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ def test_i18n_field(query, model, session):

assert model.title.get_dict() == {'en': 'En Title', 'pt': 'Pt Title'}
assert model.title.get_text() == 'En Title'


def test_class_custom_table(languages):
"""Test initialization with custom table."""
Base = declarative_base()

traduki.initialize(Base, languages, lambda: 'en', lambda: {}, attributes={'__tablename__': 'custom_table'})

assert traduki.sqla.Translation.__tablename__ == 'custom_table'
9 changes: 7 additions & 2 deletions traduki/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,27 @@ def __nonzero__(self):
return bool(unicode(self))


def initialize(base, languages, get_current_language_callback, get_language_chain_callback):
def initialize(base, languages, get_current_language_callback, get_language_chain_callback, attributes=None):
"""Initialize using given declarative base.
:param base: SQLAlchemy declarative base class
:param languages: `iterable` of supported language codes
:param get_current_language_callback: function which returns current language code
:param get_language_chain_callback: function which returns language chain `dict`
in format: {'<selector>': '<language code>'}
:param attributes: `dict` of future Translation class additional attributes or overrides.
For example: {'__tablename__': 'some_other_table'
"""

config.LANGUAGE_CALLBACK = get_current_language_callback
config.LANGUAGE_CHAIN_CALLBACK = get_language_chain_callback
config.LANGUAGES = languages

attributes = dict(((lang, Column(UnicodeText, nullable=True)) for lang in languages))
if attributes is None:
attributes = {}

attributes.update(dict(((lang, Column(UnicodeText, nullable=True)) for lang in languages)))

global Translation

Expand Down

0 comments on commit 0fdea47

Please sign in to comment.