def player(request, company_name, player_id): try: company = Company.objects.filter(short_name=company_name).get() except ObjectDoesNotExist: # todo: show signup form raise Http404() # check permission if not company.check_permission(request.user): # todo: show permission denied raise Http404() # look for target player in the same company try: player = Player.objects.filter(company=company, id=player_id).get() except ObjectDoesNotExist: raise Http404() # check if company is currently recalculating if company.recalculating: return render(request, 'techpong/recalculating.html', {'company': company}) # process cached data cached_results = json.loads(player.cached_results or '[]') cached_ratings = json.loads(player.cached_rating_changes or '[]') cached_ranks = json.loads(player.cached_rank_changes or '[]') create_sparklines(player) # ratings graphs ymin, ymax = None, None for rating_info in cached_ratings: rating = rating_info['rating'] if rating < ymin or ymin is None: ymin = rating if rating > ymax or ymax is None: ymax = rating if ymin is None: ymin = 0 if ymax is None: ymax = 500 ratings_spread = ymax - ymin graph_offset = RATINGS_GRAPH_RANGE_MULTIPLIER * ratings_spread graph_min = max(0, 10 * round((ymin - graph_offset) / 10)) graph_max = 10 * math.ceil((ymax + graph_offset) / 10) # render the player screen return render( request, 'techpong/player.html', { 'player': player, 'company': company, 'cached_results': cached_results, 'cached_ratings': cached_ratings, 'cached_ranks': cached_ranks, 'ymin': graph_min, 'ymax': graph_max })
def player(request, company_name, player_id): try: company = Company.objects.filter(short_name = company_name).get() except ObjectDoesNotExist: # todo: show signup form raise Http404() # check permission if not company.check_permission(request.user): # todo: show permission denied raise Http404() # look for target player in the same company try: player = Player.objects.filter(company=company, id=player_id).get() except ObjectDoesNotExist: raise Http404() # check if company is currently recalculating if company.recalculating: return render(request, 'techpong/recalculating.html', { 'company': company }) # process cached data cached_results = json.loads(player.cached_results or '[]') cached_ratings = json.loads(player.cached_rating_changes or '[]') cached_ranks = json.loads(player.cached_rank_changes or '[]') create_sparklines(player) # ratings graphs ymin, ymax = None, None for rating_info in cached_ratings: rating = rating_info['rating'] if rating < ymin or ymin is None: ymin = rating if rating > ymax or ymax is None: ymax = rating if ymin is None: ymin = 0 if ymax is None: ymax = 500 ratings_spread = ymax - ymin graph_offset = RATINGS_GRAPH_RANGE_MULTIPLIER * ratings_spread graph_min = max(0, 10 * round((ymin - graph_offset) / 10)) graph_max = 10 * math.ceil((ymax + graph_offset) / 10) # render the player screen return render(request, 'techpong/player.html', { 'player': player, 'company': company, 'cached_results': cached_results, 'cached_ratings': cached_ratings, 'cached_ranks': cached_ranks, 'ymin': graph_min, 'ymax': graph_max })
def dashboard(request, company_name): try: company = Company.objects.filter(short_name = company_name).get() except ObjectDoesNotExist: return render( request, 'techpong/error.html', dict( error_title="Company Not Found", error_message='Could not find Company "%s"' % company_name ) ) # check permission if not company.check_permission(request.user): return render( request, 'techpong/error.html', dict( error_title="Permission Denied", error_message='You do not have permission to access this ladder. You may need to log in to a different account.' ) ) # check if company is currently recalculating if company.recalculating: return render(request, 'techpong/recalculating.html', { 'company': company }) # get company info company_info = company.get_info() # go through each player and add sparkline graph info for player in company_info['players']: create_sparklines(player) # notifications notifications = Notification.objects.all() if request.user.profile.last_viewed_notifications: notifications = notifications.filter( notification_time__gte=request.user.profile.last_viewed_notifications ) notifications = notifications[:10] # render the dashboard return render(request, 'techpong/dashboard.html', { "csrf_token": csrf(request)['csrf_token'], 'company': company, 'info': company_info, 'notifications': notifications })
def dashboard(request, company_name): try: company = Company.objects.filter(short_name=company_name).get() except ObjectDoesNotExist: return render( request, 'techpong/error.html', dict(error_title="Company Not Found", error_message='Could not find Company "%s"' % company_name)) # check permission if not company.check_permission(request.user): return render( request, 'techpong/error.html', dict( error_title="Permission Denied", error_message= 'You do not have permission to access this ladder. You may need to log in to a different account.' )) # check if company is currently recalculating if company.recalculating: return render(request, 'techpong/recalculating.html', {'company': company}) # get company info company_info = company.get_info() # go through each player and add sparkline graph info for player in company_info['players']: create_sparklines(player) # notifications notifications = Notification.objects.all() if request.user.profile.last_viewed_notifications: notifications = notifications.filter( notification_time__gte=request.user.profile. last_viewed_notifications) notifications = notifications[:10] # render the dashboard return render( request, 'techpong/dashboard.html', { "csrf_token": csrf(request)['csrf_token'], 'company': company, 'info': company_info, 'notifications': notifications })