<s> import subprocess <EOL> import time <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> from pushmanager . core . settings import Settings <EOL> from pushmanager . core . xmppclient import XMPPQueue <EOL> from pushmanager . core . util import send_people_msg_in_groups <EOL> def send_notifications ( people , pushtype , pushmanager_url ) : <EOL> pushmanager_servername = Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if people : <EOL> msg = '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( people ) , pushtype , pushmanager_url ) <EOL> XMPPQueue . enqueue_user_xmpp ( people , '<STR_LIT>' % pushmanager_url ) <EOL> elif pushtype == '<STR_LIT>' : <EOL> msg = '<STR_LIT>' % pushmanager_servername <EOL> else : <EOL> msg = '<STR_LIT>' % pushmanager_url <EOL> if people : <EOL> send_people_msg_in_groups ( <EOL> people , "<STR_LIT>" % ( pushtype , pushmanager_url ) , <EOL> Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> person_per_group = <NUM_LIT:5> , prefix_msg = '<STR_LIT>' <EOL> ) <EOL> else : <EOL> subprocess . call ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> msg <EOL> ] ) <EOL> subject = "<STR_LIT>" <EOL> MailQueue . enqueue_user_email ( Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , msg , subject ) <EOL> class NewPushServlet ( 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 . pushtype = self . _arg ( '<STR_LIT>' ) <EOL> insert_query = db . push_pushes . insert ( { <EOL> '<STR_LIT:title>' : self . _arg ( '<STR_LIT>' ) , <EOL> '<STR_LIT:user>' : self . current_user , <EOL> '<STR_LIT>' : self . _arg ( '<STR_LIT>' ) . strip ( ) , <EOL> '<STR_LIT>' : "<STR_LIT:0>" * <NUM_LIT> , <EOL> '<STR_LIT>' : time . time ( ) , <EOL> '<STR_LIT>' : time . time ( ) , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . pushtype , <EOL> } ) <EOL> select_query = db . push_requests . select ( ) . where ( <EOL> db . push_requests . c . state == '<STR_LIT>' , <EOL> ) <EOL> db . execute_transaction_cb ( [ insert_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> insert_results , select_results = db_results <EOL> pushurl = '<STR_LIT>' % insert_results . lastrowid <EOL> pushmanager_url = self . get_base_url ( ) + pushurl <EOL> def users_involved ( request ) : <EOL> if request [ '<STR_LIT>' ] : <EOL> return [ request [ '<STR_LIT:user>' ] ] + request [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) <EOL> return [ request [ '<STR_LIT:user>' ] ] <EOL> if self . pushtype in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> people = None <EOL> elif self . pushtype == '<STR_LIT>' : <EOL> people = set ( user for x in select_results for user in users_involved ( x ) if '<STR_LIT>' in x [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> else : <EOL> people = set ( user for x in select_results for user in users_involved ( x ) ) <EOL> send_notifications ( people , self . pushtype , pushmanager_url ) <EOL> return self . redirect ( pushurl ) </s>
