#NEWLINE# def clean( self ) : #NEWLINE# #INDENT# cleaned_data = self . cleaned_data #NEWLINE# content_type_id = cleaned_data . get ( 'content_type' , None ) #NEWLINE# object_id = cleaned_data . get ( 'object_id' , None ) #NEWLINE# if ( ( content_type_id is None ) or ( object_id is None ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Missing Parameter' ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ct = ContentType . objects . get ( id = content_type_id ) #NEWLINE# #UNINDENT# except ContentType . DoesNotExist : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Bogus content' ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# obj = ct . get_object_for_this_type ( id = object_id ) #NEWLINE# #UNINDENT# except ct . model_class ( ) . DoesNotExist : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Bogus object' ) ) #NEWLINE# #UNINDENT# cleaned_data [ 'content_type' ] = ct #NEWLINE# if ( not getattr ( obj , 'annotatable' , False ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Invalid object' ) ) #NEWLINE# #UNINDENT# if ( not hasattr ( obj , Annotation . field_name ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Bogus object' ) ) #NEWLINE# #UNINDENT# text = getattr ( obj , Annotation . field_name ) #NEWLINE# if ( len ( text ) != cleaned_data [ 'lengthcheck' ] ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Text changed' ) ) #NEWLINE# #UNINDENT# if ( ( not ( 'selection_start' in cleaned_data ) ) or ( not ( 'selection_end' in cleaned_data ) ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Missing Parameter for selection' ) ) #NEWLINE# #UNINDENT# if ( not Annotation . validate_selection ( text , start = cleaned_data [ 'selection_start' ] , end = cleaned_data [ 'selection_end' ] ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Bogus selection' ) ) #NEWLINE# #UNINDENT# if ( ( 'flags' not in cleaned_data ) or ( 'selection_start' not in cleaned_data ) ) : #NEWLINE# #INDENT# raise forms . ValidationError ( _ ( 'Missing parameters' ) ) #NEWLINE# #UNINDENT# return cleaned_data