diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-11-23 21:25:27 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2012-11-23 21:25:27 +0100 |
commit | 8bcca56ce043e0e4312315d69e436935e28ad9dc (patch) | |
tree | 99f540a084ae5efa483cc98c9a8c7413dfe64bd1 /chimere/admin.py | |
parent | 7cc593fd4db11fb0ad60ad7875022f6b497ada08 (diff) | |
download | Chimère-8bcca56ce043e0e4312315d69e436935e28ad9dc.tar.bz2 Chimère-8bcca56ce043e0e4312315d69e436935e28ad9dc.zip |
Fix route rapprochement: prevent delete of associated marker
Diffstat (limited to 'chimere/admin.py')
-rw-r--r-- | chimere/admin.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/chimere/admin.py b/chimere/admin.py index 4e175aa..8fe2b77 100644 --- a/chimere/admin.py +++ b/chimere/admin.py @@ -112,9 +112,21 @@ def managed_modified(modeladmin, request, queryset): if request.POST.get('rapprochement'): couple = [(item, item_ref)] if hasattr(item, 'associated_marker'): - couple.append((item.associated_marker, item_ref.associated_marker)) - for it, it_ref in couple: - for k in request.POST: + couple.append((item.associated_marker.all()[0], + item_ref.associated_marker.all()[0])) + updated_keys = request.POST + updated_keys.pop('action') + updated_keys.pop('rapprochement') + updated_keys.pop('index') + updated_keys.pop('_selected_action') + for idx, cpl in enumerate(couple): + it, it_ref = cpl + # don't copy geometry of associated items + if idx: + for k in ('route', 'point'): + if k in updated_keys: + updated_keys.pop(k) + for k in updated_keys: if not request.POST[k]: continue if hasattr(it_ref, k): @@ -124,6 +136,7 @@ def managed_modified(modeladmin, request, queryset): for val in getattr(it, k).all(): c_value.add(val) else: + setattr(it_ref, k, getattr(it, k)) it_ref.save() elif k.startswith('property_'): try: |