#NEWLINE# @ ajax_request #NEWLINE# @ login_required #NEWLINE# @ has_perm ( 'can_modify_data' ) #NEWLINE# def add_meter_to_building( request ) : #NEWLINE# #INDENT# "Will add a building to an existing meter.\n\n    Payload is expected to look like the following:\n    {\n        'organization_id': 435,\n        'building_id': 342,\n        'meter_name': 'Unit 34.',\n        'energy_type': 'Electricity',\n        'energy_units': 'kWh'\n    }\n    " #NEWLINE# body = json . loads ( request . body ) #NEWLINE# building_id = body . get ( 'building_id' , '' ) #NEWLINE# building = BuildingSnapshot . objects . get ( pk = building_id ) #NEWLINE# meter_name = body . get ( 'meter_name' , '' ) #NEWLINE# energy_type_name = body . get ( 'energy_type' , 'Electricity' ) #NEWLINE# energy_unit_name = body . get ( 'energy_units' , 'kWh' ) #NEWLINE# energy_type = convert_choice_data ( energy_type_name , ENERGY_TYPES ) #NEWLINE# energy_units = convert_choice_data ( energy_type_name , ENERGY_UNITS ) #NEWLINE# meter = Meter . objects . create ( name = meter_name , energy_type = energy_type , energy_units = energy_units ) #NEWLINE# meter . building_snapshot . add ( building ) #NEWLINE# meter . save ( ) #NEWLINE# return { #NEWLINE# #INDENT# 'status' : 'success' , #NEWLINE# #UNINDENT# }