@ensure_csrf_cookie<EOL>def legislator(request, abbr, _id, slug=None):
try:<EOL><INDENT>meta = Metadata.get_object(abbr)<EOL><DEDENT>except DoesNotExist:<EOL><INDENT>raise Http404<EOL><DEDENT>legislator = db.legislators.find_one({'<STR_LIT>': _id})<EOL>if legislator is None:<EOL><INDENT>spec = {'<STR_LIT>': _id}<EOL>cursor = db.legislators.find(spec)<EOL>msg = '<STR_LIT>' % spec<EOL>assert cursor.count() < <NUM_LIT:2>, msg<EOL>try:<EOL><INDENT>legislator = next(cursor)<EOL><DEDENT>except StopIteration:<EOL><INDENT>raise Http404('<STR_LIT>' % _id)<EOL><DEDENT>else:<EOL><INDENT>return redirect(legislator.get_absolute_url(), permanent=True)<EOL><DEDENT><DEDENT>if not legislator['<STR_LIT>']:<EOL><INDENT>return legislator_inactive(request, abbr, legislator)<EOL><DEDENT>district = db.districts.find({'<STR_LIT>': abbr, '<STR_LIT>': legislator['<STR_LIT>'],<EOL>'<STR_LIT:name>': legislator['<STR_LIT>']})<EOL>if district:<EOL><INDENT>district_id = district[<NUM_LIT:0>]['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>district_id = None<EOL><DEDENT>sponsored_bills = legislator.sponsored_bills(<EOL>limit=<NUM_LIT:6>, sort=[('<STR_LIT>', pymongo.DESCENDING)])<EOL>legislator_votes = legislator.votes_6_sorted()<EOL>has_votes = bool(legislator_votes)<EOL>return render(<EOL>request, templatename('<STR_LIT>'),<EOL>dict(vote_preview_row_template=templatename('<STR_LIT>'),<EOL>roles=legislator.roles_manager, abbr=abbr,<EOL>district_id=district_id, metadata=meta, legislator=legislator,<EOL>sources=legislator['<STR_LIT>'],<EOL>sponsored_bills=list(sponsored_bills),<EOL>legislator_votes=list(legislator_votes),<EOL>has_votes=has_votes,<EOL>nav_active='<STR_LIT>'))<EOL>
Context:
    - vote_preview_row_template
    - roles
    - abbr
    - district_id
    - metadata
    - legislator
    - sources
    - sponsored_bills
    - legislator_votes
    - has_votes
    - nav_active

Templates:
    - billy/web/public/legislator.html
    - billy/web/public/vote_preview_row.html