Exemplo n.º 1
0
def csv_data_former(request):
    """ Generates a form for downloading a particular time period
        shifts in CSV format.
    """
    #TODO Make it compatible with the csv_data_generator

    if request.method == 'POST':
        form = DataForm(request.POST)
        if form.is_valid():
            end_date = form.cleaned_data['end_date']
            start_date = form.cleaned_data['start_date']
            shifts = Shift.objects.filter(intime__gte=start_date.strftime("%Y-%m-%d %X"), outtime__lte=end_date.strftime("%Y-%m-%d 23:59:59"))
            response = csv_data_generator(shifts)
            return response
    else:
        form = DataForm()
    return render_to_response('csv_form.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 2
0
def csv_data_former(request):
    """ Generates a form for downloading a particular time period
        shifts in CSV format.
    """
    params = {'request': request}
    if not request.user.is_staff:
        params['message'] = 'Permission Denied'
        params['reason'] = 'You do not have permission to visit this part of the page.'
        return render_to_response('fail.html', params)

    if request.method == 'POST':
        form = DataForm(request.POST)
        if form.is_valid():
            end_date = form.cleaned_data['end_date']
            start_date = form.cleaned_data['start_date']
            shifts = Shift.objects.filter(intime__gte=start_date.strftime("%Y-%m-%d %X"), outtime__lte=end_date.strftime("%Y-%m-%d 23:59:59"))
            response = csv_data_generator(shifts, end_date=end_date, start_date=start_date)
            return response
    else:
        form = DataForm()
        params['form'] = form
    return render_to_response('csv_form.html', params, context_instance=RequestContext(request))
Exemplo n.º 3
0
def csv_data_former(request):
    """ Generates a form for downloading a particular time period
        shifts in CSV format.
    """
    params = {'request': request}
    if not request.user.is_staff:
        params['message'] = 'Permission Denied'
        params['reason'] = 'You do not have permission to visit this part of the page.'
        return render_to_response('fail.html', params)

    if request.method == 'POST':
        form = DataForm(request.POST)
        if form.is_valid():
            end_date = form.cleaned_data['end_date']
            start_date = form.cleaned_data['start_date']
            shifts = Shift.objects.filter(intime__gte=start_date.strftime("%Y-%m-%d %X"), outtime__lte=end_date.strftime("%Y-%m-%d 23:59:59"))
            response = csv_data_generator(shifts, end_date=end_date, start_date=start_date)
            return response
    else:
        form = DataForm()
        params['form'] = form
    return render_to_response('csv_form.html', params, context_instance=RequestContext(request))
Exemplo n.º 4
0
def get_total_hours(request):
    """This method returns the cumulative hours worked by all employees in the
       range entered by the user in the form.
    """
    params = {'request': request}
    if request.method == 'POST':
        form = HourForm(request.POST)
        params['form'] = form
        if form.is_valid():
            end_date = form.cleaned_data['end_date']
            start_date = form.cleaned_data['start_date']
            shifts = Shift.objects.filter(intime__gte=start_date.strftime("%Y-%m-%d %X"), outtime__lte=end_date.strftime("%Y-%m-%d 23:59:59"))
            temp = []
            for i in shifts:
                temp.append(i.person)
            all_people_working = set(temp)
            all_people_working = list(all_people_working)
            shifter = defaultdict(list)
            totaler = []
            for worker in all_people_working:
                shifts_per_person = Shift.objects.filter(intime__gte=start_date.strftime("%Y-%m-%d %X"), outtime__lte=end_date.strftime("%Y-%m-%d 23:59:59"), person=worker)
                total = 0.0
                for each in shifts_per_person:
                    total = total + float(each.length())
                total_per_person = [
                    worker.__str__(),
                    round(total, 2),
                ]
                totaler.append(total_per_person)

            params['totaler'] = totaler
            return render_to_response('total_hours.html', params, context_instance=RequestContext(request))
    else:
        form = DataForm()
        params['form'] = form
    return render_to_response('total_hours.html', params, context_instance=RequestContext(request))