Example #1
0
def get_team(request, draft_id):
    """ This function is triggered by an HTTP GET request. It returns all of the
    players in this draft that have been drafted by the manager specified in the
    request. The data is formatted in JSON along with that managers value.
    """

    manager_name = request.session['manager']

    draft = Draft.objects.get(id=draft_id)
    manager = Manager.objects.get(draft=draft, name=manager_name)
    players = Player.objects.filter(draft=draft, manager=manager, timer=None)

    # Now we want to sort the list of players based on the quotas specified in
    # the draft and their values.

    team = []
    players = players.order_by('-value')
    for pos in draft.quota:
        slot = [pos, '', '']
        p = players.filter(position=pos)
        if p.exists():
            slot[1] = p[0].name
            slot[2] = p[0].value
            players = players.exclude(id=p[0].id)
        team.append(slot)

    # Add additional players that do not contribute to the teams overall value

    for p in players:
        team.append([p.position, p.name, p.value])

    response = {'team': team}
    return HttpResponse(dumps(response), content_type="application/json")
Example #2
0
def get_manager_updates(request, draft_id):
    """ This function is triggered by an HTTP GET request. It returns all of the
    managers in the database that have been modified since the time specified in
    the request. The data is formatted in JSON along with a timestamp of when
    the request was made.
    """

    now = datetime.now()
    since_str = request.GET.get('since', min_time_str)
    since = parser.parse(since_str)

    managers = Manager.objects.filter(draft=draft_id, verified=True, modified__gt=since)

    response = {'time': now.isoformat(), 'managers': managers}
    return HttpResponse(dumps(response), content_type="application/json")