'If a current revision is supplied in the form, compare it against
what the document claims is the current revision. If there\'s a
difference, then an edit has occurred since the form was constructed
and we treat it as a mid-air collision.'

def clean_current_rev(self):

    current_rev = self.cleaned_data.get('current_rev', None)
    if (not current_rev):
        return current_rev
    try:
        doc_current_rev = self.instance.document.current_revision.id
        if (unicode(current_rev) != unicode(doc_current_rev)):
            if (self.section_id and self.instance and self.instance.document):
                orig_ct = Revision.objects.get(pk=current_rev).get_section_content(self.section_id)
                curr_ct = self.instance.document.current_revision.get_section_content(self.section_id)
                if (orig_ct != curr_ct):
                    url = reverse('wiki.document_revisions', kwargs={'document_path': self.instance.document.slug})
                    raise forms.ValidationError((MIDAIR_COLLISION % {'url': url}))
                return current_rev
            else:
                url = reverse('wiki.document_revisions', kwargs={'document_path': self.instance.document.slug})
                raise forms.ValidationError((MIDAIR_COLLISION % {'url': url}))
    except Document.DoesNotExist:
        return current_rev
