-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make relationship and fk args customizable
* Add configuration option for relationship args * Add foreign_key_args parameter to translation_base function
- Loading branch information
Showing
6 changed files
with
123 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
) | ||
|
||
|
||
__version__ = '1.0.1' | ||
__version__ = '1.0.2' | ||
|
||
|
||
def make_translatable( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import sqlalchemy as sa | ||
|
||
from sqlalchemy_i18n import Translatable, translation_base | ||
from tests import DeclarativeTestCase | ||
|
||
|
||
class TestTranslationBaseCustomization(DeclarativeTestCase): | ||
def create_models(self): | ||
class Article(self.Model, Translatable): | ||
__tablename__ = 'article' | ||
__translatable__ = { | ||
'locales': ['fi', 'en'], | ||
'auto_create_locales': True, | ||
'translations_relationship_args': { | ||
'collection_class': list, | ||
} | ||
} | ||
|
||
id = sa.Column(sa.Integer, primary_key=True) | ||
|
||
locale = 'en' | ||
|
||
TranslationBase = translation_base( | ||
Article, | ||
foreign_key_args={'onupdate': 'SET NULL'} | ||
) | ||
|
||
class ArticleTranslation(TranslationBase): | ||
__tablename__ = 'article_translation' | ||
|
||
name = sa.Column(sa.Unicode(255)) | ||
|
||
self.Article = Article | ||
self.ArticleTranslation = ArticleTranslation | ||
|
||
def test_customize_foreign_key_args(self): | ||
assert ( | ||
self.ArticleTranslation.__table__.foreign_keys.pop().onupdate == | ||
'SET NULL' | ||
) | ||
|
||
def test_customize_relationships_args(self): | ||
assert self.Article._translations.property.collection_class == list |