diff options
Diffstat (limited to 'archaeological_finds/forms.py')
-rw-r--r-- | archaeological_finds/forms.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index e3207a2f5..2b3586979 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -390,6 +390,27 @@ FindSourceFormSelection = get_form_selection( _(u"You should select a document.")) +class NewFindBasketForm(forms.ModelForm): + class Meta: + model = models.FindBasket + fields = ('label', 'comment') + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user') + super(NewFindBasketForm, self).__init__(*args, **kwargs) + + def clean(self): + q = models.FindBasket.objects.filter(user=self.user, + label=self.cleaned_data['label']) + if q.count(): + raise forms.ValidationError(_(u"Another basket already exist with " + u"this name.")) + return self.cleaned_data + + def save(self, commit=True): + self.instance.user = self.user + return super(NewFindBasketForm, self).save(commit) + """ #################################### # Source management for treatments # |