@cache_page(TEN_MINUTES)
def metric_json(request, metric_slug):
    metric = _find_metric(metric_slug)

    try:
        daysback = int(request.GET['days'])
    except (TypeError, KeyError, ValueError):
        daysback = 30
    d = datetime.datetime.now() - datetime.timedelta(days=daysback)

    doc = model_to_dict(metric)
    doc['data'] = metric.gather_data(since=d)

    return http.HttpResponse(
        simplejson.dumps(doc, indent = 2 if settings.DEBUG else None),
        content_type = "application/json",
    )
dataset/ETHPy150Open django/django-dev-dashboard/dashboard/views.py/metric_json/original