diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-08-23 18:22:44 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-08-23 18:22:44 +0200 |
commit | db55fe482c5c428fdaca938efe380dc2060f8803 (patch) | |
tree | 34349c6b4a65ec5530ef2d58b33c8d536a559213 | |
parent | b03c29884697eea33d6e1cc9d5be66166aeadb34 (diff) | |
download | Ishtar-db55fe482c5c428fdaca938efe380dc2060f8803.tar.bz2 Ishtar-db55fe482c5c428fdaca938efe380dc2060f8803.zip |
Wizard: allow ManyToMany with non formset forms - fix bad initial data copy of list values
-rw-r--r-- | ishtar_common/wizards.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 5229880ef..e3df00771 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -38,18 +38,6 @@ class Wizard(NamedUrlWizardView): @staticmethod def _check_right(step, condition=True): '''Return a method to check the right for a specific step''' - """ - def check_right(self, request, storage): - cond = condition - if callable(condition): - cond = condition(self, request, storage) - if not cond: - return False - person_type = request.user.ishtaruser.person.person_type - if person_type.txt_idx == 'administrator': - return True - if person_type.rights.filter(url_name=step).count(): - return True""" def check_right(self): cond = condition if callable(condition): @@ -58,11 +46,8 @@ class Wizard(NamedUrlWizardView): return False if not hasattr(self.request.user, 'ishtaruser'): return False - person_type = self.request.user.ishtaruser.person.person_type - if person_type.txt_idx == 'administrator': - return True - if person_type.rights.filter(url_name=step).count(): - return True + return self.request.user.ishtaruser.has_right(('administrator', + step)) return check_right def __init__(self, *args, **kwargs): @@ -74,13 +59,6 @@ class Wizard(NamedUrlWizardView): condition = self.condition_dict.get(form_key, True) cond = self._check_right(form_key, condition) self.condition_dict[form_key] = cond - """ - for form_key in self.form_list.keys()[:-1]: - condition = True - if form_key in self.condition_list: - condition = self.condition_list.get(form_key, True) - cond = self._check_right(form_key, condition) - self.condition_list[form_key] = cond""" def get_prefix(self, *args, **kwargs): """As the class name can interfere when reused prefix with the url_name @@ -137,7 +115,11 @@ class Wizard(NamedUrlWizardView): if not isinstance(values, list): for key in values: form_key = next_step + '-' + key - prefixed_values[form_key] = values[key] + if isinstance(values, MultiValueDict): + prefixed_values.setlist(form_key, + values.getlist(key)) + else: + prefixed_values[form_key] = values[key] else: for formset_idx, v in enumerate(values): prefix = u"-%d-" % formset_idx @@ -222,7 +204,9 @@ class Wizard(NamedUrlWizardView): value = _(u"No") elif key in associated_models: values = [] - if "," in unicode(value): + if type(value) in (tuple, list): + values = value + elif "," in unicode(value): values = unicode(value).split(",") else: values = [value] @@ -309,7 +293,17 @@ class Wizard(NamedUrlWizardView): value = model.objects.get(pk=value) else: value = None - dct[key] = value + if hasattr(form, 'base_model') and form.base_model and \ + form.base_model == key: + whole_associated_models.append(form.base_model) + if value: + vals = value + if type(vals) not in (list, tuple): + vals = [vals] + for val in vals: + m2m.append((form.base_model, val)) + else: + dct[key] = value return self.save_model(dct, m2m, whole_associated_models, form_list, return_object) @@ -363,7 +357,7 @@ class Wizard(NamedUrlWizardView): if hasattr(m, 'related'): c_item = m.related.model(**other_objs[dependant_item]) setattr(obj, dependant_item, c_item) - obj.save() + obj.save() obj.save() else: adds = {} @@ -630,14 +624,20 @@ class Wizard(NamedUrlWizardView): return initial if hasattr(c_form, 'base_fields'): for base_field in c_form.base_fields.keys(): - fields = base_field.split('__') value = obj - for field in fields: - if not hasattr(value, field) or \ - getattr(value, field) == None: - value = obj - break - value = getattr(value, field) + if hasattr(c_form, 'base_model') and \ + base_field == c_form.base_model: + key = c_form.base_model + 's' + initial.setlist(base_field, [unicode(val.pk) + for val in getattr(obj, key).all()]) + else: + fields = base_field.split('__') + for field in fields: + if not hasattr(value, field) or \ + getattr(value, field) == None: + value = obj + break + value = getattr(value, field) if value == obj: continue if hasattr(value, 'pk'): |