Example #1
0
def index(request):
    if not request.POST:
        params = {}
        return render(request, 'index.html', params)
    else:
        f = ByTeamForm(request.POST)

    if not f.is_valid():
        return HttpResponse("Invalid arguments", status=400)

    r = f.cleaned_data
    team_id = r['team_id'] or 1

    teams = Team.objects.values_list('id', 'name', 'members__username')
    teams = sorted(teams, key=itemgetter(0, 1))

    if not len(teams):
        return HttpResponse("There are no teams created yet", status=404)

    requested_members = []
    t = []
    for (_id, name), data in groupby(teams, itemgetter(0, 1)):
        members = [x[-1] for x in data]

        active = False
        if _id == team_id:
            requested_members = members
            active = True

        t.append({
            'id': _id,
            'name': name,
            'members': members,
            'active': active
        })

    if not requested_members:
        return HttpResponse(status=404)

    resp = {
        'teams':
        t,
        'data_by_user':
        data_by_user(requested_members, r['start_date'], r['end_date'])
    }

    return HttpResponse(json.dumps(resp, cls=SetEncoder),
                        content_type='application/json')
Example #2
0
def team_users(request):
    f = ByTeamForm(request.GET)
    if not f.is_valid():
        return HttpResponse('Invalid arguments', status=400)

    r = f.cleaned_data
    t, members = get_team_members(r['team_slug'])

    users = []
    for k, v in data_by_user(members, r['start_date'], r['end_date']).items():
        v['username'] = k
        users.append(v)

    resp = {'data': users, 'workhours': get_workhours(r['start_date'])}
    return HttpResponse(json.dumps(resp, cls=SetEncoder),
                        content_type='application/json')
Example #3
0
def index(request):
    if not request.POST:
        params = {
        }
        return render(request, 'index.html', params)
    else:
        f = ByTeamForm(request.POST)

    if not f.is_valid():
        return HttpResponse("Invalid arguments", status=400)

    r = f.cleaned_data
    team_id = r['team_id'] or 1

    teams = Team.objects.values_list('id', 'name', 'members__username')
    teams = sorted(teams, key=itemgetter(0, 1))

    if not len(teams):
        return HttpResponse("There are no teams created yet", status=404)

    requested_members = []
    t = []
    for (_id, name), data in groupby(teams, itemgetter(0, 1)):
        members = [x[-1] for x in data]

        active = False
        if _id == team_id:
            requested_members = members
            active = True

        t.append({'id': _id, 'name': name, 'members': members,
                  'active': active})

    if not requested_members:
        return HttpResponse(status=404)

    resp = {
        'teams': t,
        'data_by_user': data_by_user(requested_members,
                                     r['start_date'], r['end_date'])
    }

    return HttpResponse(json.dumps(resp, cls=SetEncoder),
                        content_type='application/json')
Example #4
0
def team_tickets(request):
    f = ByTeamForm(request.GET)
    if not f.is_valid():
        return HttpResponse('Invalid arguments', status=400)

    r = f.cleaned_data
    t, members = get_team_members(r['team_slug'])

    tickets = []
    data = data_by_ticket(members, r['start_date'], r['end_date'])
    for k, v in sorted(data.items(),
                       key=lambda x: x[1]['spent_hours'],
                       reverse=True):
        v['ticket'] = k
        tickets.append(v)

    resp = {'data': tickets, 'workhours': get_workhours(r['start_date'])}
    return HttpResponse(json.dumps(resp, cls=SetEncoder),
                        content_type='application/json')