示例#1
0
def year_report(request):
    """ Provide full year reports
    for http:s//www.health-e.org.za/medicine-stockouts/ page
    """
    year = request.GET.get('year')
    start_date = arrow.get('%s-01-01' % year).date()
    end_date = arrow.get('%s-12-31' % year).date()

    cutoff = date.today() - timedelta(weeks=4)
    if end_date > cutoff:
        end_date = cutoff

    report = build_stockout_xlsx(start_date,end_date)
    response = HttpResponse(report, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    filename = 'Stockout Report - %s' % year + '.xlsx'
    response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
    return response
示例#2
0
def report_download(request):
    start_date = request.GET.get('start_date')
    end_date = request.GET.get('end_date')

    try:
        start_date = arrow.get(start_date).date()
    except arrow.ParserError:
        raise HttpResponseBadRequest("Date %s isn't valid: %s" % start_date)

    try:
        end_date = arrow.get(end_date).date()
    except arrow.ParserError:
        raise HttpResponseBadRequest("Date %s isn't valid: %s" % end_date)

    report = build_stockout_xlsx(start_date, end_date)

    response = HttpResponse(report, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    filename = 'Stockout Report - %s to %s' % (start_date.isoformat(), end_date.isoformat()) + ".xlsx"
    response['Content-Disposition'] = 'attachment; filename="' + filename + '"'
    return response