Пример #1
0
def eff(request):
    """
    Sin parámetros esta vista entra directamente a la semana en curso.
    """
    context = __get_context(request)
    eff_query_form = EffQueryForm()
    context['form'] = eff_query_form

    if request.method == 'GET':
        get_data = request.GET.copy()
        eff_query_form = EffQueryForm(get_data)
        context['form'] = eff_query_form

        if eff_query_form.is_valid():
            from_date = eff_query_form.cleaned_data['from_date']
            to_date = eff_query_form.cleaned_data['to_date']
        else:
            # If form is invalid set dates to the current week and
            # reset the form to the same date
            from_date, to_date = week(date.today())
            context['form'] = EffQueryForm({'from_date': from_date,
                                            'to_date': to_date})

        object_list = UserProfile.objects.all()

        data_list = [Data(o,from_date,to_date) for o in object_list]

        wh, lh, bh = 0, 0, 0
        for d in data_list:
            wh += d.worked_hours
            lh += d.loggable_hours
            bh += d.billable_hours
        context['total'] = DataTotal(wh,lh,bh)
        context['object_list'] = data_list
        context['from_date'] = from_date
        context['to_date'] = to_date

        for flag in (OVERTIME_FLAG, MONTHLY_FLAG):
            if flag in request.GET:
                context[flag] = request.GET[flag]

        context['navs'] = [('prev', 'previo', '«'), ('next', 'siguiente', '»')]
        if from_date == to_date:
            aux = "el %s" % from_date
        elif MONTHLY_FLAG in context:
            aux = "durante el mes de %s" % from_date.strftime('%B de %Y') # month name
        elif OVERTIME_FLAG in context:
            aux = "durante el período de horas extras [%s, %s]" % (from_date, to_date)
        else:
            aux = "entre %s y %s" % (from_date, to_date)
        context['title'] = "Horas Logueadas %s" % aux

    return render_to_response('eff_query.html', context)
Пример #2
0
def eff_client_reports_admin(request):
    context = __get_context(request)

    if 'period' in request.GET:
        if request.GET['period']=='current_month':
            from_date, to_date = month(date.today())
        elif request.GET['period']=='last_month':
            from_date, to_date = month(month(date.today())[0]-timedelta(days=1))
    else:
        if 'from_date' in request.GET and 'to_date' in request.GET:
            from_date = __aux_mk_time(request.GET['from_date'])
            to_date = __aux_mk_time(request.GET['to_date'])
        else:
            # Current week by default
            from_date, to_date = week(date.today())

    initial = {'from_date' : from_date.strftime("%Y-%m-%d"),
               'to_date' : to_date.strftime("%Y-%m-%d")}

    context['title'] = "Reporte de Clientes"

    client_report_form = ClientReportForm(initial=initial)
    context['form'] = client_report_form
    if request.method == 'POST':
        client_report_form = ClientReportForm(request.POST)
        context['form'] = client_report_form
        if client_report_form.is_valid():
            from_date = client_report_form.cleaned_data['from_date']
            to_date = client_report_form.cleaned_data['to_date']
            client = client_report_form.cleaned_data['client']

            redirect_to = '/efi/reporte_cliente/%s/?from_date=%s&to_date=%s' % (client.slug, from_date, to_date,)

            if MONTHLY_FLAG in request.GET:
                redirect_to += '&%s=%s' % (MONTHLY_FLAG, request.GET[MONTHLY_FLAG], )

            return HttpResponseRedirect(redirect_to)

    return render_to_response('admin_reportes_cliente.html', context)
Пример #3
0
def eff_current_week(request):
    return HttpResponseRedirect('/efi/?from_date=%s&to_date=%s' % week(date.today()))