Commit graph

90 commits

Author SHA1 Message Date
Benedikt Willi
66387f433a Add support for JSONField in modeltranslation/fields.py and update_translation_fields command and add tests for JSONField support. 2023-06-01 22:08:16 +02:00
Serg Tereshchenko
f0fb6ebd8d chore: Update formatting 2023-02-09 10:38:43 +02:00
Gabriele Baldi
f69e3172bc
feat: Add support for ManyToManyFields 🧑‍🤝‍🧑 (#668) 2023-01-27 15:05:18 +02:00
Maksudul Haque
4927b6cb63
Make Context Managers (fallbacks and auto_populate) Thread Safe (#657) 2022-11-08 14:13:17 +00:00
Serg Tereshchenko
86b67c271e fix: Remove six (old compat layer for python2) 2022-07-13 23:14:28 +03:00
Serg Tereshchenko
58691691b7 cleanup: Remove old south mentions 2022-05-15 11:16:58 +03:00
Serg Tereshchenko
25b6011a1f style: Apply black 2021-09-18 10:55:39 +03:00
Donald Buczek
2c9669efd8 Don't leak into current language from .clean_fields()
Django uses .clean_fields() to verify the values of all fields of an
instance, e.g. after the instance has been updated from a form view.

.clean_fields() essentially walks over the fields in the model, reads
the current values, verifies and normalizes them, and writes them
back [1].

With model-translations activated, this can leak values from a fallback
language into the current language of the session, if the value for the
current language has been set to an empty value from a translation aware
application or form.

Example:

- current language is "en"
- fallback languages are "en", "de"
- web form wants to set "title_de" to "Schnapsidee" and leave
    "title_en" empty

After the form is submitted, Django calls .clean_fields() which
processes the field "title" first

- reads value of "title" - which gives "Schnapsidee" from
    "title_de" by the fallback mechanism of Modeltranslations
- writes this value back to "title", which sets "title_en"
    as a side effect.

Bugs have been reported at [2], [3] and [4]

Disable the implicit setting of the translation field from the
translated field ( Rule 2 of [5] ) during .clean_field() processing.

[1] bf77669453/django/db/models/base.py (L1229)
[2] https://github.com/deschler/django-modeltranslation/issues/382
[3] https://github.com/infoportugal/wagtail-modeltranslation/issues/247
[4] https://github.molgen.mpg.de/molgen/mpicms/issues/15
[5] https://django-modeltranslation.readthedocs.io/en/latest/usage.html#rules-for-translated-field-access
2020-01-16 11:58:18 +01:00
Sergey Tereschenko
851bff4cb6 fix related fields translation in django 3 2019-10-27 18:58:53 +02:00
Misha Kalyna
5505208003 explicitly install and import six (which was removed from Django 3.0) 2019-10-05 21:07:08 +02:00
Andrey Maslov
1a70900ba4 Fix Django 2 related object descriptor cache 2018-04-15 04:58:18 +03:00
Mariusz Felisiak
b64ddf2e20
Used model attribute instead of deprecated ForeignObjectRel.to. 2017-06-22 22:15:37 +02:00
Jacek Tomaszewski
302c931fe0 Django 1.10 integration (ref #381) 2016-08-19 21:23:45 +02:00
Jacek Tomaszewski
caab290048 Fix travis for Python 3.5 adn 3.2; fix migrations for Django 1.9 (ref #349). 2015-12-07 00:23:17 +01:00
Jacek Tomaszewski
8320fc8a5a Add Django 1.9 support (ref #349). 2015-12-06 18:48:17 +01:00
Jacek Tomaszewski
395771d227 Patch db_column of translation fields in migration files (close #264). 2014-09-07 21:42:05 +02:00
Jacek Tomaszewski
e59cf5a4cd Readd GenericIp field support and tests as we now require Django >= 1.4. 2014-08-02 16:42:14 +02:00
Dirk Eschler
3281547a9e Respect null option of TranslationField in migrations. 2014-07-14 11:07:17 +02:00
Jacek Tomaszewski
c4d6c82f95 Fix six import (ref #253). 2014-07-11 15:04:03 +02:00
Dirk Eschler
f7acd8a688 Used six compatibility layer (ref #253). 2014-07-11 14:40:38 +02:00
Dirk Eschler
fd911bb37b Fixed unicode call in deconstruct to maintain Python3 compatibility. 2014-07-11 13:31:57 +02:00
Dirk Eschler
e4e325a8e7 Fixed translation fields in migrations don't include language code (close #253). 2014-07-11 12:37:41 +02:00
Jacek Tomaszewski
6b8c429921 Add deconstruct() to field definition. 2014-06-09 23:19:54 +02:00
Dirk Eschler
591e945c33 Add more control over required languages (close #143). 2014-03-15 15:18:52 +01:00
Jacek Tomaszewski
c27a4e4e10 Fix form submission (close #219). 2013-12-26 18:59:24 +01:00
Jacek Tomaszewski
9a5fe20140 Fix empty FileField handling (close #215). 2013-11-13 19:04:42 +01:00
Jacek Tomaszewski
a3a274ae62 Add docs about empty_values (close #211). 2013-11-09 14:28:38 +01:00
Jacek Tomaszewski
71af06c7c9 Add configurable formfields (close #211, ref #163, #187).
This will hopefully at last resolve the problem with nullable CharFields.
2013-10-23 15:40:45 +02:00
Jacek Tomaszewski
b8cf1ef015 Fix db_column (close #210). 2013-10-18 10:46:15 +02:00
Jacek Tomaszewski
0e76f1ec7d Add OneToOneField support. 2013-10-12 13:58:57 +02:00
Jacek Tomaszewski
81638809bc Fix form handling in case of excluded translated field (close #183). 2013-10-11 20:07:37 +02:00
Jacek Tomaszewski
656dca3e40 Show None checkboxes on form fields, especially admin (close #187). 2013-10-10 23:05:26 +02:00
wrwrwr
22faea9646 Reworked the solution by replacing clearable widgets with a widget wrapper. This makes it possible to wrap only widgets of nullable fields, and thus not add the clear checkbox when it's not needed.
The implementation is loosely based on RelatedFieldWidgetWrapper from contrib.admin, but uses a bit more Python magic; tested only with TextInput and Textarea widgets and their admin counterparts, but with a bit of luck should work with other widgets too.
2013-05-14 22:21:03 +02:00
wrwrwr
b9494f7607 Merge branch 'master' into feature/no-empty-string-fallback-for-nullable
Conflicts:
	modeltranslation/admin.py
	modeltranslation/fields.py
	modeltranslation/translator.py
2013-05-13 13:34:37 +02:00
Jacek Tomaszewski
fef3109e60 Fix test running in Django 1.6: foreignkey support (close #169). 2013-04-02 23:27:21 +02:00
Jacek Tomaszewski
32e945e28b Handle non-translation form submision for translated models (close #167). 2013-04-02 09:51:44 +02:00
Jacek Tomaszewski
07f7164289 Handle only/defer manager methods (close #166). 2013-04-02 09:51:44 +02:00
wrwrwr
97d966244d Implemented a widget that shows a clear checkbox for any non-required form field.
Overriden admin widgets of CharFields and TextFields and patched forms.CharField for nullable fields, so undefined translations don't get filled with empty strings when an admin form is saved (thus becoming defined in the case of a nullable field).
2013-03-24 17:59:21 +01:00
wrwrwr
b00a1044c6 Flake8, overindented continuation line. 2013-03-17 17:43:24 +01:00
wrwrwr
627c2b55e9 Added a fallback_undefined option to allow customizing the value that triggers falling back. 2013-03-17 17:35:22 +01:00
wrwrwr
7d209ae4e3 Only fallback when there is no value for a given translation or the value is the field's default.
For CharField(null=True) the default is None, so empty string becomes a proper value (it's sometimes useful to treat it differently than None).
2013-03-17 11:24:24 +01:00
Jacek Tomaszewski
47cc2cb1b7 Fix flake8 2013-03-13 23:52:44 +01:00
Jacek Tomaszewski
5feff41795 Change the form of `related_query_name` for implicit related_names (ref #161). 2013-03-13 19:24:00 +01:00
Jacek Tomaszewski
fccdf93577 Finish ForeignKey reverse relation handling (ref #161).
Also enhance tests and refactor MultilingualManager rewriting of
spanned relations lookups.
2013-03-13 15:50:22 +01:00
Braden MacDonald
43a61a0bcc Add tests for foreign key reverse relations, and fix some issues. Still incomplete. ref deschler/django-modeltranslation#161 2013-03-10 16:39:14 -07:00
Jacek Tomaszewski
fc798eaeb4 Attempt to rewrite related_names (ref #161). 2013-03-08 21:13:37 +01:00
Braden MacDonald
16de24183a Add a descriptor so that ForeignKey 'field_id' attributes work. 2013-03-06 15:54:56 -08:00
Braden MacDonald
420e3b6c52 Implement ForeignKey support (does not support reverse relations) 2013-03-06 14:20:16 -08:00
Jacek Tomaszewski
38ff4a28ea Refactor fix for #154 and add a test. 2013-02-27 20:02:23 +01:00
Jacek Tomaszewski
26b904ef7e Hotfix for #154 2013-02-26 23:17:19 +01:00