<s> from collections import defaultdict <EOL> import sqlalchemy as SA <EOL> import pushmanager . core . db as db <EOL> import pushmanager . core . util <EOL> from pushmanager . core . requesthandler import RequestHandler <EOL> checklist_reminders = { <EOL> '<STR_LIT>' : dict ( ( target , '<STR_LIT>' ) for target in ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } <EOL> class ChecklistServlet ( RequestHandler ) : <EOL> def get ( 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> self . pushmaster = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT>' ) <EOL> c = db . push_checklist . c <EOL> r = db . push_requests . c <EOL> query = SA . select ( [ <EOL> c . target , c . type , c . complete , c . id , c . request , <EOL> r . title , r . repo , r . branch , r . user , <EOL> ] ) . where ( SA . and_ ( <EOL> r . id == c . request , <EOL> r . state != '<STR_LIT>' , <EOL> c . request == db . push_pushcontents . c . request , <EOL> db . push_pushcontents . c . push == self . pushid , <EOL> ) ) <EOL> db . execute_cb ( query , self . on_db_complete ) <EOL> post = get <EOL> def on_db_complete ( self , success , db_results ) : <EOL> if not success or db_results is None : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> items_by_target = { } <EOL> for item in db_results : <EOL> items_by_target . setdefault ( item [ '<STR_LIT:target>' ] , [ ] ) . append ( item ) <EOL> self . render ( <EOL> "<STR_LIT>" , <EOL> pushmaster = self . pushmaster , <EOL> items_by_target = self . __dedup_search_list ( items_by_target ) , <EOL> item_count = db_results . rowcount , <EOL> checklist_reminders = checklist_reminders <EOL> ) <EOL> def __dedup_search_list ( self , items_by_target ) : <EOL> clean_items_by_target = defaultdict ( list ) <EOL> for target , items in items_by_target . items ( ) : <EOL> merge_items = defaultdict ( list ) <EOL> for item in items : <EOL> if item [ '<STR_LIT:type>' ] == "<STR_LIT>" : <EOL> clean_items_by_target [ target ] . append ( item ) <EOL> else : <EOL> merge_items [ item [ '<STR_LIT:type>' ] ] . append ( item ) <EOL> for type_ , items in merge_items . iteritems ( ) : <EOL> if len ( items ) > <NUM_LIT:1> : <EOL> users = set ( item [ '<STR_LIT:user>' ] for item in items ) <EOL> ids = [ str ( item [ '<STR_LIT:id>' ] ) for item in items ] <EOL> is_complete = all ( [ item [ '<STR_LIT>' ] for item in items ] ) <EOL> merged_item = { <EOL> "<STR_LIT:target>" : target , <EOL> "<STR_LIT:type>" : type_ , <EOL> "<STR_LIT>" : is_complete , <EOL> "<STR_LIT:id>" : u"<STR_LIT:U+002C>" . join ( ids ) , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT:title>" : u"<STR_LIT>" , <EOL> "<STR_LIT>" : u"<STR_LIT>" , <EOL> "<STR_LIT>" : u'<STR_LIT>' , <EOL> "<STR_LIT:user>" : u"<STR_LIT:U+002C>" . join ( users ) <EOL> } <EOL> clean_items_by_target [ target ] . append ( merged_item ) <EOL> elif len ( items ) == <NUM_LIT:1> : <EOL> clean_items_by_target [ target ] . append ( items [ <NUM_LIT:0> ] ) <EOL> return dict ( clean_items_by_target ) <EOL> class ChecklistToggleServlet ( RequestHandler ) : <EOL> def post ( self ) : <EOL> if not self . current_user : <EOL> return self . send_error ( <NUM_LIT> ) <EOL> self . checklist = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT:id>' ) <EOL> new_value = pushmanager . core . util . get_int_arg ( self . request , '<STR_LIT>' ) <EOL> query = db . push_checklist . update ( ) . where ( <EOL> db . push_checklist . c . id == self . checklist ) . values ( { '<STR_LIT>' : new_value } ) <EOL> db . execute_cb ( query , lambda _ , __ : None ) </s>
