diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-05-04 01:10:40 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-05-04 01:10:40 +0200 | 
| commit | ada0ab4962eb437bfbd2b300c5aca69bf5719bfb (patch) | |
| tree | dcfa2689395822cf1475deb1a6107bebb6006701 /ishtar_common/forms_common.py | |
| parent | 0500c0a5098c2b3347ffd36faaa692e97be3b5a4 (diff) | |
| download | Ishtar-ada0ab4962eb437bfbd2b300c5aca69bf5719bfb.tar.bz2 Ishtar-ada0ab4962eb437bfbd2b300c5aca69bf5719bfb.zip | |
Imports: manage unmatched item links
Diffstat (limited to 'ishtar_common/forms_common.py')
| -rw-r--r-- | ishtar_common/forms_common.py | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index b6971c4f4..677656af6 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -98,6 +98,43 @@ class NewImportForm(forms.ModelForm):          self.instance.user = user          return super(NewImportForm, self).save(commit) +class TargetKeyForm(forms.ModelForm): +    class Meta: +        model = models.TargetKey +        fields = ('target', 'value', 'key') +        widgets = { +            'value': forms.TextInput(attrs={'readonly':'readonly'}), +            'key': forms.Select(), +        } + +    def __init__(self, *args, **kwargs): +        super(TargetKeyForm, self).__init__(*args, **kwargs) +        instance = getattr(self, 'instance', None) +        if instance and instance.pk: +            self.fields['target'].widget.attrs['readonly'] = True +            self.fields['value'].widget.attrs['readonly'] = True +        self.fields['key'].widget.choices = list(instance.target.get_choices()) + +    def clean_target(self): +        instance = getattr(self, 'instance', None) +        if instance and instance.pk: +            return instance.target +        else: +            return self.cleaned_data['target'] + +    def clean_value(self): +        instance = getattr(self, 'instance', None) +        if instance and instance.pk: +            return instance.value +        else: +            return self.cleaned_data['value'] + +    def save(self, commit=True): +        super(TargetKeyForm, self).save(commit) +        if self.cleaned_data.get('value'): +            self.instance.is_set = True +            self.instance.save() +  class OrganizationForm(NewItemForm):      form_label = _(u"Organization")      associated_models = {'organization_type':models.OrganizationType} | 
