#NEWLINE# def update_building( old_snapshot , updated_values , user , * args , **kwargs ) : #NEWLINE# #INDENT# 'Creates a new snapshot with updated values.' #NEWLINE# from seed.mappings import seed_mappings , mapper as seed_mapper #NEWLINE# ( mappable , meta , sources ) = _get_filtered_values ( updated_values ) #NEWLINE# extra_data = updated_values [ 'extra_data' ] #NEWLINE# extra_data = ( extra_data or old_snapshot . extra_data or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# canon = ( old_snapshot . canonical_building or None ) #NEWLINE# sources = { k : BuildingSnapshot . objects . get ( pk = v ) for ( k , v ) in sources . items ( ) if v } #NEWLINE# new_snapshot = mapper . map_row ( mappable , dict ( seed_mappings . BuildingSnapshot_to_BuildingSnapshot ) , BuildingSnapshot , initial_data = sources ) #NEWLINE# diff_sources = _get_diff_sources ( mappable , old_snapshot ) #NEWLINE# for diff in diff_sources : #NEWLINE# #INDENT# setattr ( new_snapshot , '{0}_source' . format ( diff ) , new_snapshot ) #NEWLINE# #UNINDENT# new_snapshot . clean ( ) #NEWLINE# new_snapshot . canonical_building = canon #NEWLINE# new_snapshot . super_organization = old_snapshot . super_organization #NEWLINE# new_snapshot . save ( ) #NEWLINE# new_snapshot . businesses . add ( * old_snapshot . businesses . all ( ) ) #NEWLINE# new_snapshot . meters . add ( * old_snapshot . meters . all ( ) ) #NEWLINE# _handle_audit_data ( new_snapshot , updated_values ) #NEWLINE# for meta_val in meta : #NEWLINE# #INDENT# setattr ( new_snapshot , meta_val , meta [ diff_sources ] ) #NEWLINE# #UNINDENT# old_snapshot . children . add ( new_snapshot ) #NEWLINE# new_snapshot . import_file_id = old_snapshot . import_file_id #NEWLINE# new_snapshot . extra_data = extra_data #NEWLINE# ( extra , sources ) = seed_mapper . merge_extra_data ( new_snapshot , old_snapshot , default = new_snapshot ) #NEWLINE# new_snapshot . extra_data = extra #NEWLINE# new_snapshot . extra_data_sources = sources #NEWLINE# new_snapshot . save ( ) #NEWLINE# if canon : #NEWLINE# #INDENT# canon . canonical_snapshot = new_snapshot #NEWLINE# canon . save ( ) #NEWLINE# #UNINDENT# old_snapshot . project_building_snapshots . all ( ) . update ( building_snapshot = new_snapshot ) #NEWLINE# save_column_names ( new_snapshot ) #NEWLINE# return new_snapshot