def get_committee_assignments(person): """ Find committee assignments for the given person in current congress. Returns sorted list of CommitteeMemberRole objects where each object is committee assignment which could has subcommittee assignments in ``subroles`` attribute, and simple membership in a subcommittees list. """ roles = person.committeeassignments.select_related('committee', 'committee__committee') parent_mapping = {} for role in roles: if role.committee.committee_id: parent_mapping.setdefault(role.committee.committee_id, []).append(role) role_tree = [] for role in roles: if not role.committee.committee: # is a main committee role.subroles = sort_members([ x for x in parent_mapping.get(role.committee.pk, []) if x.role not in (CommitteeMemberRole.member, CommitteeMemberRole.exofficio) ]) role.subcommittees = sorted([ x.committee for x in parent_mapping.get(role.committee.pk, []) if x.role in (CommitteeMemberRole.member, CommitteeMemberRole.exofficio) ], key=lambda c: c.name_no_article) role_tree.append(role) role_tree = sort_members(role_tree) return role_tree
def committee_details(request, parent_code, child_code=None): if child_code: if len(child_code) == 2: obj = get_object_or_404(Committee, code=parent_code+child_code) else: # legacy obj = get_object_or_404(Committee, code=child_code) return redirect(obj, permanent=True) parent = obj.committee else: obj = get_object_or_404(Committee, code=parent_code) parent = None members = sort_members(obj.members.all()) subcommittees = sorted(obj.subcommittees.filter(obsolete=False), key=lambda s : s.name_no_article) party_counts = { } for m in members: role = m.person.get_current_role() if role: # member left congress but is still listed as committee member party_counts[role.party] = party_counts.get(role.party, 0) + 1 party_counts = sorted(party_counts.items(), key = lambda p : -p[1]) return {'committee': obj, 'parent': parent, 'subcommittees': subcommittees, 'members': members, 'SIMPLE_MEMBER': CommitteeMemberRole.member, 'TYPE_JOINT': CommitteeType.joint, 'feed': Feed.CommitteeFeed(obj), "member_highlights": [m for m in members if m.role in (CommitteeMemberRole.chairman, CommitteeMemberRole.vice_chairman, CommitteeMemberRole.ranking_member)], "party_counts": party_counts, }
def committee_details(request, parent_code, child_code=None): from events.models import Feed if child_code: obj = get_object_or_404(Committee, code=child_code, committee__code=parent_code) parent = obj.committee else: obj = get_object_or_404(Committee, code=parent_code) parent = None members = sort_members(obj.members.all()) subcommittees = sorted(obj.subcommittees.filter(obsolete=False), key=lambda s: s.name_no_article) party_counts = {} for m in members: role = m.person.get_current_role() if role: # member left congress but is still listed as committee member party_counts[role.party] = party_counts.get(role.party, 0) + 1 party_counts = sorted(party_counts.items(), key=lambda p: -p[1]) return { "committee": obj, "parent": parent, "subcommittees": subcommittees, "members": members, "SIMPLE_MEMBER": CommitteeMemberRole.member, "TYPE_JOINT": CommitteeType.joint, "feed": Feed.CommitteeFeed(obj), "member_highlights": [ m for m in members if m.role in (CommitteeMemberRole.chairman, CommitteeMemberRole.vice_chairman, CommitteeMemberRole.ranking_member) ], "party_counts": party_counts, }
def committee_details(request, parent_code, child_code=None): if child_code: if len(child_code) == 2: obj = get_object_or_404(Committee, code=parent_code+child_code) else: # legacy obj = get_object_or_404(Committee, code=child_code) return redirect(obj, permanent=True) parent = obj.committee else: obj = get_object_or_404(Committee, code=parent_code) parent = None members = sort_members(obj.members.all()) subcommittees = sorted(obj.subcommittees.filter(obsolete=False), key=lambda s : s.name_no_article) party_counts = { } for m in members: role = m.person.get_current_role() if role: # member left congress but is still listed as committee member party_counts[role.party] = party_counts.get(role.party, 0) + 1 party_counts = sorted(party_counts.items(), key = lambda p : -p[1]) return {'committee': obj, 'parent': parent, 'subcommittees': subcommittees, 'members': members, 'SIMPLE_MEMBER': CommitteeMemberRole.member, 'TYPE_JOINT': CommitteeType.joint, 'feed': obj.get_feed(), "member_highlights": [m for m in members if m.role in (CommitteeMemberRole.chair, CommitteeMemberRole.vice_chair, CommitteeMemberRole.ranking_member)], "party_counts": party_counts, "recent_reports": obj.get_recent_reports(), "press_statements": fetch_statements(obj), }
def get_committee_assignments(person): """ Find committee assignments for the given person in current congress. Returns sorted list of CommitteeMemberRole objects where each object is committee assinment which could has subcommittee assignments in ``subroles`` attribute. """ roles = person.committeeassignments.select_related('committee', 'committee__committee') parent_mapping = {} for role in roles: if role.committee.committee_id: parent_mapping.setdefault(role.committee.committee_id, []).append(role) role_tree = [] for role in roles: if not role.committee.committee: role.subroles = sort_members([x for x in parent_mapping.get(role.committee.pk, [])]) role_tree.append(role) role_tree = sort_members(role_tree) return role_tree
def get_committee_assignments(person): """ Find committee assignments for the given person in current congress. Returns sorted list of CommitteeMemberRole objects where each object is committee assinment which could has subcommittee assignments in ``subroles`` attribute. """ roles = person.committeeassignments.all() parent_mapping = {} for role in roles: if role.committee.committee_id: parent_mapping.setdefault(role.committee.committee_id, []).append(role) role_tree = [] for role in roles: if not role.committee.committee: role.subroles = sort_members( [x for x in parent_mapping.get(role.committee.pk, [])]) role_tree.append(role) role_tree = sort_members(role_tree) return role_tree
def lookup_reps(request): from django.contrib.humanize.templatetags.humanize import ordinal from person.name import get_person_name # Get the state and district from the query string. try: state = request.GET['state'] district = int(request.GET['district']) if state not in stateapportionment: raise Exception() except: return {} # Get the bill (optional) from the query string from bill.models import Bill try: bill = Bill.from_congressproject_id(request.GET["bill"]) except: bill = None # Helper to get relevant committee assignments. from committee.models import CommitteeMember, CommitteeMemberRole from committee.util import sort_members def mention_committees_once(committeeassignments): # The committee assignments have been sorted first by role (i.e. # committees that the person is the chair of come first) and then # by committee name (which also puts subcommittees after committees). # In order to be less verbose, only mention each full committee # once --- take the first in each mention. seen = set() for c in committeeassignments: if (c.committee in seen) or (c.committee.committee in seen): continue yield c if c.committee.committee is not None: seen.add(c.committee.committee) # add main committee else: seen.add(c.committee) # add this committee bounds = get_district_bounds(state, district) return { "state": { "name": statenames[state], "isTerritory": stateapportionment[state] == "T", }, "district": { "ordinal": ordinal(district) if district > 0 else "At Large", "bounds": { "center": { "latitude": bounds[0], "longitude": bounds[1] }, "zoom": bounds[2] } }, "members": [{ "id": p.id, "name": get_person_name(p, role_recent=True, firstname_position="before", show_title=True, show_party=False, show_district=False), "name_formal": p.current_role.get_title() + " " + p.lastname, "url": p.get_absolute_url(), "type": p.current_role.get_role_type_display(), "description": p.current_role.get_description(), "party": p.current_role.party, "photo_url": p.get_photo_url_50() if p.has_photo() else None, "contact_url": (p.current_role.extra or {}).get("contact_form") or p.current_role.website, "phone": p.current_role.phone, "website": p.current_role.website, "pronouns": { "him_her": p.him_her, "his_her": p.his_her, "he_she": p.he_she, }, "bill-status": { "cosponsor": p in bill.cosponsors.all(), "committee-assignments": [{ "committee": c.committee.fullname, "role": c.get_role_display() if c.role in ( CommitteeMemberRole.chair, CommitteeMemberRole.ranking_member, CommitteeMemberRole.vice_chair) else None, } for c in mention_committees_once( sort_members( CommitteeMember.objects.filter( person=p, committee__in=bill.committees.all())))] } if bill else None, } for p in list( Person.objects.filter(roles__current=True, roles__state=state, roles__role_type=RoleType.senator).order_by( 'roles__senator_rank')) + list( Person.objects.filter( roles__current=True, roles__state=state, roles__district=district, roles__role_type=RoleType.representative))] }
def lookup_reps(request): from django.contrib.humanize.templatetags.humanize import ordinal from person.name import get_person_name # Get the state and district from the query string. try: state = request.GET['state'] district = int(request.GET['district']) if state not in stateapportionment: raise Exception() except: return { } # Get the bill (optional) from the query string from bill.models import Bill try: bill = Bill.from_congressproject_id(request.GET["bill"]) except: bill = None # Helper to get relevant committee assignments. from committee.models import CommitteeMember, CommitteeMemberRole from committee.util import sort_members def mention_committees_once(committeeassignments): # The committee assignments have been sorted first by role (i.e. # committees that the person is the chair of come first) and then # by committee name (which also puts subcommittees after committees). # In order to be less verbose, only mention each full committee # once --- take the first in each mention. seen = set() for c in committeeassignments: if (c.committee in seen) or (c.committee.committee in seen): continue yield c if c.committee.committee is not None: seen.add(c.committee.committee) # add main committee else: seen.add(c.committee) # add this committee bounds = get_district_bounds(state, district) return { "state": { "name": statenames[state], "isTerritory": stateapportionment[state] == "T", }, "district": { "ordinal": ordinal(district) if district > 0 else "At Large", "bounds": { "center": { "latitude": bounds[0], "longitude": bounds[1] }, "zoom": bounds[2] } }, "members": [ { "id": p.id, "name": get_person_name(p, role_recent=True, firstname_position="before", show_title=True, show_party=False, show_district=False), "name_formal": p.current_role.get_title() + " " + p.lastname, "url": p.get_absolute_url(), "type": p.current_role.get_role_type_display(), "description": p.current_role.get_description(), "party": p.current_role.party, "photo_url": p.get_photo_url_50() if p.has_photo() else None, "contact_url": (p.current_role.extra or {}).get("contact_form") or p.current_role.website, "phone": p.current_role.phone, "website": p.current_role.website, "pronouns": { "him_her": p.him_her, "his_her": p.his_her, "he_she": p.he_she, }, "bill-status": { "cosponsor": p in bill.cosponsors.all(), "committee-assignments": [ { "committee": c.committee.fullname, "role": c.get_role_display() if c.role in (CommitteeMemberRole.chair, CommitteeMemberRole.ranking_member, CommitteeMemberRole.vice_chair) else None, } for c in mention_committees_once( sort_members( CommitteeMember.objects.filter(person=p, committee__in=bill.committees.all()))) ] } if bill else None, } for p in list(Person.objects.filter(roles__current=True, roles__state=state, roles__role_type=RoleType.senator) .order_by('roles__senator_rank')) + list(Person.objects.filter(roles__current=True, roles__state=state, roles__district=district, roles__role_type=RoleType.representative)) ] }