Пример #1
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
Пример #2
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
Пример #3
0
    def __call__(self, count=5, ver_num=3):
        res = []
        cat = getToolByName(self.context, 'portal_catalog')
        brains = cat.searchResults({'portal_type': ['EEAFigure'],
                                    'sort_on': 'modified',
                                    'sort_order': 'reverse',
                                    'review_state': 'published'})

        for brain in brains:
            figure = brain.getObject()
            api = IGetVersions(figure)
            versions = api.versions()
            versions_num = len(versions)
            if versions_num > ver_num:
                latest_version = api.latest_version()
                if not latest_version in res:
                    res.append(latest_version)
            if len(res) == count:
                break

        return res