@unique_session_or_json_redirect
def get_statistics(request, planid):
    note_session_activity(request)

    status = { 'success': False }
    try:
        plan = Plan.objects.get(pk=planid)
    except:
        status['message'] = _(
                "Couldn't get geography info from the server. No plan with the given id.")
        return HttpResponse( json.dumps(status), mimetype='application/json', status=500)

    if 'version' in request.REQUEST:
        try:
            version = int(request.REQUEST['version'])
        except:
            version = plan.version
    else:
        version = plan.version

    try:
        display = ScoreDisplay.objects.get(legislative_body=plan.legislative_body, name="%s_sidebar_demo" % plan.legislative_body.name)
    except:
        status['message'] = _('Unable to get Demographics ScoreDisplay')
        status['exception'] = traceback.format_exc()
    
    if 'displayId' in request.REQUEST:
        try:
            display = ScoreDisplay.objects.get(pk=request.POST['displayId'])
        except:
            status['message'] = _('Unable to get Personalized ScoreDisplay')
            status['exception'] = traceback.format_exc()

    else:
        logger.warn('No displayId in request.')
        logger.warn(str(request.POST))
        
    try :
        html = display.render(plan, request, version=version)
        return HttpResponse(html, mimetype='text/html')
    except Exception, ex:
        status['message'] = _("Couldn't render display tab.")
        status['exception'] = traceback.format_exc()
        logger.warn("Couldn't render display tab")
        logger.debug('Reason: %s', ex)
        return HttpResponse( json.dumps(status), mimetype='application/json', status=500)
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/get_statistics/original