Exemple #1
0
 def testFolderUpgrade(self):
     from plone.folder.interfaces import IOrderableFolder
     self.importFile(__file__, 'test-full.zexp')
     # `portal_type` and `Type` can be checked before migration...
     oldsite = getattr(self.app, self.site_id)
     ids = 'news', 'events', 'Members'
     for id in ids:
         obj = oldsite[id]
         self.assertEqual(obj.portal_type, 'Large Plone Folder')
         self.assertEqual(obj.Type(), 'Large Folder')
         brain, = oldsite.portal_catalog(getId=id)  # asserts only one
         self.assertEqual(brain.portal_type, 'Large Plone Folder')
         self.assertEqual(brain.Type, 'Large Folder')
     # now let's migrate...
     oldsite, result = self.migrate()
     self.assertFalse(oldsite.portal_migration.needUpgrading())
     # after migration `/news`, `/events` and `/Members` are based on
     # `plone.(app.)folder`, but still have no ordering set...
     for id in ids:
         obj = oldsite[id]
         self.assertTrue(IOrderableFolder.providedBy(obj),
                         '%s not orderable?' % id)
         self.assertEqual(obj._ordering, 'unordered',
                          '%s has no `_ordering`?' % id)
         self.assertEqual(obj.portal_type, 'Folder')
         self.assertEqual(obj.Type(), 'Folder')
         brain, = oldsite.portal_catalog(getId=id)  # asserts only one
         self.assertEqual(brain.portal_type, 'Folder')
         self.assertEqual(brain.Type, 'Folder')
Exemple #2
0
 def testFolderUpgrade(self):
     from plone.folder.interfaces import IOrderableFolder
     self.importFile(__file__, 'test-full.zexp')
     # `portal_type` and `Type` can be checked before migration...
     oldsite = getattr(self.app, self.site_id)
     ids = 'news', 'events', 'Members'
     for id in ids:
         obj = oldsite[id]
         self.assertEqual(obj.portal_type, 'Large Plone Folder')
         self.assertEqual(obj.Type(), 'Large Folder')
         brain, = oldsite.portal_catalog(getId=id)   # asserts only one
         self.assertEqual(brain.portal_type, 'Large Plone Folder')
         self.assertEqual(brain.Type, 'Large Folder')
     # now let's migrate...
     oldsite, result = self.migrate()
     self.assertFalse(oldsite.portal_migration.needUpgrading())
     # after migration `/news`, `/events` and `/Members` are based on
     # `plone.(app.)folder`, but still have no ordering set...
     for id in ids:
         obj = oldsite[id]
         self.assertTrue(IOrderableFolder.providedBy(obj),
             '%s not orderable?' % id)
         self.assertEqual(obj._ordering, 'unordered',
             '%s has no `_ordering`?' % id)
         self.assertEqual(obj.portal_type, 'Folder')
         self.assertEqual(obj.Type(), 'Folder')
         brain, = oldsite.portal_catalog(getId=id)   # asserts only one
         self.assertEqual(brain.portal_type, 'Folder')
         self.assertEqual(brain.Type, 'Folder')
 def _create_sort_options(self):
     if not IOrderableFolder.providedBy(self.context):
         return None
     ordering = self.context.getOrdering()
     if ICatalogOrdering.providedBy(ordering):
         settings = ordering.settings()
         static_sort_criteria = settings.get('criterium', '')
         static_sort_reversed = settings.get('reversed', False)
     else:
         static_sort_criteria = 'manual'
         static_sort_reversed = False
     def create_option(name, title):
         return {
             'name': name,
             'title': title,
             'active': name == static_sort_criteria
         }
     options = [
         create_option('manual', _('foldercontents_manual_order', default=u'Manual')),
         create_option('sortable_title', _('foldercontents_title_order', default=u'Title')),
         create_option('id', _('foldercontents_id_order', default=u'Short Name')),
         create_option('modified', _('foldercontents_modification_order', default=u'Modification Date')),
         create_option('created', _('foldercontents_creation_order', default=u'Creation Date')),
         create_option('effective', _('foldercontents_effective_order', default=u'Publishing Date')),
         create_option('expires', _('foldercontents_expiry_order', default=u'Expiration Date')),
         create_option('portal_type', _('foldercontents_type_order', default=u'Type')),
     ]
     return SortOptions(options, static_sort_reversed)
def _supports_explicit_ordering(context):
    if IPloneSiteRoot.providedBy(context):
        return True
    if not IOrderableFolder.providedBy(context):
        return False
    ordering = context.getOrdering()
    return IExplicitOrdering.providedBy(ordering)
Exemple #5
0
    def __call__(self, item_id, delta, subset_ids=None):
        context = aq_inner(self.context)
        try:
            if not IOrderableFolder.providedBy(context):
                if not base_hasattr(context, 'moveObjectsByDelta'):
                    # for instance, plone site root does not use plone.folder
                    raise ValueError("Not an ordered folder.")
            else:
                ordering = context.getOrdering()
                if not IExplicitOrdering.providedBy(ordering):
                    raise ValueError("Ordering disable on folder.")

            delta = int(delta)
            if subset_ids is not None:
                objectPos = self.context.getObjectPosition
                position_id = [(objectPos(id), id) for id in subset_ids]
                position_id.sort()
                if subset_ids != [id for position, id in position_id]:
                    raise ValueError("Client/server ordering mismatch.")
                self.context.moveObjectsByDelta(item_id, delta, subset_ids)
        except ValueError as e:
            self.context.REQUEST.response.setStatus('BadRequest')
            return str(e)

        ploneUtils = getToolByName(self.context, 'plone_utils')
        ploneUtils.reindexOnReorder(self.context)
        return "<done />"
Exemple #6
0
 def orderable(self):
     """
     """
     context = aq_inner(self.context)
     if not IOrderableFolder.providedBy(context):
         if hasattr(context, 'moveObjectsByDelta'):
             # for instance, plone site root does not use plone.folder
             return True
         else:
             return False
     ordering = context.getOrdering()
     return IExplicitOrdering.providedBy(ordering)
def update_ordered_content_handler(obj, event):
    parent = aq_parent(aq_inner(obj))
    if IOrderableFolder.providedBy(parent):
        ordering = parent.getOrdering()
        if IFlexibleOrdering.providedBy(ordering):
            key = ordering.key_func(obj)
            if key not in ordering.order:
                # Reinsert the object into the ordering
                obj_id = obj.getId()
                ordering.notifyRemoved(obj_id)
                ordering.notifyAdded(obj_id)
                # We need to re-reindex the order, in case we're not
                # using a Gopip index
                if hasattr(aq_base(obj), 'reindexObject'):
                    obj.reindexObject(idxs=['getObjPositionInParent'])
 def __call__(self):
     authenticator = getMultiAdapter((self.context, self.request),
                                     name=u"authenticator")
     if not authenticator.verify() or \
             self.request['REQUEST_METHOD'] != 'POST':
         raise Unauthorized
     # The site root doesn't support sort policicies
     if not IOrderableFolder.providedBy(self.context):
         messages = IStatusMessage(self.request)
         messages.add(_(u"This folder doesn't support reordering"), type='error')
         self.request.response.redirect(
             '%s/folder_contents' % self.context.absolute_url())
         return ''
     sort_crit = self.request.form.get('on')
     sort_reversed = bool(self.request.form.get('reversed'))
     if sort_crit == 'manual':
         self.context.setOrdering('')
     else:
         self.context.setOrdering('catalog')
         settings = self.context.getOrdering().settings()
         settings['criterium'] = sort_crit
         settings['reversed'] = sort_reversed
     self.request.response.redirect(
         '%s/folder_contents' % self.context.absolute_url())
Exemple #9
0
 def __call__(self):
     return IOrderableFolder.providedBy(self.context)
def _supports_ordering_policies(context):
    return IOrderableFolder.providedBy(context)
Exemple #11
0
 def __call__(self):
     if not IOrderableFolder.providedBy(self.context):
         return None
     return self.index()