#NEWLINE# @ records . route ( '/<zone_id>/update' , methods = [ 'GET' , 'POST' ] ) #NEWLINE# def records_update( zone_id ) : #NEWLINE# #INDENT# from route53.models import ChangeBatch , Change , db #NEWLINE# conn = get_connection ( ) #NEWLINE# zone = conn . get_hosted_zone ( zone_id ) [ 'GetHostedZoneResponse' ] [ 'HostedZone' ] #NEWLINE# val_dict = get_record_fields ( ) #NEWLINE# if ( request . method == 'GET' ) : #NEWLINE# #INDENT# values = request . args . getlist ( 'value' ) #NEWLINE# if ( not values ) : #NEWLINE# #INDENT# abort ( 404 ) #NEWLINE# #UNINDENT# initial_data = dict ( val_dict ) #NEWLINE# initial_data [ 'value' ] = ';' . join ( values ) #NEWLINE# form = RecordForm ( ** initial_data ) #NEWLINE# #UNINDENT# error = None #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = RecordForm ( ) #NEWLINE# change_batch = ChangeBatch ( change_id = '' , status = 'created' , comment = form . comment . data ) #NEWLINE# db . session . add ( change_batch ) #NEWLINE# values = request . form . getlist ( 'data_value' ) #NEWLINE# delete_change = Change ( action = 'DELETE' , change_batch_id = change_batch . id , values = { #NEWLINE# #INDENT# 'values' : values , #NEWLINE# #UNINDENT# } , ** val_dict ) #NEWLINE# create_change = Change ( action = 'CREATE' , change_batch_id = change_batch . id , values = { #NEWLINE# #INDENT# 'values' : form . values , #NEWLINE# #UNINDENT# } , type = form . type . data , ttl = form . ttl . data , name = form . name . data ) #NEWLINE# db . session . add ( delete_change ) #NEWLINE# db . session . add ( create_change ) #NEWLINE# rendered_xml = render_change_batch ( { #NEWLINE# #INDENT# 'changes' : [ delete_change , create_change ] , #NEWLINE# 'comment' : change_batch . comment , #NEWLINE# #UNINDENT# } ) #NEWLINE# try : #NEWLINE# #INDENT# resp = conn . change_rrsets ( zone_id , rendered_xml ) #NEWLINE# change_batch . process_response ( resp ) #NEWLINE# db . session . commit ( ) #NEWLINE# return redirect ( url_for ( 'zones.zones_records' , zone_id = zone_id ) ) #NEWLINE# #UNINDENT# except DNSServerError as error : #NEWLINE# #INDENT# error = error #NEWLINE# #UNINDENT# #UNINDENT# return render_template ( 'records/update.html' , val_dict = val_dict , values = values , form = form , zone = zone , zone_id = zone_id , error = error )