Exemple #1
0
 def print_report(report):
     data_objects = report.get_all()
     data_objects = report.since_filter(data_objects, since)
     data_objects = report.order_by(data_objects, None)
     data_list = reports.generate(data_objects, report, dict(since=since))
     if options.number > 0:
         data_list = data_list[:options.number]
     if len(data_list) > 0:
         table = [report.headers] + [[str(o[untitle(h)])
             for h in report.headers] for o in data_list]
         pprint_table(sys.stdout, table)
     else:
         print 'None found.'
Exemple #2
0
 def print_report(report):
     data_objects = report.get_all()
     data_objects = report.since_filter(data_objects, since)
     data_objects = report.order_by(data_objects, None)
     data_list = reports.generate(data_objects, report, dict(since=since))
     if options.number > 0:
         data_list = data_list[:options.number]
     if len(data_list) > 0:
         table = [report.headers] + [[str(o[untitle(h)])
             for h in report.headers] for o in data_list]
         pprint_table(sys.stdout, table)
     else:
         print 'None found.'
Exemple #3
0
def get_data(request, content_type, content_id=None, detail_type=None):
    """Retrieves and structures data, then returns it as a JSON object.
    
    Returns a JSON object containing data on given content type.
    If content_id is provided, data on the details of the content_type
    object associated with that id will be returned.  The data is
    filtered by GET parameters in the request.
    
    """
    if not content_type in reports.all:
        raise ValueError("Invalid content type '%s'." % content_type)
    report = reports.all[content_type]
    params = {}
    for k, v in request.GET.iteritems():
        params[str(k)] = v
    params['since'] = parse_since(params.get('since'))
    if detail_type:
        if not detail_type in report.details:
            raise ValueError("Invalid detail type '%s'." % detail_type)
        data_key = detail_type
        data_set = report.details[data_key](content_id, **params)
    else:
        data_key = content_type
        data_set = report(content_id)
    report = reports.all[data_key]
    if isinstance(data_set, QuerySet):
        print data_key
        data_set = report.since_filter(data_set, params['since'])
        data_set = report.order_by(data_set, params.get('order'))
    page, page_data = paginate(request, data_set)
    json_data = {
        'data': reports.generate(page.object_list, report, params),
        'page': page_data,
    }
    json = simplejson.dumps(json_data, cls=JSONObjectEncoder)
    return http.HttpResponse(json, mimetype="json")