示例#1
0
def compress_endorsements(endorsements: Endorsements) -> Endorsements:
    """
    Compress endorsed categories using wildcard notation if possible.

    We want to avoid simply enumerating all of the categories that exist. If
    all subjects in an archive are present, we represent that as "{archive}.*".
    If all subjects in all archives are present, we represent that as "*.*".

    Parameters
    ----------
    endorsements : list
        A list of endorsed categories.

    Returns
    -------
    list
        The same endorsed categories, compressed with wildcards where possible.

    """
    compressed: Endorsements = []
    grouped = groupby(sorted(endorsements, key=_get_archive), key=_get_archive)
    for archive, archive_endorsements in grouped:
        archive_endorsements = list(archive_endorsements)
        if _all_subjects_in_archive(archive, archive_endorsements):
            compressed.append(_category(archive, "*"))
        else:
            for endorsement in archive_endorsements:
                compressed.append(endorsement)
    if _all_archives(compressed):
        return [taxonomy.Category("*.*")]
    return compressed
 def _inject_secondaries_if_changed(self) -> None:
     """Inject secondary classification events if a change has occurred."""
     # Add any missing secondaries.
     for dbc in self.current_row.categories:
         if dbc.category not in self.submission.secondary_categories \
                 and not dbc.is_primary:
             self._inject(AddSecondaryClassification,
                          category=taxonomy.Category(dbc.category))
    def test_save_secondary_proposal(self):
        """A submission has a new cross-list proposal."""
        with in_memory_db():
            create = CreateSubmission(creator=self.user,
                                      created=datetime.now(UTC))
            before, after = None, create.apply(None)
            create, before = store_event(create, before, after)

            event = AddProposal(creator=self.user,
                                created=datetime.now(UTC),
                                proposed_event_type=AddSecondaryClassification,
                                proposed_event_data={
                                    'category': taxonomy.Category('cs.DL'),
                                },
                                comment='foo')
            after = event.apply(before)
            with transaction():
                event, after = store_event(event, before, after)

            session = current_session()
            db_sb = session.query(models.Submission).get(event.submission_id)

            # Make sure that we get the right submission ID.
            self.assertIsNotNone(event.submission_id)
            self.assertEqual(event.submission_id, after.submission_id)
            self.assertEqual(event.submission_id, db_sb.submission_id)

            db_props = session.query(models.CategoryProposal).all()
            self.assertEqual(len(db_props), 1)
            self.assertEqual(db_props[0].submission_id, after.submission_id)
            self.assertEqual(db_props[0].category, 'cs.DL')
            self.assertEqual(db_props[0].is_primary, 0)
            self.assertEqual(db_props[0].updated.replace(tzinfo=UTC),
                             event.created)
            self.assertEqual(db_props[0].proposal_status,
                             models.CategoryProposal.UNRESOLVED)

            self.assertEqual(db_props[0].proposal_comment.logtext,
                             event.comment)
示例#4
0
 def __post_init__(self):
     """Ensure that we have an :class:`arxiv.taxonomy.Category`."""
     super(AddSecondaryClassification, self).__post_init__()
     if self.category and not isinstance(self.category, taxonomy.Category):
         self.category = taxonomy.Category(self.category)