In the same file in the Django property app, we define a method that returns a JSON response to a jQuery AJAX request for room information. Again, as before, if the property key is present in the request, we use the property service to retrieve a Property instance:
def autoPopRoomsByPropKey(request, prop_key = None) :
import json
config = Config()
propSvc = PropertyService(config)
result = []
if prop_key :
temp = propSvc.fetchRoomsByPropertyKey(prop_key)
If we are able to get an instance, we flatten the RoomType.beds property list into a string:
if temp :
for rooms in temp :
beds = ''
for val in rooms['beds'] :
beds += val + ', '
beds = beds[0:-2]
We then formulate a return value as a JSON encoded list of dictionaries:
room_config = config.getConfig('rooms')
link = '<a target="...