def lines(request): abbr = request.POST['abbr'] name = request.POST['name'] coach_info = boxscore.get_coach_info(abbr) box = boxscore.get_boxscore(abbr, name) template = loader.get_template('linesform.html') html = template.render(Context({"starters": box[0], "bench": box[1], "coach": coach_info})) return HttpResponse(simplejson.dumps({'html': html}), mimetype='application/javascript')
def markup(request): abbr = request.POST['abbr'] name = request.POST['name'] box = boxscore.get_boxscore(abbr, name) starters = box[0] bench = box[1] game_id = box[2] abbrs = box[3] names = box[4] score = box[5] starters = decorate_lines(request, starters) bench = decorate_lines(request, bench) if 'show_nba_data' in request.POST: starters = add_nba_data(starters, abbr) bench = add_nba_data(bench, abbr) coach = {'name': request.POST['coach_name'], 'image': request.POST['coach_image'], 'blurb': request.POST['coach_blurb'], 'rating': request.POST['coach_rating']} allow_user_voting = 'allow_user_voting' in request.POST # utah workaoround #if abbrs[0] == 'utah': # abbrs[0] = 'uta' #if abbrs[1] == 'utah': # abbrs[1] = 'uta' # list of things things = [] for t in request.POST.getlist('things'): if t != '': things.append(t) num_names = ['One Thing', 'Two Things', 'Three Things', 'Four Things', 'Five Things'] str_things_count = None if things: str_things_count = num_names[len(things)-1] # create html template = loader.get_template('reaction.html') html = template.render(Context({"allow_user_voting": allow_user_voting, "team_id": abbr, "starters": starters, "bench": bench, 'game_id': game_id, 'abbrs': abbrs, 'names': names, 'score': score, 'things': things, 'str_things_count': str_things_count, 'coach': coach})) # create css location = "/www/Recap-Generator/recaphack/static/styles.css" f = open(location, "r") css = f.read() r = Recap(html=html, css=css, home_abbr=abbrs[1], away_abbr=abbrs[0], home_name=names[1], away_name=names[0], home_score=score[1], away_score=score[0]) home_abbr = abbrs[1] r.save() # css and html combined into one payload to be returned to browser template = loader.get_template('markup.html') full_markup = template.render(Context({"css": css, "html": html, "id": r.id })) return HttpResponse(simplejson.dumps({'html': full_markup}), mimetype='application/javascript')