コード例 #1
0
    def test_citation_sorting(self):
        # A list of citations ordered properly
        cs = [
            Citation(volume=22,
                     reporter="IL",
                     page="44",
                     type=Citation.NEUTRAL),
            Citation(volume=22,
                     reporter="U.S.",
                     page="44",
                     type=Citation.FEDERAL),
            Citation(volume=22,
                     reporter="S. Ct.",
                     page="33",
                     type=Citation.FEDERAL),
            Citation(
                volume=22,
                reporter="Alt.",
                page="44",
                type=Citation.STATE_REGIONAL,
            ),
        ]

        # Mess up the ordering of the list above.
        cs_shuffled = cs[:]
        last = cs_shuffled.pop()
        cs_shuffled.insert(0, last)
        self.assertNotEqual(cs, cs_shuffled)

        # Now sort the messed up list, and check if it worked.
        cs_sorted = sorted(cs_shuffled, key=sort_cites)
        self.assertEqual(cs, cs_sorted)
コード例 #2
0
 def to_model(self):
     # Create a citation object as in our models. Eventually, the version in
     # our models should probably be the only object named "Citation". Until
     # then, this function helps map from this object to the Citation object
     # in the models.
     c = ModelCitation(**{
         key: value for key, value in
         self.__dict__.items() if
         key in ModelCitation._meta.get_all_field_names()
     })
     c.type = self._get_cite_type()
     return c
コード例 #3
0
 def to_model(self):
     # Create a citation object as in our models. Eventually, the version in
     # our models should probably be the only object named "Citation". Until
     # then, this function helps map from this object to the Citation object
     # in the models.
     c = ModelCitation(
         **{
             key: value
             for key, value in self.__dict__.items()
             if key in ModelCitation._meta.get_all_field_names()
         })
     c.type = self._get_cite_type()
     return c
コード例 #4
0
 def to_model(self):
     # Create a citation object as in our models. Eventually, the version in
     # our models should probably be the only object named "Citation". Until
     # then, this function helps map from this object to the Citation object
     # in the models.
     c = ModelCitation(
         **{
             key: value
             for key, value in self.__dict__.items()
             if key in ModelCitation._meta.get_all_field_names()
         })
     canon = REPORTERS[self.canonical_reporter]
     cite_type = canon[self.lookup_index]["cite_type"]
     c.type = map_reporter_db_cite_type(cite_type)
     return c
コード例 #5
0
def make_citation(cite_str, cluster, cite_type):
    """Create and return a citation object for the input values."""
    citation_obj = get_citations(cite_str)[0]
    return Citation(
        cluster=cluster,
        volume=citation_obj.volume,
        reporter=citation_obj.reporter,
        page=citation_obj.page,
        type=cite_type,
    )
コード例 #6
0
    def make_objects(self, item, court, sha1_hash, content):
        """Takes the meta data from the scraper and associates it with objects.

        Returns the created objects.
        """
        blocked = item['blocked_statuses']
        if blocked:
            date_blocked = date.today()
        else:
            date_blocked = None

        case_name_short = (item.get('case_name_shorts') or
                           self.cnt.make_case_name_short(item['case_names']))
        docket = Docket(
            docket_number=item.get('docket_numbers', ''),
            case_name=item['case_names'],
            case_name_short=case_name_short,
            court=court,
            blocked=blocked,
            date_blocked=date_blocked,
            source=Docket.SCRAPER,
        )

        west_cite_str = item.get('west_citations', '')
        state_cite_str = item.get('west_state_citations', '')
        neutral_cite_str = item.get('neutral_citations', '')
        cluster = OpinionCluster(
            judges=item.get('judges', ''),
            date_filed=item['case_dates'],
            date_filed_is_approximate=item['date_filed_is_approximate'],
            case_name=item['case_names'],
            case_name_short=case_name_short,
            source='C',
            precedential_status=item['precedential_statuses'],
            nature_of_suit=item.get('nature_of_suit', ''),
            blocked=blocked,
            date_blocked=date_blocked,
            # These three fields are replaced below.
            federal_cite_one=west_cite_str,
            state_cite_one=state_cite_str,
            neutral_cite=neutral_cite_str,
            syllabus=item.get('summaries', ''),
        )
        citations = []
        if west_cite_str:
            citation_obj = get_citations(west_cite_str)[0]
            citations.append(
                Citation(
                    cluster=cluster,
                    volume=citation_obj.volume,
                    reporter=citation_obj.reporter,
                    page=citation_obj.page,
                    type=Citation.WEST,
                ))
        if state_cite_str:
            citation_obj = get_citations(state_cite_str)[0]
            citations.append(
                Citation(
                    cluster=cluster,
                    volume=citation_obj.volume,
                    reporter=citation_obj.reporter,
                    page=citation_obj.page,
                    type=Citation.STATE,
                ))
        if neutral_cite_str:
            citation_obj = get_citations(neutral_cite_str)[0]
            citations.append(
                Citation(
                    cluster=cluster,
                    volume=citation_obj.volume,
                    reporter=citation_obj.reporter,
                    page=citation_obj.page,
                    type=Citation.NEUTRAL,
                ))
        opinion = Opinion(
            type='010combined',
            sha1=sha1_hash,
            download_url=item['download_urls'],
        )

        error = False
        try:
            cf = ContentFile(content)
            extension = get_extension(content)
            file_name = trunc(item['case_names'].lower(), 75) + extension
            opinion.file_with_date = cluster.date_filed
            opinion.local_path.save(file_name, cf, save=False)
        except:
            msg = ('Unable to save binary to disk. Deleted '
                   'item: %s.\n %s' %
                   (item['case_names'], traceback.format_exc()))
            logger.critical(msg.encode('utf-8'))
            ErrorLog(log_level='CRITICAL', court=court, message=msg).save()
            error = True

        return docket, opinion, cluster, citations, error