diff options
Diffstat (limited to 'ishtar_common/forms_common.py')
| -rw-r--r-- | ishtar_common/forms_common.py | 22 | 
1 files changed, 17 insertions, 5 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 2b52f0919..2df825594 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -315,7 +315,7 @@ class TargetKeyFormset(BaseModelFormSet):  class OrganizationForm(ManageOldType, NewItemForm):      prefix = 'organization' -    form_label = _(u"Organization") +    form_label = _("Organization")      associated_models = {'organization_type': models.OrganizationType,                           "precise_town": models.Town}      name = forms.CharField( @@ -348,7 +348,7 @@ class OrganizationForm(ManageOldType, NewItemForm):              models.OrganizationType.get_help()          self.limit_fields() -    def save(self, user): +    def save(self, user, item=None):          dct = self.cleaned_data          dct['history_modifier'] = user          dct['organization_type'] = models.OrganizationType.objects.get( @@ -359,7 +359,12 @@ class OrganizationForm(ManageOldType, NewItemForm):                      pk=dct["precise_town"])              except models.Town.DoesNotExist:                  dct.pop("precise_town") -        new_item = models.Organization(**dct) +        if not item: +            new_item = models.Organization(**dct) +        else: +            new_item = item +            for k in dct: +                setattr(new_item, k, dct[k])          new_item.save()          return new_item @@ -792,7 +797,7 @@ class PersonForm(SimplePersonForm):          self.fields['person_types'].help_text = models.PersonType.get_help()          self.limit_fields() -    def save(self, user): +    def save(self, user, item=None):          dct = self.cleaned_data          dct['history_modifier'] = user          for key in self.associated_models.keys(): @@ -806,7 +811,14 @@ class PersonForm(SimplePersonForm):                      except model.DoesNotExist:                          dct.pop(key)          person_types = dct.pop('person_types') -        new_item = models.Person.objects.create(**dct) +        if not item: +            new_item = models.Person.objects.create(**dct) +        else: +            for k in dct: +                setattr(item, k, dct[k]) +            item.save() +            item.person_types.clear() +            new_item = item          for pt in person_types:              new_item.person_types.add(pt)          return new_item  | 
