def test_make_editable_with_unapproved(self): """Make an old version editable while having an unapproved version. """ content = self.root.test manager = IVersionManager(content.get_mockup_version(1)) self.assertTrue(manager.make_editable()) self.assertEqual(len(content.objectIds('Mockup Version')), 6)
def test_get_expiration_datetime(self): """Verify get_expiration_datetime """ manager = IVersionManager(self.root.test.get_editable()) self.assertEqual(manager.get_expiration_datetime(), None) now = DateTime() self.root.test.set_unapproved_version_expiration_datetime(now) self.assertEqual(manager.get_expiration_datetime(), now)
def test_delete_unapproved_version(self): """Delete an unapproved version. """ content = self.root.test self.assertEqual(len(content.objectIds('Mockup Version')), 5) manager = IVersionManager(content.get_editable()) self.assertTrue(manager.delete()) self.assertEqual(content.get_editable(), None) self.assertEqual(len(content.objectIds('Mockup Version')), 4)
def test_delete_published_version(self): """Delete a published version. This is not possible and should trigger an error. """ content = self.root.test self.assertEqual(len(content.objectIds('Mockup Version')), 5) manager = IVersionManager(content.get_viewable()) with self.assertRaises(VersioningError): manager.delete() self.assertEqual(len(content.objectIds('Mockup Version')), 5)
def test_make_editable_with_approved(self): """Make an old version editable while having an approved and yet not published version. This will not work. """ content = self.root.test self.layer.login('editor') publisher = IPublicationWorkflow(content) publisher.approve(DateTime() + 50) self.layer.login('author') manager = IVersionManager(content.get_mockup_version(1)) with self.assertRaises(VersioningError): manager.make_editable() self.assertEqual(len(content.objectIds('Mockup Version')), 5)
def copy_version(source, target, ensure=False): """Copy version document from source to target. """ # Move text move_text(source, target) # Copy metadata content copy_annotation(source, target) # Publication datetime info = IVersionManager(source) publication_datetime = info.get_publication_datetime() if publication_datetime is None and ensure: publication_datetime = DateTime() target.set_unapproved_version_publication_datetime(publication_datetime) target.set_unapproved_version_expiration_datetime( info.get_expiration_datetime()) # Copy last author information user = aq_base(source.get_last_author_info()) if not isinstance(user, NoneMember): target._last_author_userid = user.id target._last_author_info = aq_base(user) # Copy creator information target._owner = getattr(aq_base(source), '_owner', None)
def test_delete_closed_version(self): """Delete a previously closed version. """ content = self.root.test self.assertEqual(len(content.objectIds('Mockup Version')), 5) manager = IVersionManager(content.get_mockup_version(0)) manager.delete() self.assertEqual(len(content.objectIds('Mockup Version')), 4) manager = IVersionManager(content.get_mockup_version(1)) manager.delete() self.assertEqual(len(content.objectIds('Mockup Version')), 3)
def copy_version(source, target, ensure=False): """Copy version document from source to target. """ # Move text move_text(source, target) # Copy metadata content copy_annotation(source, target) # Publication datetime info = IVersionManager(source) publication_datetime = info.get_publication_datetime() if publication_datetime is None and ensure: publication_datetime = DateTime() target.set_unapproved_version_publication_datetime( publication_datetime) target.set_unapproved_version_expiration_datetime( info.get_expiration_datetime()) # Copy last author information user = aq_base(source.get_last_author_info()) if not isinstance(user, NoneMember): target._last_author_userid = user.id target._last_author_info = aq_base(user) # Copy creator information target._owner = getattr(aq_base(source), '_owner', None)
def test_get_publication_datetime(self): """Verify get_publication_datetime """ manager = IVersionManager(self.root.test.get_editable()) self.assertEqual(manager.get_publication_datetime(), None) now = DateTime() self.root.test.set_unapproved_version_publication_datetime(now) self.assertEqual(manager.get_publication_datetime(), now) # Published version already have a publication date since they # are published. manager = IVersionManager(self.root.test.get_viewable()) self.assertNotEqual(manager.get_publication_datetime(), None)
class PublicationStatusInfo(grok.Adapter): grok.context(IVersion) grok.provides(IPublicationStatusInfo) def __init__(self, context): self.context = context self.manager = IVersionManager(self.context) @property def id(self): return self.context.getId() @property def modification_time(self): dt = self.manager.get_modification_datetime() if dt is not None: return dt.asdatetime() @property def publication_time(self): dt = self.manager.get_publication_datetime() if dt is not None: return dt.asdatetime() @property def expiration_time(self): dt = self.manager.get_expiration_datetime() if dt is not None: return dt.asdatetime() @property def last_author(self): author = self.manager.get_last_author() if author is not None: return author.fullname() @property def version_status(self): return self.manager.get_status() def delete(self): return self.manager.delete() def copy_for_editing(self): return self.manager.make_editable()
def date_published(self): manager = IVersionManager(self.context) return manager.get_publication_datetime()
def test_get_last_author(self): """Return the last author who change the version. """ manager = IVersionManager(self.root.test.get_viewable()) self.assertNotEqual(manager.get_last_author(), 'editor')
def test_implementation(self): published = self.root.test.get_viewable() manager = IVersionManager(published) self.assertTrue(verifyObject(IVersionManager, manager))
def test_get_status(self): """Get status of different version. """ content = self.root.test manager = IVersionManager(content.get_mockup_version(1)) self.assertEqual(manager.get_status(), 'closed') manager = IVersionManager(content.get_mockup_version(2)) self.assertEqual(manager.get_status(), 'last_closed') manager = IVersionManager(content.get_mockup_version(3)) self.assertEqual(manager.get_status(), 'published') manager = IVersionManager(content.get_mockup_version(4)) self.assertEqual(manager.get_status(), 'unapproved')
def __init__(self, context): self.context = context self.manager = IVersionManager(self.context)
def versioning_state(self): version = self.form.getContent().context manager = IVersionManager(version) return str(manager.get_status())