def _put_in_parent_mappings(self, repo_folder): changed = False parent = aq_parent(aq_inner(repo_folder)) child = repo_folder child_number = IReferenceNumber(child).get_local_number() child_intid = self.intids.getId(child) ref = IReferenceNumberPrefix(parent) is_in_intid_mapping = child_intid in ref.get_prefix_mapping(child) if not is_in_intid_mapping: ref.set_number(child, number=child_number) changed = True return changed
def save_new_prefix(self, action): data, errors = self.extractData() if len(errors) > 0: return obj = self.context parent = aq_parent(aq_inner(obj)) new_prefix = unicode(data['prefix']) old_prefix = IReferenceNumberPrefix(parent).get_number(obj) intids = getUtility(IIntIds) intid = intids.getId(aq_base(obj)) prefix_adapter = IReferenceNumberPrefix(parent) # Check if prefix already allocated prefix_mapping = prefix_adapter.get_prefix_mapping(obj) child_mapping = prefix_adapter.get_child_mapping(obj) if new_prefix in prefix_mapping.values() or \ new_prefix in child_mapping.keys(): raise Exception("This prefix is already allocated!") # Save new prefix in both mappings prefix_mapping[intid] = new_prefix child_mapping[new_prefix] = intid # Drop entry for old prefix from child_mapping if old_prefix in child_mapping: child_mapping.pop(old_prefix) if IRepositoryFolder.providedBy(obj): # Also change the prefix on the repo folder behavior rnp_behavior = IReferenceNumberPrefixBehavior(obj) rnp_behavior.reference_number_prefix = new_prefix obj.reindexObject() IStatusMessage(self.request).addStatusMessage( _(u"Reference Number prefix for '%s' " "changed to '%s'" % (obj.id, new_prefix)), 'info') return self.request.RESPONSE.redirect(self.context.absolute_url())
def test_copying_dossier_purges_child_reference_number_mappings(self): dossier = create(Builder("dossier").within(self.source_repo)) subdossier_1 = create(Builder("dossier").within(dossier)) subdossier_2 = create(Builder("dossier").within(dossier)) dossier_copy = api.content.copy(source=dossier, target=self.target_repo) # there are two copied subdossiers self.assertEqual(2, len(dossier_copy.listFolderContents())) subdossier1_copy = dossier_copy.listFolderContents()[0] # copied dossier contains mappings for copied subdossiers starting at # 1, the mapping was purged on copy ref = IReferenceNumberPrefix(dossier_copy) ref.get_child_mapping(subdossier1_copy) self.assertItemsEqual([u"1", u"2"], ref.get_child_mapping(subdossier1_copy).keys()) # there are no more entries for the previous subdossiers intids = getUtility(IIntIds) prefixed_intids = ref.get_prefix_mapping(subdossier1_copy).keys() self.assertNotIn(intids.getId(subdossier_1), prefixed_intids) self.assertNotIn(intids.getId(subdossier_2), prefixed_intids)
def test_copying_dossier_purges_child_reference_number_mappings(self): self.login(self.dossier_responsible) subdossier = create(Builder('dossier').within(self.empty_dossier)) dossier_copy = api.content.copy(source=self.empty_dossier, target=self.empty_repofolder) # subdossier is copied self.assertEqual(1, len(dossier_copy.get_subdossiers())) subdossier_copy = dossier_copy.get_subdossiers()[0].getObject() # copied dossier contains mappings for copied subdossiers starting at # 1, the mapping was purged on copy ref = IReferenceNumberPrefix(dossier_copy) self.assertItemsEqual([u'1'], ref.get_child_mapping(subdossier_copy).keys()) # there are no more entries for the previous subdossiers intids = getUtility(IIntIds) prefixed_intids = ref.get_prefix_mapping(subdossier_copy).keys() self.assertNotIn(intids.getId(subdossier), prefixed_intids) self.assertIn(intids.getId(subdossier_copy), prefixed_intids)
def test_copying_dossier_purges_child_reference_number_mappings(self): self.login(self.dossier_responsible) subdossier = create(Builder('dossier').within(self.empty_dossier)) dossier_copy = api.content.copy( source=self.empty_dossier, target=self.empty_repofolder) # subdossier is copied self.assertEqual(1, len(dossier_copy.get_subdossiers())) subdossier_copy = dossier_copy.get_subdossiers()[0].getObject() # copied dossier contains mappings for copied subdossiers starting at # 1, the mapping was purged on copy ref = IReferenceNumberPrefix(dossier_copy) self.assertItemsEqual( [u'1'], ref.get_child_mapping(subdossier_copy).keys()) # there are no more entries for the previous subdossiers intids = getUtility(IIntIds) prefixed_intids = ref.get_prefix_mapping(subdossier_copy).keys() self.assertNotIn(intids.getId(subdossier), prefixed_intids) self.assertIn(intids.getId(subdossier_copy), prefixed_intids)
def test_copying_dossier_purges_child_reference_number_mappings(self): dossier = create(Builder('dossier').within(self.source_repo)) subdossier_1 = create(Builder('dossier').within(dossier)) subdossier_2 = create(Builder('dossier').within(dossier)) dossier_copy = api.content.copy(source=dossier, target=self.target_repo) # there are two copied subdossiers self.assertEqual(2, len(dossier_copy.listFolderContents())) subdossier1_copy = dossier_copy.listFolderContents()[0] # copied dossier contains mappings for copied subdossiers starting at # 1, the mapping was purged on copy ref = IReferenceNumberPrefix(dossier_copy) ref.get_child_mapping(subdossier1_copy) self.assertItemsEqual([u'1', u'2'], ref.get_child_mapping(subdossier1_copy).keys()) # there are no more entries for the previous subdossiers intids = getUtility(IIntIds) prefixed_intids = ref.get_prefix_mapping(subdossier1_copy).keys() self.assertNotIn(intids.getId(subdossier_1), prefixed_intids) self.assertNotIn(intids.getId(subdossier_2), prefixed_intids)