#NEWLINE# def form_valid( self , form ) : #NEWLINE# #INDENT# success = True #NEWLINE# save_attachments = False #NEWLINE# save_poll_answers = False #NEWLINE# ( self . object , topic ) = form . save ( commit = False ) #NEWLINE# if perms . may_attach_files ( self . request . user ) : #NEWLINE# #INDENT# aformset = self . get_attachment_formset_class ( ) ( self . request . POST , self . request . FILES , instance = self . object ) #NEWLINE# if aformset . is_valid ( ) : #NEWLINE# #INDENT# save_attachments = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# success = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# aformset = None #NEWLINE# #UNINDENT# if perms . may_create_poll ( self . request . user ) : #NEWLINE# #INDENT# pollformset = self . get_poll_answer_formset_class ( ) ( ) #NEWLINE# if ( getattr ( self , 'forum' , None ) or ( topic . head == self . object ) ) : #NEWLINE# #INDENT# if ( topic . poll_type != Topic . POLL_TYPE_NONE ) : #NEWLINE# #INDENT# pollformset = self . get_poll_answer_formset_class ( ) ( self . request . POST , instance = topic ) #NEWLINE# if pollformset . is_valid ( ) : #NEWLINE# #INDENT# save_poll_answers = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# success = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# topic . poll_question = None #NEWLINE# topic . poll_answers . all ( ) . delete ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# pollformset = None #NEWLINE# #UNINDENT# if success : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# topic . save ( ) #NEWLINE# #UNINDENT# except ValidationError as e : #NEWLINE# #INDENT# success = False #NEWLINE# errors = form . _errors . setdefault ( 'name' , ErrorList ( ) ) #NEWLINE# errors += e . error_list #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . object . topic = topic #NEWLINE# self . object . save ( ) #NEWLINE# if save_attachments : #NEWLINE# #INDENT# aformset . save ( ) #NEWLINE# #UNINDENT# if save_poll_answers : #NEWLINE# #INDENT# pollformset . save ( ) #NEWLINE# #UNINDENT# return HttpResponseRedirect ( self . get_success_url ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# return self . render_to_response ( self . get_context_data ( form = form , aformset = aformset , pollformset = pollformset ) )