Skip to content

Commit

Permalink
Mark object with the translation property as modified when the proper…
Browse files Browse the repository at this point in the history
…ty setter is called
  • Loading branch information
bubenkoff committed Dec 4, 2015
1 parent 18b02d0 commit e4a0646
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.pyc
*.pyo
*.orig
.env
/.tox
/bin
/include
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python
# command to install dependencies
install:
- pip install python-coveralls virtualenv
- pip install tox
# # command to run tests
script: python setup.py test
script: tox
after_success:
- pip install -r requirements-testing.txt -e .
- py.test --cov=traduki --cov-report=term-missing tests
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
10 changes: 8 additions & 2 deletions traduki/config.py
Original file line number Diff line number Diff line change
@@ -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']
4 changes: 4 additions & 0 deletions traduki/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e4a0646

Please sign in to comment.