Ejemplo n.º 1
0
 def get_office_id(self):
     if self.role_type in (RoleType.president, RoleType.vicepresident):
         return RoleType.by_value(self.role_type).key
     if self.role_type == RoleType.senator:
         return ("sen", self.state, self.senator_class)
     if self.role_type == RoleType.representative:
         return ("rep", self.state, self.district)
     raise ValueError()
Ejemplo n.º 2
0
def person_session_stats(request, pk, session):
    # get the person and the statistics
    person = get_object_or_404(Person, pk=pk)
    try:
        stats = person.get_session_stats(session)
    except ValueError:
        # no stats
        raise Http404()

    # get the role as stored in the file
    role = PersonRole.objects.get(id=stats["role_id"])

    # mark the role as current if the logical end date is in the future, to fix the display of Served/Serving
    role.current = (role.logical_dates()[1] > datetime.now().date())

    # clean and sort the stats for this person so they're ready for display
    from person.views_sessionstats import clean_person_stats
    clean_person_stats(stats)

    # group into an order for navigation
    nav_groups = []
    for stat in stats["stats"]:
        for group in nav_groups:
            if group["icon"] == stat["icon"]:
                group["stats"].append(stat)
                break
        else:
            nav_groups.append({"icon": stat["icon"], "stats": [stat]})

    import dateutil.parser
    from person.types import Gender, RoleType

    # what dates specifically for the congress?
    (period_min, period_max) = get_congress_dates(stats["meta"]["congress"])
    period_min = max(period_min, role.logical_dates()[0])
    period_max = min(period_max, role.logical_dates()[1])

    return {
        "publishdate": dateutil.parser.parse(stats["meta"]["as-of"]),
        "period": session_stats_period(session, stats),
        "congress_dates": (period_min, period_max),
        "person": person,
        "photo": person.get_photo()[0],
        "himher": Gender.by_value(person.gender).pronoun_object,
        "role": role,
        "class": RoleType.by_value(role.role_type).label.lower() + "s",
        "session": session,
        "meta": stats["meta"],
        "stats": stats["stats"],
        "nav_groups": nav_groups,
    }
Ejemplo n.º 3
0
def person_session_stats(request, pk, session):
    # get the person and the statistics
    person = get_object_or_404(Person, pk=pk)
    try:
        stats = person.get_session_stats(session)
    except ValueError:
        # no stats
        raise Http404()

    # get the role as stored in the file
    role = PersonRole.objects.get(id=stats["role_id"])

    # mark the role as current if the logical end date is in the future, to fix the display of Served/Serving
    role.current = (role.logical_dates()[1] > datetime.now().date())

    # clean and sort the stats for this person so they're ready for display
    from person.views_sessionstats import clean_person_stats
    clean_person_stats(stats)

    # group into an order for navigation
    nav_groups = []
    for stat in stats["stats"]:
        for group in nav_groups:
            if group["icon"] == stat["icon"]:
                group["stats"].append(stat)
                break
        else:
            nav_groups.append({ "icon": stat["icon"], "stats": [stat]  })

    import dateutil.parser
    from person.types import Gender, RoleType

    # what dates specifically for the congress?
    (period_min, period_max) = get_congress_dates(stats["meta"]["congress"])
    period_min = max(period_min, role.logical_dates()[0])
    period_max = min(period_max, role.logical_dates()[1])

    return {
        "publishdate": dateutil.parser.parse(stats["meta"]["as-of"]),
        "period": session_stats_period(session, stats),
        "congress_dates": (period_min, period_max),
        "person": person,
        "photo": person.get_photo()[0],
        "himher": Gender.by_value(person.gender).pronoun_object,
        "role": role,
        "class": RoleType.by_value(role.role_type).label.lower() + "s",
        "session": session,
        "meta": stats["meta"],
        "stats": stats["stats"],
        "nav_groups": nav_groups,
    }
Ejemplo n.º 4
0
def person_session_stats(request, pk, session):
    # get the person and the statistics
    person = get_object_or_404(Person, pk=pk)
    try:
        stats = person.get_session_stats(session)
    except ValueError:
        # no stats
        raise Http404()

    # get the role as stored in the file
    role = PersonRole.objects.get(id=stats["role_id"])

    # clean and sort the stats for this person so they're ready for display
    from person.views_sessionstats import clean_person_stats
    clean_person_stats(stats)

    # group into an order for navigation
    nav_groups = []
    for stat in stats["stats"]:
        for group in nav_groups:
            if group["icon"] == stat["icon"]:
                group["stats"].append(stat)
                break
        else:
            nav_groups.append({"icon": stat["icon"], "stats": [stat]})

    import dateutil
    from person.types import Gender, RoleType

    return {
        "publishdate": dateutil.parser.parse(stats["meta"]["as-of"]),
        "person": person,
        "photo": person.get_photo()[0],
        "himher": Gender.by_value(person.gender).pronoun_object,
        "role": role,
        "class": RoleType.by_value(role.role_type).label.lower() + "s",
        "session": session,
        "meta": stats["meta"],
        "stats": stats["stats"],
        "nav_groups": nav_groups,
    }
Ejemplo n.º 5
0
def person_session_stats(request, pk, session):
    # get the person and the statistics
    person = get_object_or_404(Person, pk=pk)
    try:
        stats = person.get_session_stats(session)
    except ValueError:
        # no stats
        raise Http404()

    # get the role as stored in the file
    role = PersonRole.objects.get(id=stats["role_id"])

    # clean and sort the stats for this person so they're ready for display
    from person.views_sessionstats import clean_person_stats
    clean_person_stats(stats)

    # group into an order for navigation
    nav_groups = []
    for stat in stats["stats"]:
        for group in nav_groups:
            if group["icon"] == stat["icon"]:
                group["stats"].append(stat)
                break
        else:
            nav_groups.append({ "icon": stat["icon"], "stats": [stat]  })

    import dateutil
    from person.types import Gender, RoleType

    return {
        "publishdate": dateutil.parser.parse(stats["meta"]["as-of"]),
        "person": person,
        "photo": person.get_photo()[0],
        "himher": Gender.by_value(person.gender).pronoun_object,
        "role": role,
        "class": RoleType.by_value(role.role_type).label.lower() + "s",
        "session": session,
        "meta": stats["meta"],
        "stats": stats["stats"],
        "nav_groups": nav_groups,
    }
Ejemplo n.º 6
0
def person_search_manager(mode):
    sm = SearchManager(Person, connection="person")

    sm.add_option('text', label='name', type="text")

    if mode == "current":
        sm.add_filter('current_role_type__in',
                      [RoleType.representative, RoleType.senator])
        sm.add_option('current_role_type',
                      label="serving in the...",
                      type="radio",
                      formatter=lambda v: RoleType.by_value(int(v)).
                      congress_chamber_long)
        sm.add_option('current_role_title', label="title", type="radio")
        sm.add_option('current_role_state',
                      label="state",
                      type="select",
                      formatter=format_state,
                      sort="LABEL")
        sm.add_option('current_role_district',
                      label="district",
                      type="select",
                      formatter=format_district,
                      visible_if=lambda form: "current_role_state" in form,
                      sort="KEY")
        sm.add_option('current_role_party',
                      label="party",
                      type="select",
                      formatter=lambda v: v.capitalize())
    elif mode == "all":
        sm.add_filter('all_role_types__in',
                      [RoleType.representative, RoleType.senator])
        sm.add_filter(
            'all_role_states__in', list(statenames)
        )  # only to filter the facet so an empty state value doesn't appear for MoCs that have also served as prez/vp
        sm.add_option('all_role_types',
                      label="ever served in the...",
                      type="radio",
                      formatter=lambda v: getattr(
                          RoleType.by_value(int(v)), 'congress_chamber_long',
                          RoleType.by_value(int(v)).label))
        sm.add_option('all_role_states',
                      label="ever represented...",
                      type="select",
                      formatter=format_state,
                      sort="LABEL")
        sm.add_option('all_role_districts',
                      label="district...",
                      type="select",
                      formatter=format_statedistrict,
                      visible_if=lambda form: "all_role_states" in form,
                      sort="KEY")
        sm.add_option('all_role_parties', label="party", type="select")

    sm.add_option('gender')

    sm.add_sort("Name", "sortname", default=True)
    if mode == "current":
        sm.add_sort("Seniority (Oldest First)", "first_took_office")
        sm.add_sort("Seniority (Newest Members First)", "-first_took_office")
    elif mode == "all":
        sm.add_sort("First Took Office (Oldest First)", "first_took_office")
        sm.add_sort("First Took Office (Newest First)", "-first_took_office")
        sm.add_sort("Left Office", "-left_office")

    sm.set_template("""
    	<div style="float: left; margin-right: 1.5em">
			{% if object.has_photo %}
				<img src="{{object.get_photo_url_50}}" width="50" height="60" alt="Photo of {{object.name}}"/>
			{% else %}
				<div style="border: 1px solid black; width: 50px; height: 60px;"/>
			{% endif %}
		</div>
    	<a href="{{object.get_absolute_url}}" style="margin-top: 4px">{{object.name_no_details_lastfirst}}</a>
    	<div>{{description}}</div>
	""")
    sm.set_template_context_func(template_get_context)

    return sm
Ejemplo n.º 7
0
 def leadership_title_full(self):
     if not self.leadership_title: return None
     if self.leadership_title == "Speaker": return "Speaker of the House"
     return RoleType.by_value(self.role_type).congress_chamber + " " + self.leadership_title
Ejemplo n.º 8
0
def person_search_manager(mode):
    sm = SearchManager(Person, connection="person")

    sm.add_option('text', label='name', type="text")

    if mode == "current":
        sm.add_filter('current_role_type__in', [RoleType.representative, RoleType.senator])
        sm.add_option('current_role_type', label="serving in the...", type="radio", formatter=lambda v : RoleType.by_value(int(v)).congress_chamber_long)
        sm.add_option('current_role_title', label="title", type="radio")
        sm.add_option('current_role_state', label="state", type="select", formatter=format_state, sort="LABEL")
        sm.add_option('current_role_district', label="district", type="select", formatter=format_district, visible_if=lambda form:"current_role_state" in form, sort="KEY")
        sm.add_option('current_role_party', label="party", type="select", formatter=lambda v : v.capitalize())
    elif mode == "all":
        sm.add_filter('all_role_types__in', [RoleType.representative, RoleType.senator])
        sm.add_filter('all_role_states__in', list(statenames)) # only to filter the facet so an empty state value doesn't appear for MoCs that have also served as prez/vp
        sm.add_option('all_role_types', label="ever served in the...", type="radio", formatter=lambda v : getattr(RoleType.by_value(int(v)), 'congress_chamber_long', RoleType.by_value(int(v)).label))
        sm.add_option('all_role_states', label="ever represented...", type="select", formatter=format_state, sort="LABEL")
        sm.add_option('all_role_districts', label="district...", type="select", formatter=format_statedistrict, visible_if=lambda form:"all_role_states" in form, sort="KEY")
        sm.add_option('all_role_parties', label="party", type="select")

    sm.add_option('gender')

    sm.add_sort("Name", "sortname", default=True)
    if mode == "current":
        sm.add_sort("Seniority (Oldest First)", "first_took_office")
        sm.add_sort("Seniority (Newest Members First)", "-first_took_office")
    elif mode == "all":
        sm.add_sort("First Took Office (Oldest First)", "first_took_office")
        sm.add_sort("First Took Office (Newest First)", "-first_took_office")
        sm.add_sort("Left Office", "-left_office")
    
    sm.set_template("""
    	<div style="float: left; margin-right: 1.5em">
			{% if object.has_photo %}
				<img src="{{object.get_photo_url_50}}" width="50" height="60"/>
			{% else %}
				<div style="border: 1px solid black; width: 50px; height: 60px;"/>
			{% endif %}
		</div>
    	<a href="{{object.get_absolute_url}}" style="margin-top: 4px">{{object.name_no_details_lastfirst}}</a>
    	<div>{{description}}</div>
	""")
    sm.set_template_context_func(template_get_context)

    return sm