Ejemplo n.º 1
0
 def add_or_update(self, *items):
     """
     Given an item, adds it to the index, or updates it if it's already
     in the index.
     """
     self.stdout.write("Adding or updating item(s): %s\n" % list(items))
     # Use Celery to add or update the item asynchronously
     if self.type == Opinion:
         add_or_update_opinions.delay(items)
     elif self.type == Audio:
         add_or_update_audio_files.delay(items)
     elif self.type == Person:
         add_or_update_people.delay(items)
Ejemplo n.º 2
0
 def add_or_update(self, *items):
     """
     Given an item, adds it to the index, or updates it if it's already
     in the index.
     """
     self.stdout.write("Adding or updating item(s): %s\n" % list(items))
     # Use Celery to add or update the item asynchronously
     if self.type == Opinion:
         add_or_update_opinions.delay(items)
     elif self.type == Audio:
         add_or_update_audio_files.delay(items)
     elif self.type == Person:
         add_or_update_people.delay(items)
Ejemplo n.º 3
0
 def delete_model(self, request, obj):
     obj.delete()
     from cl.search.tasks import add_or_update_people
     add_or_update_people.delay([obj.person_id])
Ejemplo n.º 4
0
 def save_model(self, request, obj, form, change):
     obj.save()
     from cl.search.tasks import add_or_update_people
     add_or_update_people.delay([obj.person_id])
Ejemplo n.º 5
0
 def save_model(self, request, obj, form, change):
     obj.save()
     from cl.search.tasks import add_or_update_people
     add_or_update_people.delay([obj.person_id], force_commit=False)
Ejemplo n.º 6
0
    def fix_fjc_positions(self, infile=None):
        """
        Addresses issue #624.

        We had some errant regexes in the district court assignments. This code
        reassigns the court fields for these judges where the new regexes
        differs from the old ones.

        :param infile: The import file with fjc-data.xslx
        :return: None
        """

        if infile is None:
            self.ensure_input_file()
            infile = self.options['input_file']
        textfields = [
            'firstname', 'midname', 'lastname', 'gender',
            'Place of Birth (City)', 'Place of Birth (State)',
            'Place of Death (City)', 'Place of Death (State)'
        ]
        df = pd.read_excel(infile, 0)
        for x in textfields:
            df[x] = df[x].replace(np.nan, '', regex=True)
        df['Employment text field'].replace(to_replace=r';\sno',
                                            value=r', no',
                                            inplace=True,
                                            regex=True)
        for i, item in df.iterrows():
            fjc_id = item['Judge Identification Number']
            p = Person.objects.get(fjc_id=fjc_id)
            logger.info("Doing person with FJC ID: %s, "
                        "https://courtlistener.com%s" %
                        (fjc_id, p.get_absolute_url()))

            exclusions = []
            for posnum in range(1, 7):
                if posnum > 1:
                    pos_str = ' (%s)' % posnum
                else:
                    pos_str = ''

                if pd.isnull(item['Court Name' + pos_str]):
                    continue
                courtid = get_fed_court_object(item['Court Name' + pos_str])
                if courtid is None:
                    raise
                date_termination = process_date_string(
                    item['Date of Termination' + pos_str])
                date_start = process_date_string(item['Commission Date' +
                                                      pos_str])
                date_recess_appointment = process_date_string(
                    item['Recess Appointment date' + pos_str])
                if pd.isnull(
                        date_start) and not pd.isnull(date_recess_appointment):
                    date_start = date_recess_appointment
                if pd.isnull(date_start):
                    # if still no start date, skip
                    continue
                positions = (Position.objects.filter(
                    person=p,
                    date_start=date_start,
                    date_termination=date_termination,
                    position_type='jud').exclude(pk__in=exclusions))
                position_count = positions.count()
                if position_count < 1:
                    logger.info("Couldn't find position to match '%s' on '%s' "
                                "with exclusions: %s" %
                                (p, date_start, exclusions))
                    add_positions_from_row(item,
                                           p,
                                           self.debug,
                                           fix_nums=[posnum])
                    if not self.debug:
                        add_or_update_people.delay([p.pk])
                    continue
                elif position_count == 1:
                    # Good case. Press on!
                    position = positions[0]
                    exclusions.append(position.pk)
                elif position_count > 1:
                    logger.info(
                        "Got too many results for '%s' on '%s'. Got %s" %
                        (p, date_start, position_count))
                    continue

                if position.court.pk == courtid:
                    logger.info("Court IDs are both '%s'. No changes made." %
                                courtid)
                else:
                    logger.info("Court IDs are different! Old: %s, New: %s" %
                                (position.court.pk, courtid))
                    court = Court.objects.get(pk=courtid)
                    position.court = court

                    if not self.debug:
                        position.save()
                        add_or_update_people.delay([p.pk])
Ejemplo n.º 7
0
 def save_model(self, request, obj, form, change):
     obj.save()
     from cl.search.tasks import add_or_update_people
     add_or_update_people.delay([obj.pk], force_commit=False)
Ejemplo n.º 8
0
    def fix_fjc_positions(self, infile=None):
        """
        Addresses issue #624.

        We had some errant regexes in the district court assignments. This code
        reassigns the court fields for these judges where the new regexes
        differs from the old ones.

        :param infile: The import file with fjc-data.xslx
        :return: None
        """

        if infile is None:
            self.ensure_input_file()
            infile = self.options['input_file']
        textfields = ['firstname', 'midname', 'lastname', 'gender',
                      'Place of Birth (City)', 'Place of Birth (State)',
                      'Place of Death (City)', 'Place of Death (State)']
        df = pd.read_excel(infile, 0)
        for x in textfields:
            df[x] = df[x].replace(np.nan, '', regex=True)
        df['Employment text field'].replace(to_replace=r';\sno', value=r', no',
                                            inplace=True, regex=True)
        for i, item in df.iterrows():
            fjc_id = item['Judge Identification Number']
            p = Person.objects.get(fjc_id=fjc_id)
            print(
                "Doing person with FJC ID: %s, https://courtlistener.com%s" %
                  (fjc_id, p.get_absolute_url())
            )

            exclusions = []
            for posnum in range(1, 7):
                if posnum > 1:
                    pos_str = ' (%s)' % posnum
                else:
                    pos_str = ''

                if pd.isnull(item['Court Name' + pos_str]):
                    continue
                courtid = get_fed_court_object(item['Court Name' + pos_str])
                if courtid is None:
                    raise
                date_termination = process_date_string(
                    item['Date of Termination' + pos_str])
                date_start = process_date_string(
                    item['Commission Date' + pos_str])
                date_recess_appointment = process_date_string(
                    item['Recess Appointment date' + pos_str])
                if pd.isnull(date_start) and not pd.isnull(
                        date_recess_appointment):
                    date_start = date_recess_appointment
                if pd.isnull(date_start):
                    # if still no start date, skip
                    continue
                positions = (Position.objects
                                .filter(person=p, date_start=date_start,
                                        date_termination=date_termination,
                                        position_type='jud')
                                .exclude(pk__in=exclusions))
                position_count = positions.count()
                if position_count < 1:
                    print "Couldn't find position to match '%s' on '%s' with " \
                          "exclusions: %s" % (p, date_start, exclusions)
                    add_positions_from_row(item, p, self.debug,
                                           fix_nums=[posnum])
                    if not self.debug:
                        add_or_update_people.delay([p.pk])
                    continue
                elif position_count == 1:
                    # Good case. Press on!
                    position = positions[0]
                    exclusions.append(position.pk)
                elif position_count > 1:
                    print "Got too many results for '%s' on '%s'. Got %s" % \
                          (p, date_start, position_count)
                    continue

                if position.court.pk == courtid:
                    print "Court IDs are both '%s'. No changes made." % courtid
                else:
                    print "Court IDs are different! Old: %s, New: %s" % (
                        position.court.pk, courtid)
                    court = Court.objects.get(pk=courtid)
                    position.court = court

                    if not self.debug:
                        position.save()
                        add_or_update_people.delay([p.pk])
Ejemplo n.º 9
0
 def delete_model(self, request, obj):
     obj.delete()
     from cl.search.tasks import add_or_update_people
     add_or_update_people.delay([obj.person_id])
Ejemplo n.º 10
0
 def save_model(self, request, obj, form, change):
     obj.save()
     from cl.search.tasks import add_or_update_people
     add_or_update_people.delay([obj.pk])