Exemple #1
0
    def afterSetUp(self):
        """ After Setup
        """
        self.setRoles(('Manager', ))
        portal = self.portal

        #setup content and translations
        fid = portal.invokeFactory("Folder", 'f1')
        self.folder = portal[fid]
        self.folder.addTranslation('ro')
        self.folder_ro = self.folder.getTranslation('ro')
        assert self.folder_ro.isTranslation() is True
        assert self.folder_ro.getLanguage() == 'ro'
        docid = self.folder.invokeFactory("Document", 'd1')
        self.doc = self.folder[docid]
        self.doc.addTranslation('ro')
        self.doc_ro = self.doc.getTranslation('ro')
        assert self.doc_ro.isTranslation() is True
        assert self.doc_ro.getLanguage() == 'ro'
        assert self.doc_ro.getTranslation() == self.doc
        #archive content
        archive_object(self.folder)
        assert IObjectArchived.providedBy(self.folder)
        archive_children(self.folder)
        assert IObjectArchived.providedBy(self.doc)
        archive_translations(self.folder, also_children=True)
        assert IObjectArchived.providedBy(self.folder_ro)
        assert IObjectArchived.providedBy(self.doc_ro)
Exemple #2
0
 def test_archive_previous_versions(self):
     """ Test the archival of the previous versions
         for the given object
     """
     version = create_version(self.folder)
     archive_previous_versions(version)
     assert not IObjectArchived.providedBy(version)
     assert IObjectArchived.providedBy(self.folder)
 def test_archive_previous_versions(self):
     """ Test the archival of the previous versions
         for the given object
     """
     version = create_version(self.folder)
     archive_previous_versions(version)
     assert not IObjectArchived.providedBy(version)
     assert IObjectArchived.providedBy(self.folder)
 def test_archive_previous_versions_with_children(self):
     """ Test the archival of the previous versions
         for the given object and their children
     """
     version = create_version(self.folder)
     archive_previous_versions(version, also_children=True)
     assert not IObjectArchived.providedBy(version)
     assert IObjectArchived.providedBy(self.folder)
     assert IObjectArchived.providedBy(self.doc)
Exemple #5
0
 def test_unarchive_obj_and_translations(self):
     """ Test the unarchival of the object and translations
     """
     unarchive_object(self.folder)
     objects = unarchive_translations(self.folder)
     expected_output = [self.folder_ro]
     assert not IObjectArchived.providedBy(self.folder)
     assert not IObjectArchived.providedBy(self.folder_ro)
     assert objects == expected_output
Exemple #6
0
 def test_unarchive_obj_and_children(self):
     """ Test the unarchival of the object and children
     """
     unarchive_object(self.folder)
     objects = unarchive_children(self.folder)
     expected_output = [self.doc]
     assert not IObjectArchived.providedBy(self.folder)
     assert not IObjectArchived.providedBy(self.doc)
     assert objects == expected_output
Exemple #7
0
 def test_archive_previous_versions_with_children(self):
     """ Test the archival of the previous versions
         for the given object and their children
     """
     version = create_version(self.folder)
     archive_previous_versions(version, also_children=True)
     assert not IObjectArchived.providedBy(version)
     assert IObjectArchived.providedBy(self.folder)
     assert IObjectArchived.providedBy(self.doc)
Exemple #8
0
 def test_archive_previous_versions_without_children(self):
     """ Test the archival of the previous versions
         for the given object even when calling the method
         that should archive also the children
     """
     fid = self.portal.invokeFactory("Folder", 'f2')
     self.folder = self.portal[fid]
     version = create_version(self.folder)
     archive_previous_versions(version, also_children=True)
     assert not IObjectArchived.providedBy(version)
     assert IObjectArchived.providedBy(self.folder)
 def test_archive_previous_versions_without_children(self):
     """ Test the archival of the previous versions
         for the given object even when calling the method
         that should archive also the children
     """
     fid = self.portal.invokeFactory("Folder", 'f2')
     self.folder = self.portal[fid]
     version = create_version(self.folder)
     archive_previous_versions(version, also_children=True)
     assert not IObjectArchived.providedBy(version)
     assert IObjectArchived.providedBy(self.folder)
Exemple #10
0
 def test_unarchive_obj_and_children_translations(self):
     """ Test the unarchival of the object and translations
     """
     unarchive_object(self.folder)
     objects = unarchive_children(self.folder)
     objects.extend(unarchive_translations(self.folder, also_children=True))
     expected_output = [self.doc, self.folder_ro, self.doc_ro]
     assert not IObjectArchived.providedBy(self.folder)
     assert not IObjectArchived.providedBy(self.folder_ro)
     assert not IObjectArchived.providedBy(self.doc)
     assert not IObjectArchived.providedBy(self.doc_ro)
     assert objects == expected_output
Exemple #11
0
    def __call__(self, **kwargs):
        PostOnly(self.request)
        form = self.request.form
        recurse = form.get('workflow_unarchive_recurse', False)

        context = self.context
        ploneview = getMultiAdapter((context, self.request), name='plone')
        if ploneview.isDefaultPageInFolder():
            context = self.context.getParentNode()

        if recurse:
            catalog = getToolByName(context, 'portal_catalog')
            query = {'path': '/'.join(context.getPhysicalPath())}
            brains = catalog.searchResults(query)

            for brain in brains:
                obj = brain.getObject()
                if IObjectArchived.providedBy(obj):
                    storage = queryAdapter(obj, IObjectArchivator)
                    storage.unarchive(obj)
            msg = "Object and contents have been unarchived"
        else:
            storage = queryAdapter(context, IObjectArchivator)
            storage.unarchive(context)
            msg = "Object has been unarchived"

        IStatusMessage(context.REQUEST).add(msg, 'info')

        return self.request.response.redirect(context.absolute_url())
Exemple #12
0
def archive_previous_versions(context,
                              skip_already_archived=True,
                              same_archive_date=False,
                              also_children=False,
                              **kwargs):
    """ Archive previous versions of given object
    :param object context: object
    :param bool skip_already_archived: boolean indicating whether it should skip
           archiving the previous version that is already archived
    :param bool same_archive_date: boolean indicating whether the object being
           archived should receive the same archiving date as the context
    :param bool also_children: boolean indicating whether the children of the
           versions should also be archived
    :param dict kwargs: options that are passed to the archive method directly
           affecting it's results if they are passed
    :rtype list
    """
    versions_adapter = IGetVersions(context)
    archivator_adapter = queryAdapter(context, IObjectArchivator)
    options = kwargs
    if not options:
        custom_message = getattr(archivator_adapter, 'custom_message', '')
        reason = getattr(archivator_adapter, 'reason', 'content_is_outdated')
        initiator = getattr(archivator_adapter, 'initiator', None)
        options = {
            'custom_message': custom_message,
            'initiator': initiator,
            'reason': reason
        }
    if same_archive_date and getattr(archivator_adapter, 'archive_date'):
        options.update({'archive_date': archivator_adapter.archive_date})
    versions = versions_adapter.versions()
    previous_versions = []
    uid = context.UID()
    for version in versions:
        if version.UID() == uid:
            break
        previous_versions.append(version)
    affected_objects = []
    for obj in previous_versions:
        if skip_already_archived:
            if IObjectArchived.providedBy(obj):
                continue
        if also_children:
            affected_objects.extend(archive_obj_and_children(obj, **options))
        else:
            storage = queryAdapter(obj, IObjectArchivator)
            storage.archive(obj, **options)
            affected_objects.append(obj)
    return affected_objects
Exemple #13
0
def archive_previous_versions(context, skip_already_archived=True,
                              same_archive_date=False, also_children=False,
                              **kwargs):
    """ Archive previous versions of given object
    :param object context: object
    :param bool skip_already_archived: boolean indicating whether it should skip
           archiving the previous version that is already archived
    :param bool same_archive_date: boolean indicating whether the object being
           archived should receive the same archiving date as the context
    :param bool also_children: boolean indicating whether the children of the
           versions should also be archived
    :param dict kwargs: options that are passed to the archive method directly
           affecting it's results if they are passed
    :rtype list
    """
    versions_adapter = IGetVersions(context)
    archivator_adapter = queryAdapter(context, IObjectArchivator)
    options = kwargs
    if not options:
        custom_message = getattr(archivator_adapter, 'custom_message', '')
        reason = getattr(archivator_adapter, 'reason',
                         'content_is_outdated')
        initiator = getattr(archivator_adapter, 'initiator', None)
        options = {'custom_message': custom_message,
                   'initiator': initiator,
                   'reason': reason}
    if same_archive_date and getattr(archivator_adapter, 'archive_date'):
        options.update({'archive_date': archivator_adapter.archive_date})
    versions = versions_adapter.versions()
    previous_versions = []
    uid = context.UID()
    for version in versions:
        if version.UID() == uid:
            break
        previous_versions.append(version)
    affected_objects = []
    for obj in previous_versions:
        if skip_already_archived:
            if IObjectArchived.providedBy(obj):
                continue
        if also_children:
            affected_objects.extend(archive_obj_and_children(obj, **options))
        else:
            storage = queryAdapter(obj, IObjectArchivator)
            storage.archive(obj, **options)
            affected_objects.append(obj)
    return affected_objects
Exemple #14
0
def unarchive_children(context):
    """ Unarchive given context's children
    :param context: object
    """
    catalog = getToolByName(context, 'portal_catalog')
    query = {'path': '/'.join(context.getPhysicalPath()), 'Language': 'all'}
    brains = catalog.searchResults(query)

    affected_objects = []
    for brain in brains:
        obj = brain.getObject()
        if obj == context:
            continue
        if IObjectArchived.providedBy(obj):
            storage = queryAdapter(obj, IObjectArchivator)
            storage.unarchive(obj)
            affected_objects.append(obj)
    return affected_objects
Exemple #15
0
 def update(self):
     """ Update viewlet
     """
     self.is_archived = IObjectArchived.providedBy(self.context) \
                             and "true" or "false"
Exemple #16
0
 def update(self):
     """ Update viewlet
     """
     self.is_archived = "true" if IObjectArchived.providedBy(self.context) \
         else "false"
Exemple #17
0
 def update(self):
     """ Update viewlet
     """
     self.is_archived = IObjectArchived.providedBy(self.context) \
                             and "true" or "false"
Exemple #18
0
    def test_archive_object(self):
        """ Test the archival of the object
        """

        archive_object(self.folder)
        assert IObjectArchived.providedBy(self.folder)
Exemple #19
0
 def test_archive_obj_and_children(self):
     """ Test the archival of the object and children
     """
     archive_obj_and_children(self.folder)
     assert IObjectArchived.providedBy(self.folder)
     assert IObjectArchived.providedBy(self.doc)
Exemple #20
0
 def test_archive_obj_and_children(self):
     """ Test history version
     """
     archive_obj_and_children(self.folder)
     assert IObjectArchived.providedBy(self.folder)
     assert IObjectArchived.providedBy(self.doc)
Exemple #21
0
 def test_archive_obj_and_children(self):
     """ Test history version
     """
     archive_obj_and_children(self.folder)
     assert IObjectArchived.providedBy(self.folder)
     assert IObjectArchived.providedBy(self.doc)
Exemple #22
0
 def is_archived(self):
     """Is this object archived?"""
     return bool(IObjectArchived.providedBy(self.__parent__))
Exemple #23
0
 def is_archived(self):
     """Is this object archived?"""
     return bool(IObjectArchived.providedBy(self.__parent__))