def region(request, abbr):
report = db.reports.find_one({'<STR_LIT>': abbr})<EOL>try:<EOL><INDENT>meta = Metadata.get_object(abbr)<EOL><DEDENT>except DoesNotExist:<EOL><INDENT>raise Http404<EOL><DEDENT>fallback_bounds = GEO_BOUNDS['<STR_LIT>']<EOL>geo_bounds = GEO_BOUNDS.get(abbr.upper(), fallback_bounds)<EOL>legislators = meta.legislators({'<STR_LIT>': True}, {'<STR_LIT>': True,<EOL>'<STR_LIT>': True})<EOL>party_counts = defaultdict(lambda: defaultdict(int))<EOL>for leg in legislators:<EOL><INDENT>if '<STR_LIT>' in leg:    <EOL><INDENT>party_counts[leg['<STR_LIT>']][leg['<STR_LIT>']] += <NUM_LIT:1><EOL><DEDENT><DEDENT>chambers = []<EOL>for chamber_type, chamber in meta['<STR_LIT>'].items():<EOL><INDENT>res = {}<EOL>res['<STR_LIT:type>'] = chamber_type<EOL>res['<STR_LIT:title>'] = chamber['<STR_LIT:title>']<EOL>res['<STR_LIT:name>'] = chamber['<STR_LIT:name>']<EOL>res['<STR_LIT>'] = {<EOL>'<STR_LIT:count>': sum(party_counts[chamber_type].values()),<EOL>'<STR_LIT>': dict(party_counts[chamber_type]),<EOL>}<EOL>res['<STR_LIT>'] = meta.committees({'<STR_LIT>': chamber_type}<EOL>).count()<EOL>res['<STR_LIT>'] = meta.bills({'<STR_LIT>': chamber_type}).sort(<EOL>[('<STR_LIT>', -<NUM_LIT:1>)]).limit(<NUM_LIT:2>)<EOL>res['<STR_LIT>'] = meta.bills({'<STR_LIT>': chamber_type}).sort(<EOL>[('<STR_LIT>' + chamber_type, -<NUM_LIT:1>)]).limit(<NUM_LIT:2>)<EOL>chambers.append(res)<EOL><DEDENT>joint_committee_count = meta.committees({'<STR_LIT>': '<STR_LIT>'}).count()<EOL>sessions = meta.sessions()<EOL>for s in sessions:<EOL><INDENT>try:<EOL><INDENT>s['<STR_LIT>'] = (<EOL>report['<STR_LIT>']['<STR_LIT>'][s['<STR_LIT:id>']]['<STR_LIT>']<EOL>+ report['<STR_LIT>']['<STR_LIT>'][s['<STR_LIT:id>']]['<STR_LIT>'])<EOL><DEDENT>except KeyError:<EOL><INDENT>s['<STR_LIT>'] = <NUM_LIT:0><EOL><DEDENT><DEDENT>return render(request, templatename('<STR_LIT>'),<EOL>dict(abbr=abbr, metadata=meta, sessions=sessions,<EOL>chambers=chambers,<EOL>joint_committee_count=joint_committee_count,<EOL>geo_bounds=geo_bounds,<EOL>nav_active='<STR_LIT>'))<EOL>
Context:
    - abbr
    - metadata
    - sessions
    - chambers
    - joint_committee_count
    - geo_bounds
    - nav_active

Templates:
    - bill/web/public/region.html