Beispiel #1
0
def projectspace_moved(obj, event):
    """ When a projectspace is renamed, we correct collections """
    if IObjectRemovedEvent.providedBy(event):
        return
    portal = api.portal.get()
    path = '/'.join(obj.getPhysicalPath())
    # correct path criteria in collections
    for brain in portal.portal_catalog(path=path,
                                       portal_type='DashboardCollection'):
        ob = brain.getObject()
        query = ob.query
        for elt in query:
            if elt['i'] == 'path':
                elt['v'] = path
        ob.query = query
    # correct default collection
    for brain in portal.portal_catalog(
            path=path, object_provides=ICollectionCategories.__identifier__):
        ob = brain.getObject()
        criterion = getCollectionLinkCriterion(ob)
        criterias = ICriteria(ob)
        old_uid = criterias.get(criterion.__name__).get('default')
        old_path = uuidToPhysicalPath(old_uid)
        old_id = os.path.basename(old_path)
        if old_path.endswith('/{}/{}'.format(ob.id, old_id)):
            default_col = ob[old_id].UID()
            _updateDefaultCollectionFor(ob, default_col)
            logger.info('Replaced default col {} by {} on {}'.format(
                old_uid, default_col, ob.absolute_url()))
        else:
            raise ValueError("Cannot update default col on {}".format(
                ob.absolute_url()))
    def test_updateDefaultCollectionFor(self):
        """This method will define the default collection used by the collection-link
           widget defined in a faceted enabled folder."""
        # get the collection-link and check that it has no default
        criterion = getCollectionLinkCriterion(self.folder)
        self.assertFalse(criterion.default)
        # right, do things correctly, add a DashboardCollection and use it as default
        dashcoll_id = self.folder.invokeFactory('DashboardCollection', 'dashcoll', title='Dashboard Collection')
        dashcoll = getattr(self.folder, dashcoll_id)
        dashcoll.reindexObject()
        _updateDefaultCollectionFor(self.folder, dashcoll.UID())
        self.assertEquals(criterion.default, dashcoll.UID())

        # calling it on a non faceted enabled folder will raise a NoFacetedViewDefinedException
        nonfacetedfolder_id = self.portal.invokeFactory('Folder', 'notnacetedfolder', title='Non Faceted Folder')
        nonfacetedfolder = getattr(self.portal, nonfacetedfolder_id)
        nonfacetedfolder.reindexObject()
        self.assertRaises(NoFacetedViewDefinedException, _updateDefaultCollectionFor, nonfacetedfolder, 'anUID')
Beispiel #3
0
def script1_3():
    verbose('Pst dashboards migration on %s' % obj.absolute_url_path())
    catalog = obj.portal_catalog
    from collective.eeafaceted.collectionwidget.utils import _updateDefaultCollectionFor
    from imio.project.pst import add_path
    for brain in catalog(portal_type='projectspace'):
        ps = brain.getObject()
        if 'operationalobjectives' not in ps:
            continue
        folder = ps['operationalobjectives']
        xmlpath = add_path('faceted_conf/operationalobjective.xml')
        folder.unrestrictedTraverse('@@faceted_exportimport').import_xml(
            import_file=open(xmlpath))
        _updateDefaultCollectionFor(folder, folder['all'].UID())
    obj.portal_setup.runImportStepFromProfile('imio.project.core:default',
                                              'viewlets',
                                              run_dependencies=False)
    transaction.commit()
Beispiel #4
0
def _enableFacetedDashboardFor(obj,
                               xmlpath=None,
                               show_left_column=True,
                               default_UID=None,
                               enable_faceted=True,
                               update_layout=True):
    """Enable a faceted view on obj and import a
       specific xml if given p_xmlpath."""
    # already a faceted?
    if enable_faceted and IFacetedNavigable.providedBy(obj):
        logger.error("Faceted navigation is already enabled for '%s'" %
                     '/'.join(obj.getPhysicalPath()))
        return

    # do not go further if xmlpath does not exist
    if xmlpath and not path.exists(xmlpath):
        raise Exception("Specified xml file '%s' doesn't exist" % xmlpath)
    # .enable() here under will redirect to enabled faceted
    # we cancel this, safe previous RESPONSE status and location
    response_status = obj.REQUEST.RESPONSE.getStatus()
    response_location = obj.REQUEST.RESPONSE.getHeader('location')
    if enable_faceted:
        obj.unrestrictedTraverse('@@faceted_subtyper').enable()

    if update_layout:
        # use correct layout in the faceted
        IFacetedLayout(obj).update_layout('faceted-table-items')
    # show the left portlets
    if show_left_column and IHidePloneLeftColumn.providedBy(obj):
        noLongerProvides(obj, IHidePloneLeftColumn)
    # import configuration
    if xmlpath:
        obj.unrestrictedTraverse('@@faceted_exportimport').import_xml(
            import_file=open(xmlpath))
    # define default collection UID
    if default_UID:
        _updateDefaultCollectionFor(obj, default_UID)
    obj.reindexObject()
    obj.REQUEST.RESPONSE.status = response_status
    obj.REQUEST.RESPONSE.setHeader('location', response_location or '')
Beispiel #5
0
 def adapt_dashboards(self):
     # mark dashboards
     for brain in self.pc(object_provides='imio.project.pst.interfaces.IImioPSTProject'):
         pst = brain.getObject()
         for id, inf in (('strategicobjectives', IOSDashboardBatchActions),
                         ('operationalobjectives', IOODashboardBatchActions),
                         ('pstactions', IActionDashboardBatchActions),
                         ('tasks', ITaskDashboardBatchActions)):
             folder = pst[id]
             logger.info("Adding interface '{}' on '{}'".format(inf.__identifier__, folder.absolute_url_path()))
             alsoProvides(folder, inf)
             if id == 'operationalobjectives':
                 xmlpath = add_path('faceted_conf/operationalobjective.xml')
                 folder.unrestrictedTraverse('@@faceted_exportimport').import_xml(import_file=open(xmlpath))
                 _updateDefaultCollectionFor(folder, folder['all'].UID())
     for inf, marker in ((IImioPSTProject, IOSDashboardBatchActions),
                         (IStrategicObjective, IOODashboardBatchActions),
                         (IOperationalObjective, IActionDashboardBatchActions),
                         (IPSTAction, ITaskDashboardBatchActions)):
         logger.info("Setting interface '{}' on '{}' objects".format(marker.__identifier__, inf.__identifier__))
         for brain in self.pc(object_provides=inf.__identifier__):
             alsoProvides(brain.getObject(), marker)
Beispiel #6
0
def add_demo_data(context):
    """ """
    CUSTOM_VIEW_FIELDS = [
        u'pretty_link', u'Creator', u'CreationDate', u'ModificationDate',
        u'review_state', u'select_row'
    ]
    portal = context.getSite()
    # create container and searches
    folder = api.content.create(container=portal,
                                type='Folder',
                                title='Dashboard')
    default_collection = api.content.create(
        container=folder,
        type='DashboardCollection',
        title='Every elements',
        query=[{
            u'i': u'path',
            u'o': u'plone.app.querystring.operation.string.path',
            u'v': u''
        }],
        customViewFields=CUSTOM_VIEW_FIELDS,
        showNumberOfItems=False,
        tal_condition=u'',
        roles_bypassing_talcondition=[],
        sort_on=None,
        sort_reversed=False)
    api.content.create(
        container=folder,
        type='DashboardCollection',
        title='My elements',
        query=[{
            u'i': u'path',
            u'o': u'plone.app.querystring.operation.string.path',
            u'v': u''
        }, {
            u'i': u'Creator',
            u'o': u'plone.app.querystring.operation.string.currentUser',
            u'v': u''
        }],
        customViewFields=CUSTOM_VIEW_FIELDS,
        showNumberOfItems=False,
        tal_condition=u'',
        roles_bypassing_talcondition=[],
        sort_on=None,
        sort_reversed=False)
    api.content.create(container=folder,
                       type='DashboardCollection',
                       title='Elements to review',
                       query=[{
                           u'i': u'review_state',
                           u'o':
                           u'plone.app.querystring.operation.selection.is',
                           u'v': u'pending'
                       }],
                       customViewFields=CUSTOM_VIEW_FIELDS,
                       showNumberOfItems=True,
                       tal_condition=u'',
                       roles_bypassing_talcondition=[],
                       sort_on=None,
                       sort_reversed=False)
    api.content.create(container=folder,
                       type='DashboardCollection',
                       title='Expired elements',
                       query=[{
                           u'i': u'expires',
                           u'o':
                           u'plone.app.querystring.operation.date.beforeToday',
                           u'v': u''
                       }],
                       customViewFields=CUSTOM_VIEW_FIELDS,
                       showNumberOfItems=True,
                       tal_condition=u'',
                       roles_bypassing_talcondition=[],
                       sort_on=None,
                       sort_reversed=False)
    # enable faceted and configure
    enableFacetedDashboardFor(folder, show_left_column=False)
    _updateDefaultCollectionFor(folder, default_collection.UID())