<s> __author__ = "<STR_LIT>" <EOL> __email__ = "<STR_LIT>" <EOL> import re <EOL> import urllib <EOL> from django import newforms as forms <EOL> from buzzengine . api import models <EOL> from google . appengine . api import taskqueue <EOL> class NewCommentForm ( forms . Form ) : <EOL> article_url = forms . URLField ( required = True , widget = forms . HiddenInput ) <EOL> article_title = forms . CharField ( required = False , widget = forms . HiddenInput ) <EOL> author_name = forms . CharField ( required = True , label = "<STR_LIT:Name>" ) <EOL> author_email = forms . EmailField ( required = True , label = "<STR_LIT>" ) <EOL> author_url = forms . URLField ( required = False , label = "<STR_LIT>" ) <EOL> author_ip = forms . CharField ( required = False ) <EOL> comment = forms . CharField ( required = True , widget = forms . Textarea ( attrs = { '<STR_LIT>' : <NUM_LIT:30> , '<STR_LIT>' : <NUM_LIT:3> } ) ) <EOL> def save ( self ) : <EOL> data = self . clean_data <EOL> article_url = data . get ( '<STR_LIT>' ) <EOL> article_title = data . get ( '<STR_LIT>' ) or data . get ( '<STR_LIT>' ) <EOL> article = models . Article . get_or_insert ( article_url , url = article_url , title = article_title ) <EOL> if article . title != article_title : <EOL> article . title = article_title <EOL> article . put ( ) <EOL> author_email = data . get ( '<STR_LIT>' ) <EOL> author_name = data . get ( '<STR_LIT>' ) <EOL> author_url = data . get ( '<STR_LIT>' ) <EOL> author_ip = data . get ( '<STR_LIT>' ) <EOL> author_key = ( author_email or '<STR_LIT>' ) + author_name <EOL> author = models . Author . get_or_insert ( author_key , name = author_name ) <EOL> has_changes = False <EOL> if author . url != author_url and author_url : <EOL> author . url = author_url <EOL> has_changes = True <EOL> if author_email and author_email != author . email : <EOL> author . email = author_email <EOL> has_changes = True <EOL> if has_changes : <EOL> author . put ( ) <EOL> comment = models . Comment ( parent = article , comment = data . get ( '<STR_LIT>' ) , author = author , article = article , author_ip = author_ip ) <EOL> comment . put ( ) <EOL> params = urllib . urlencode ( { '<STR_LIT>' : article_url , '<STR_LIT>' : comment . key ( ) . id ( ) } ) <EOL> taskqueue . add ( url = "<STR_LIT>" + params , method = "<STR_LIT:GET>" ) <EOL> self . _author = author <EOL> self . _article = article <EOL> self . _comment = comment <EOL> return comment <EOL> @ property <EOL> def output ( self ) : <EOL> return { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:url>' : self . _article . url , <EOL> '<STR_LIT:title>' : self . _article . title , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:email>' : self . _author . email , <EOL> '<STR_LIT:name>' : self . _author . name , <EOL> '<STR_LIT:url>' : self . _author . url , <EOL> } , <EOL> '<STR_LIT>' : self . _comment . comment , <EOL> } </s>
