Exemplo n.º 1
0
def view_person(request, pk, slug):
    person = get_object_or_404(Person, pk=pk)

    # Redirect the user if they're trying to check out an alias.
    if person.is_alias:
        return HttpResponseRedirect(reverse('view_person', args=[
            person.is_alias_of.pk, person.is_alias_of.slug
        ]))

    # Make the title string.
    locations = ', '.join(
        {p.court.short_name for p in person.positions.all() if p.court}
    )
    title = person.name_full
    if locations:
        title = "Judge %s (%s)" % (title, locations)

    # Regroup the positions by whether they're judgeships or other. This allows
    # us to use the {% ifchanged %} template tags to have two groups in the
    # template.
    judicial_positions = []
    other_positions = []
    for p in person.positions.all().order_by('-date_start'):
        if p.is_judicial_position:
            judicial_positions.append(p)
        else:
            other_positions.append(p)
    positions = judicial_positions + other_positions

    # Use Solr to get relevant opinions that the person wrote
    conn = SolrInterface(settings.SOLR_OPINION_URL, mode='r')
    q = {
        'q': 'author_id:{p} OR panel_ids:{p}'.format(p=person.pk),
        'fl': ['id', 'court_id', 'caseName', 'absolute_url', 'court',
               'court_citation_string', 'dateFiled', 'docketNumber',
               'citeCount', 'status', 'citation'],
        'rows': 5,
        'start': 0,
        'sort': 'score desc',
        'caller': 'view_person',
    }
    authored_opinions = conn.raw_query(**q).execute()

    return render_to_response(
        'view_person.html',
        {'person': person,
         'title': title,
         'aba_ratings': person.aba_ratings.all().order_by('-year_rated'),
         'political_affiliations': (person.political_affiliations.all()
                                    .order_by('-date_start')),
         'positions': positions,
         'educations': person.educations.all().order_by('-degree_year'),
         'authored_opinions': authored_opinions,
         'ftm_last_updated': settings.FTM_LAST_UPDATED,
         'private': False},
        RequestContext(request),
    )
Exemplo n.º 2
0
def view_person(request, pk, slug):
    person = get_object_or_404(Person, pk=pk)

    # Redirect the user if they're trying to check out an alias.
    if person.is_alias:
        return HttpResponseRedirect(reverse('view_person', args=[
            person.is_alias_of.pk, person.is_alias_of.slug
        ]))

    # Make the title string.
    locations = ', '.join(
        {p.court.short_name for p in person.positions.all() if p.court}
    )
    title = person.name_full
    if locations:
        title = "Judge %s (%s)" % (title, locations)

    # Regroup the positions by whether they're judgeships or other. This allows
    # us to use the {% ifchanged %} template tags to have two groups in the
    # template.
    judicial_positions = []
    other_positions = []
    for p in person.positions.all().order_by('-date_start'):
        if p.is_judicial_position:
            judicial_positions.append(p)
        else:
            other_positions.append(p)
    positions = judicial_positions + other_positions

    # Use Solr to get relevant opinions that the person wrote
    conn = SolrInterface(settings.SOLR_OPINION_URL, mode='r')
    q = {
        'q': 'author_id:{p} OR panel_ids:{p}'.format(p=person.pk),
        'fl': ['id', 'court_id', 'caseName', 'absolute_url', 'court',
               'court_citation_string', 'dateFiled', 'docketNumber',
               'citeCount', 'status', 'citation'],
        'rows': 5,
        'start': 0,
        'sort': 'score desc',
        'caller': 'view_person',
    }
    authored_opinions = conn.raw_query(**q).execute()

    return render(request, 'view_person.html', {
        'person': person,
        'title': title,
        'aba_ratings': person.aba_ratings.all().order_by('-year_rated'),
        'political_affiliations': (person.political_affiliations.all()
                                   .order_by('-date_start')),
        'positions': positions,
        'educations': person.educations.all().order_by('-degree_year'),
        'authored_opinions': authored_opinions,
        'ftm_last_updated': settings.FTM_LAST_UPDATED,
        'private': False
    })
Exemplo n.º 3
0
def view_person(request, pk, slug):
    person = get_object_or_404(Person, pk=pk)

    # Redirect the user if they're trying to check out an alias.
    if person.is_alias:
        return HttpResponseRedirect(
            reverse(
                "view_person",
                args=[person.is_alias_of.pk, person.is_alias_of.slug],
            ))

    title = make_title_str(person)

    img_path = make_img_path(person)

    # Regroup the positions by whether they're judgeships or other. This allows
    # us to use the {% ifchanged %} template tags to have two groups in the
    # template.
    judicial_positions = []
    other_positions = []
    for p in person.positions.all().order_by("-date_start"):
        if p.is_judicial_position:
            judicial_positions.append(p)
        else:
            other_positions.append(p)
    positions = judicial_positions + other_positions

    # Use Solr to get relevant opinions that the person wrote
    conn = SolrInterface(settings.SOLR_OPINION_URL, mode="r")
    q = {
        "q":
        "author_id:{p} OR panel_ids:{p}".format(p=person.pk),
        "fl": [
            "id",
            "court_id",
            "caseName",
            "absolute_url",
            "court",
            "court_citation_string",
            "dateFiled",
            "docketNumber",
            "citeCount",
            "status",
            "citation",
        ],
        "rows":
        5,
        "start":
        0,
        "sort":
        "score desc",
        "caller":
        "view_person",
    }
    authored_opinions = conn.raw_query(**q).execute()

    # Use Solr to get the oral arguments for the judge
    conn = SolrInterface(settings.SOLR_AUDIO_URL, mode="r")
    q = {
        "q":
        "panel_ids:{p}".format(p=person.pk),
        "fl": [
            "id",
            "absolute_url",
            "caseName",
            "court_id",
            "dateArgued",
            "docketNumber",
            "court_citation_string",
        ],
        "rows":
        5,
        "start":
        0,
        "sort":
        "dateArgued desc",
        "caller":
        "view_person",
    }
    oral_arguments_heard = conn.raw_query(**q).execute()

    return render(
        request,
        "view_person.html",
        {
            "person":
            person,
            "title":
            title,
            "img_path":
            img_path,
            "aba_ratings":
            person.aba_ratings.all().order_by("-year_rated"),
            "political_affiliations":
            (person.political_affiliations.all().order_by("-date_start")),
            "positions":
            positions,
            "educations":
            person.educations.all().order_by("-degree_year"),
            "authored_opinions":
            authored_opinions,
            "oral_arguments_heard":
            oral_arguments_heard,
            "ftm_last_updated":
            settings.FTM_LAST_UPDATED,
            "private":
            False,
        },
    )
Exemplo n.º 4
0
def update_judges_by_solr(candidate_id_map, debug):
    """Update judges by looking up each entity from FTM in Solr."""
    conn = SolrInterface(settings.SOLR_PEOPLE_URL, mode='r')
    match_stats = defaultdict(int)
    # These IDs are ones that cannot be updated due to being identified as
    # problematic in FTM's data.
    blacklisted_ids = defaultdict(set)
    for court_id, candidate_list in candidate_id_map.items():
        for candidate in candidate_list:
            # Look up the candidate in Solr.
            print("\nDoing: %s" % candidate['name'])
            name = (' AND '.join([word for word in candidate['name'].split() if
                                 len(word) > 1])).replace(',', '')
            results = conn.raw_query(**{
                'caller': 'ftm_update_judges_by_solr',
                'fq': [
                    'name:(%s)' % name,
                    'court_exact:%s' % court_id,
                    # This filters out Sr/Jr problems by insisting on recent
                    # positions. 1980 is arbitrary, based on testing.
                    'date_start:[1980-12-31T23:59:59Z TO *]',
                ],
                'q': "*",
            }).execute()

            if len(results) == 0:
                match_stats[len(results)] += 1
                print("  Found no matches.")

            elif len(results) == 1:
                match_stats[len(results)] += 1
                print("  Found one match: %s" % results[0]['name'])

                # Get the person from the DB and update them.
                pk = results[0]['id']
                if pk in blacklisted_ids:
                    continue
                p = Person.objects.get(pk=pk)
                if p.ftm_eid:
                    if p.ftm_eid != candidate['eid']:
                        print("  Found values in ftm database fields. This "
                              "indicates a duplicate in FTM.")

                        blacklisted_ids[p.pk].add(candidate['eid'])
                        blacklisted_ids[p.pk].add(p.ftm_eid)
                        p.ftm_eid = ""
                        p.ftm_total_received = None
                    else:
                        print("  Found values with matching EID. Adding "
                              "amounts, since this indicates multiple "
                              "jurisdictions that the judge was in.")
                        p.ftm_total_received += candidate['total']
                    if not debug:
                        p.save()
                else:
                    # No major problems. Proceed.
                    p.ftm_eid = candidate['eid']
                    p.ftm_total_received = candidate['total']
                    if not debug:
                        p.save()

            elif len(results) > 1:
                match_stats[len(results)] += 1
                print("  Found more than one match: %s" % results)

    print_stats(match_stats, candidate_id_map)
    print("Blacklisted IDs: %s" % blacklisted_ids)
def update_judges_by_solr(candidate_id_map, debug):
    """Update judges by looking up each entity from FTM in Solr."""
    conn = SolrInterface(settings.SOLR_PEOPLE_URL, mode='r')
    match_stats = defaultdict(int)
    # These IDs are ones that cannot be updated due to being identified as
    # problematic in FTM's data.
    blacklisted_ids = defaultdict(set)
    for court_id, candidate_list in candidate_id_map.items():
        for candidate in candidate_list:
            # Look up the candidate in Solr.
            logger.info("Doing: %s" % candidate['name'])
            name = (' AND '.join([
                word for word in candidate['name'].split() if len(word) > 1
            ])).replace(',', '')
            results = conn.raw_query(
                **{
                    'caller':
                    'ftm_update_judges_by_solr',
                    'fq': [
                        'name:(%s)' % name,
                        'court_exact:%s' % court_id,
                        # This filters out Sr/Jr problems by insisting on recent
                        # positions. 1980 is arbitrary, based on testing.
                        'date_start:[1980-12-31T23:59:59Z TO *]',
                    ],
                    'q':
                    "*",
                }).execute()

            if len(results) == 0:
                match_stats[len(results)] += 1
                logger.info("Found no matches.")

            elif len(results) == 1:
                match_stats[len(results)] += 1
                logger.info("Found one match: %s" % results[0]['name'])

                # Get the person from the DB and update them.
                pk = results[0]['id']
                if pk in blacklisted_ids:
                    continue
                p = Person.objects.get(pk=pk)
                if p.ftm_eid:
                    if p.ftm_eid != candidate['eid']:
                        logger.info("  Found values in ftm database fields. "
                                    "This indicates a duplicate in FTM.")

                        blacklisted_ids[p.pk].add(candidate['eid'])
                        blacklisted_ids[p.pk].add(p.ftm_eid)
                        p.ftm_eid = ""
                        p.ftm_total_received = None
                    else:
                        logger.info("Found values with matching EID. Adding "
                                    "amounts, since this indicates multiple "
                                    "jurisdictions that the judge was in.")
                        p.ftm_total_received += candidate['total']
                    if not debug:
                        p.save()
                else:
                    # No major problems. Proceed.
                    p.ftm_eid = candidate['eid']
                    p.ftm_total_received = candidate['total']
                    if not debug:
                        p.save()

            elif len(results) > 1:
                match_stats[len(results)] += 1
                logger.info("  Found more than one match: %s" % results)

    print_stats(match_stats, candidate_id_map)
    logger.info("Blacklisted IDs: %s" % blacklisted_ids)