#NEWLINE# def save( self , instance = None , commit = True ) : #NEWLINE# #INDENT# if self . errors : #NEWLINE# #INDENT# raise ValueError ( 'form does not validate' ) #NEWLINE# #UNINDENT# location = ( instance or self . location ) #NEWLINE# is_new = ( location . location_id is None ) #NEWLINE# for field in ( 'name' , 'location_type' , 'site_code' ) : #NEWLINE# #INDENT# setattr ( location , field , self . cleaned_data [ field ] ) #NEWLINE# #UNINDENT# coords = self . cleaned_data [ 'coordinates' ] #NEWLINE# setattr ( location , 'latitude' , ( coords [ 0 ] if coords else None ) ) #NEWLINE# setattr ( location , 'longitude' , ( coords [ 1 ] if coords else None ) ) #NEWLINE# if self . cleaned_data [ 'parent_id' ] : #NEWLINE# #INDENT# location . lineage = get_lineage_from_location_id ( self . cleaned_data [ 'parent_id' ] ) #NEWLINE# #UNINDENT# location . metadata = self . custom_data . get_data_to_save ( ) #NEWLINE# for ( k , v ) in self . cleaned_data . iteritems ( ) : #NEWLINE# #INDENT# if k . startswith ( 'prop:' ) : #NEWLINE# #INDENT# prop_name = k [ len ( 'prop:' ) : ] #NEWLINE# setattr ( location , prop_name , v ) #NEWLINE# #UNINDENT# #UNINDENT# orig_parent_id = self . cleaned_data . get ( 'orig_parent_id' ) #NEWLINE# reparented = ( orig_parent_id is not None ) #NEWLINE# if reparented : #NEWLINE# #INDENT# location . flag_post_move = True #NEWLINE# location . previous_parents . append ( orig_parent_id ) #NEWLINE# #UNINDENT# if commit : #NEWLINE# #INDENT# location . save ( ) #NEWLINE# #UNINDENT# if ( not is_new ) : #NEWLINE# #INDENT# location_edited . send ( sender = 'loc_mgmt' , loc = location , moved = reparented ) #NEWLINE# #UNINDENT# return location