<s> from collections import defaultdict <EOL> from changes . api . serializer import Crumbler , register <EOL> from changes . models import JobStep , JobPlan <EOL> @ register ( JobStep ) <EOL> class JobStepCrumbler ( Crumbler ) : <EOL> def get_extra_attrs_from_db ( self , item_list ) : <EOL> result = { } <EOL> job_id_to_steps = defaultdict ( list ) <EOL> for step in item_list : <EOL> job_id_to_steps [ step . job_id ] . append ( step ) <EOL> if job_id_to_steps : <EOL> for jobplan in JobPlan . query . filter ( JobPlan . job_id . in_ ( job_id_to_steps . keys ( ) ) ) : <EOL> for step in job_id_to_steps [ jobplan . job_id ] : <EOL> result [ step ] = { '<STR_LIT>' : jobplan } <EOL> for step in item_list : <EOL> if step not in result : <EOL> result [ step ] = { '<STR_LIT>' : None } <EOL> return result <EOL> def crumble ( self , instance , attrs ) : <EOL> jobplan = attrs [ '<STR_LIT>' ] <EOL> return { <EOL> '<STR_LIT:id>' : instance . id . hex , <EOL> '<STR_LIT:name>' : instance . label , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : instance . phase_id . hex , <EOL> } , <EOL> '<STR_LIT:data>' : dict ( instance . data ) , <EOL> '<STR_LIT:result>' : instance . result , <EOL> '<STR_LIT:status>' : instance . status , <EOL> '<STR_LIT:image>' : jobplan and jobplan . snapshot_image , <EOL> '<STR_LIT>' : instance . node , <EOL> '<STR_LIT>' : instance . duration , <EOL> '<STR_LIT>' : instance . replacement_id , <EOL> '<STR_LIT>' : instance . date_created , <EOL> '<STR_LIT>' : instance . date_started , <EOL> '<STR_LIT>' : instance . date_finished , <EOL> } </s>
