From c39f1aa8a0eab5183a2e515f4271b18a2bd1ea0c Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 16 Jun 2012 02:03:14 -0400 Subject: [PATCH] Add form field clean method to detect if documents are already checked out --- apps/checkouts/forms.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/checkouts/forms.py b/apps/checkouts/forms.py index d2032ed124..cfdecee26e 100644 --- a/apps/checkouts/forms.py +++ b/apps/checkouts/forms.py @@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _ from django.core import validators from .models import DocumentCheckout +from .exceptions import DocumentAlreadyCheckedOut class SplitDeltaWidget(forms.widgets.MultiWidget): @@ -101,3 +102,9 @@ class DocumentCheckoutForm(forms.ModelForm): widgets = { 'document': forms.widgets.HiddenInput(), } + + def clean_document(self): + document = self.cleaned_data['document'] + if document.is_checked_out(): + raise DocumentAlreadyCheckedOut + return document