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 | bdc9cdab0d5e314b5d1a33a2d87fca22138d649d (patch) | |
| tree | dcfa2689395822cf1475deb1a6107bebb6006701 /ishtar_common/forms_common.py | |
| parent | 274b8d44ccf1f099f2e22b5a6a70f9743b746c1d (diff) | |
| download | Ishtar-bdc9cdab0d5e314b5d1a33a2d87fca22138d649d.tar.bz2 Ishtar-bdc9cdab0d5e314b5d1a33a2d87fca22138d649d.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} | 
