<s> import time <EOL> 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 . rb import RBQueue <EOL> from pushmanager . core . requesthandler import RequestHandler <EOL> class LivePushServlet ( RequestHandler ) : <EOL> def _arg ( self , key ) : <EOL> return pushmanager . core . util . get_str_arg ( self . request , key , '<STR_LIT>' ) <EOL> def post ( self ) : <EOL> if not self . current_user : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> self . pushid = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT:id>' ) <EOL> push_query = db . push_pushes . update ( ) . where ( db . push_pushes . c . id == self . pushid ) . values ( { <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : time . time ( ) , <EOL> } ) <EOL> request_query = db . push_requests . update ( ) . where ( SA . and_ ( <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> SA . exists ( <EOL> [ <NUM_LIT:1> ] , <EOL> SA . and_ ( <EOL> db . push_pushcontents . c . push == self . pushid , <EOL> db . push_pushcontents . c . request == db . push_requests . c . id , <EOL> ) <EOL> ) ) ) . values ( { <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : time . time ( ) , <EOL> } ) <EOL> reset_query = db . push_requests . update ( ) . where ( <EOL> SA . exists ( <EOL> [ <NUM_LIT:1> ] , <EOL> SA . and_ ( <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> db . push_pushcontents . c . push == self . pushid , <EOL> db . push_pushcontents . c . request == db . push_requests . c . id , <EOL> ) <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 . push == self . pushid , <EOL> db . push_pushcontents . c . request == db . push_requests . c . id , <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> ) ) ) <EOL> live_query = db . push_requests . select ( ) . where ( <EOL> SA . and_ ( db . push_requests . c . state == '<STR_LIT>' , <EOL> db . push_pushcontents . c . push == self . pushid , <EOL> db . push_pushcontents . c . request == db . push_requests . c . id ) <EOL> ) <EOL> db . execute_transaction_cb ( <EOL> [ push_query , request_query , reset_query , delete_query , live_query ] , <EOL> self . on_db_complete , <EOL> ) <EOL> def on_db_complete ( self , success , db_results ) : <EOL> self . check_db_results ( success , db_results ) <EOL> _ , _ , _ , _ , live_requests = db_results <EOL> for req in live_requests : <EOL> if req [ '<STR_LIT>' ] : <EOL> review_id = int ( req [ '<STR_LIT>' ] ) <EOL> RBQueue . enqueue_review ( review_id ) <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 ) </s>
