#NEWLINE# @ login_required #NEWLINE# @ ratelimit ( rate = '1/10s' ) #NEWLINE# def publish( request , user_id = None ) : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# tform = TopicForPrivateForm ( user = request . user , data = request . POST ) #NEWLINE# cform = CommentForm ( user = request . user , data = request . POST ) #NEWLINE# tpform = TopicPrivateManyForm ( user = request . user , data = request . POST ) #NEWLINE# if ( ( not request . is_limited ) and all ( [ tform . is_valid ( ) , cform . is_valid ( ) , tpform . is_valid ( ) ] ) ) : #NEWLINE# #INDENT# topic = tform . save ( ) #NEWLINE# cform . topic = topic #NEWLINE# comment = cform . save ( ) #NEWLINE# comment_posted ( comment = comment , mentions = None ) #NEWLINE# tpform . topic = topic #NEWLINE# tpform . save_m2m ( ) #NEWLINE# TopicNotification . bulk_create ( users = tpform . get_users ( ) , comment = comment ) #NEWLINE# return redirect ( topic . get_absolute_url ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# tform = TopicForPrivateForm ( ) #NEWLINE# cform = CommentForm ( ) #NEWLINE# initial = None #NEWLINE# if user_id : #NEWLINE# #INDENT# user = get_object_or_404 ( User , pk = user_id ) #NEWLINE# initial = { #NEWLINE# #INDENT# 'users' : [ user . username ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# tpform = TopicPrivateManyForm ( initial = initial ) #NEWLINE# #UNINDENT# context = { #NEWLINE# #INDENT# 'tform' : tform , #NEWLINE# 'cform' : comment , #NEWLINE# 'tpform' : tpform , #NEWLINE# #UNINDENT# } #NEWLINE# return render ( request , 'spirit/topic/private/publish.html' , context )