예제 #1
0
파일: views.py 프로젝트: emilioramirez/eff
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)
예제 #2
0
파일: views.py 프로젝트: emilioramirez/eff
def __process_period(request, is_prev):
    context = __process_dates(request)
    from_date = context['from_date']
    to_date = context['to_date']

    if is_prev:
        reference_date = context['from_date'] - relativedelta(days=1)
        op = lambda x,y: x - y
    else:
        reference_date = context['to_date'] + relativedelta(days=1)
        op = lambda x,y: x + y

    aux = '&%s=True'
    if OVERTIME_FLAG in request.GET:
        (from_date, to_date) = overtime_period(reference_date)
        aux = aux % OVERTIME_FLAG
    elif MONTHLY_FLAG in request.GET:
        (from_date, to_date) = month(reference_date)
        aux = aux % MONTHLY_FLAG
    else:
        (from_date, to_date) = period(context['from_date'],
                                      context['to_date'],
                                      op)
        aux = ''

    referer = '/'.join(request.META['HTTP_REFERER'].split('/')[3:-1])

    if referer != 'efi/charts':
        redirect_to = '/%s/?from_date=%s&to_date=%s%s' % (referer,
                                                          from_date,
                                                          to_date,
                                                          aux)
    else:
        qstring = '&%s' % '&'.join(request.META['HTTP_REFERER'].
                                   split('/').pop().split('&')[1:])
        redirect_to = '/%s/?dates=%s,%s%s%s' % (referer,
                                                from_date,
                                                to_date,
                                                qstring,
                                                aux)

    return HttpResponseRedirect(redirect_to)
예제 #3
0
파일: views.py 프로젝트: emilioramirez/eff
def eff_last_month(request):
    from_date, to_date = month(month(date.today())[0]-timedelta(days=1))
    return HttpResponseRedirect('/efi/?from_date=%s&to_date=%s&%s=True' % (from_date, to_date, MONTHLY_FLAG))
예제 #4
0
파일: views.py 프로젝트: emilioramirez/eff
def eff_current_month(request):
    from_date, to_date = month(date.today())
    return HttpResponseRedirect('/efi/?from_date=%s&to_date=%s&%s=True' % (from_date, to_date, MONTHLY_FLAG))