<s> import sqlalchemy as SA <EOL> import pushmanager . core . db as db <EOL> import pushmanager . core . util <EOL> from pushmanager . core . mail import MailQueue <EOL> from pushmanager . core . requesthandler import RequestHandler <EOL> class DelayRequestServlet ( RequestHandler ) : <EOL> def post ( self ) : <EOL> if not self . current_user : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> self . requestid = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT:id>' ) <EOL> update_query = db . push_requests . update ( ) . where ( SA . and_ ( <EOL> db . push_requests . c . id == self . requestid , <EOL> db . push_requests . c . state . in_ ( ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ) ) . values ( { <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> } ) <EOL> delete_query = db . push_pushcontents . delete ( ) . where ( <EOL> SA . exists ( [ <NUM_LIT:1> ] , SA . and_ ( <EOL> db . push_pushcontents . c . request == db . push_requests . c . id , <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> ) ) ) <EOL> select_query = db . push_requests . select ( ) . where ( <EOL> db . push_requests . c . id == self . requestid , <EOL> ) <EOL> db . execute_transaction_cb ( [ update_query , delete_query , select_query ] , self . on_db_complete ) <EOL> get = post <EOL> def on_db_complete ( self , success , db_results ) : <EOL> self . check_db_results ( success , db_results ) <EOL> _ , _ , req = db_results <EOL> req = req . first ( ) <EOL> if req [ '<STR_LIT:state>' ] != '<STR_LIT>' : <EOL> return self . redirect ( "<STR_LIT>" % self . current_user ) <EOL> if req [ '<STR_LIT>' ] : <EOL> user_string = '<STR_LIT>' % ( req [ '<STR_LIT:user>' ] , req [ '<STR_LIT>' ] ) <EOL> users = [ req [ '<STR_LIT:user>' ] ] + req [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) <EOL> else : <EOL> user_string = req [ '<STR_LIT:user>' ] <EOL> users = [ req [ '<STR_LIT:user>' ] ] <EOL> msg = ( <EOL> """<STR_LIT>""" <EOL> ) % pushmanager . core . util . EscapedDict ( { <EOL> '<STR_LIT>' : self . current_user , <EOL> '<STR_LIT:user>' : user_string , <EOL> '<STR_LIT:title>' : req [ '<STR_LIT:title>' ] , <EOL> '<STR_LIT>' : req [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : req [ '<STR_LIT>' ] , <EOL> } ) <EOL> subject = "<STR_LIT>" % ( user_string , req [ '<STR_LIT:title>' ] ) <EOL> MailQueue . enqueue_user_email ( users , msg , subject ) <EOL> self . redirect ( "<STR_LIT>" % self . current_user ) </s>
