diff --git a/.gitignore b/.gitignore index c28cbd1..53205ec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.pyc *.pyo *.orig +.env /.tox /bin /include diff --git a/CHANGES.rst b/CHANGES.rst index bfe2a4c..9a397a7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Unreleased ---------- * Use index=True when declaring language columns to be able to search efficiently on language fields. +* Mark object with the translation property as modified when the property setter is called (bubenkoff) 1.0.0 ----- diff --git a/traduki/config.py b/traduki/config.py index 2caf399..2fda5af 100644 --- a/traduki/config.py +++ b/traduki/config.py @@ -1,7 +1,13 @@ """Configuration for i18n.""" -LANGUAGE_CALLBACK = lambda: 'en' -LANGUAGE_CHAIN_CALLBACK = lambda: {'*': LANGUAGE_CALLBACK()} +def LANGUAGE_CALLBACK(): + """Current language callback.""" + return 'en' + + +def LANGUAGE_CHAIN_CALLBACK(): + """Language chain callback.""" + return {'*': LANGUAGE_CALLBACK()} LANGUAGES = ['en'] diff --git a/traduki/sqla.py b/traduki/sqla.py index bd60353..f004670 100644 --- a/traduki/sqla.py +++ b/traduki/sqla.py @@ -10,7 +10,9 @@ from sqlalchemy import Column, Integer, ForeignKey, UnicodeText from sqlalchemy.exc import ArgumentError +from sqlalchemy.inspection import inspect from sqlalchemy.orm import relationship +from sqlalchemy.orm.attributes import flag_modified from sqlalchemy.orm.interfaces import AttributeExtension from sqlalchemy.orm.properties import RelationshipProperty from sqlalchemy.sql import operators as oper, functions as func @@ -134,6 +136,8 @@ def set(state, value, oldvalue, initiator): :param oldvalue: The current value. :param initiator: SQLAlchemy initiator (accessor). """ + if state._strong_obj is not None: + flag_modified(state._strong_obj, inspect(state._strong_obj.__class__).primary_key[0].name) if value is None: return None