google-code-export / django-modeltranslation

Automatically exported from code.google.com/p/django-modeltranslation
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Widgets for translated fields are not properly copied from original fields #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
using version 0.3.3 from pypi

Steps to reproduce the problem:
1. Add several char fields to a model with different lengths and mark them for 
translation
2. Go to the admin, and all field inputs will have the attributes of the last 
field in the admin - most notably maxlength="..."

The problem is that when you're copying the widget from the original field, 
"copy.copy" is used.
"copy" does not copy the attrs dictionary, but rather sets a reference to the 
dict of the original widget.
Since Django admin uses one widget instance for all Charfields, all char fields 
get the attrs of the last field's widget.

"deepcopy"must be used instead - then everything works correctly.

Patch:

modeltranslation/admin.py - line 44 - 
TranslationAdminBase.patch_translation_field(...)

44:            field.widget = copy(orig_formfield.widget)

must become

44:            field.widget = deepcopy(orig_formfield.widget)

Original issue reported on code.google.com by boris.ch...@gmail.com on 7 May 2012 at 11:55

GoogleCodeExporter commented 9 years ago
Boris was kind enough to provide a fix on Github: 

https://github.com/sentido/django-modeltranslation/commit/5f9dec4d61685b962fafbd
232daf27adb8ea756e

Original comment by chris@improbable.org on 7 May 2012 at 6:12

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r131.

Original comment by eschler on 10 May 2012 at 8:34