We are now in a position to define view methods, entered into /path/to/repo/www/chapter_09/trends/views.py. The first method defined is future(). It defines initial form values, creates a TrendForm instance, renders it using the trend.html template, and injects the resulting HTML into the layout. The only other method is futureJson(), which responds to an AJAX request. Its main job is to make a call to the BookingService class instance, which is in the booksomeplace.domain.booking module:
def futureJson(request) :
import json
bookSvc = BookingService(Config())
params = {
'trend_city' : None,
'trend_region' : 'England',
'trend_locality' : None,
'trend_country' : 'GB',
'trend_factor' : 0.10
}
if request.method == 'POST':
params = request.POST
data = bookSvc.getTrendData(params)
return HttpResponse(json.dumps(data)...