Ejemplo n.º 1
0
def index_view(request):
    start_date = end_date = error = None
    if request.method == 'POST':
        if ('cal_year', u'Calendar Year') in request.POST.items():
            end_date = datetime.datetime.now()
            start_date = datetime.datetime(year = end_date.year, month = 1, day = 1)
        elif ('school_year', u'School Year   ') in request.POST.items():
            end_date = datetime.datetime.now()
            if end_date.month >= 8:
                start_date = datetime.datetime(year = end_date.year, month = 8, day = 15)
            else:
                start_date = datetime.datetime(year = end_date.year - 1, month = 8, day = 15)
        elif ('last_month', u' Last Month    ') in request.POST.items():
            end_date = datetime.datetime.now()
            start_date = end_date - datetime.timedelta(days = 30)
        elif ('ever', u'     Ever     ') in request.POST.items():
            start_date = datetime.datetime(year = 2011, month = 10, day = 17)
            end_date = datetime.datetime.now()
        else:
            start_date = datetime.datetime.strptime(request.POST.get('start'), '%m/%d/%Y')
            end_date =  datetime.datetime.strptime(request.POST.get('end'), '%m/%d/%Y')

    if not start_date or not end_date or start_date > end_date:
        start_date = datetime.datetime(year = 2011, month = 10, day = 17)
        end_date = datetime.datetime.now()

    top_spenders = money_log.top_spenders(20, start_date = start_date, end_date = end_date)
    return {'top_users': top_spenders, 'start_date': start_date.strftime('%m/%d/%Y'),
            'end_date': end_date.strftime('%m/%d/%Y'), 'start_date_epoch': unix_time(start_date),
            'end_date_epoch': unix_time(end_date), 'error': error}
Ejemplo n.º 2
0
def index_view(request):
    start_date = end_date = error = None
    if request.method == "POST":
        if ("cal_year", u"Calendar Year") in request.POST.items():
            end_date = datetime.datetime.now()
            start_date = datetime.datetime(year=end_date.year, month=1, day=1)
        elif ("school_year", u"School Year   ") in request.POST.items():
            end_date = datetime.datetime.now()
            if end_date.month >= 8:
                start_date = datetime.datetime(year=end_date.year, month=8, day=15)
            else:
                start_date = datetime.datetime(year=end_date.year - 1, month=8, day=15)
        elif ("last_month", u" Last Month    ") in request.POST.items():
            end_date = datetime.datetime.now()
            start_date = end_date - datetime.timedelta(days=30)
        elif ("ever", u"     Ever     ") in request.POST.items():
            start_date = datetime.datetime(year=2011, month=10, day=17)
            end_date = datetime.datetime.now()
        else:
            start_date = datetime.datetime.strptime(request.POST.get("start"), "%m/%d/%Y")
            end_date = datetime.datetime.strptime(request.POST.get("end"), "%m/%d/%Y")

    if not start_date or not end_date or start_date > end_date:
        start_date = datetime.datetime(year=2011, month=10, day=17)
        end_date = datetime.datetime.now()

    top_drinks = drink_log.top_drinks(15, start_date=start_date, end_date=end_date)
    top_spenders = money_log.top_spenders(15, start_date=start_date, end_date=end_date)
    hours = drink_log.top_hours(start_date=start_date, end_date=end_date)
    punchcard = drink_log.punchcard(start_date=start_date, end_date=end_date)
    start_date_format = start_date.strftime("%m/%d/%Y")
    end_date_format = end_date.strftime("%m/%d/%Y")
    return {
        "top_drinks": top_drinks,
        "hours": hours,
        "top_users": top_spenders,
        "start_date": start_date_format,
        "end_date": end_date_format,
        "error": error,
        "new_hours": punchcard,
    }