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 resolveUID(mo): path, anchor, scale = find_scaling(mo.group(1)) setSite(site) orig_path = uuid_utils.uuidToPhysicalPath(path) if orig_path is None: # print "NOT resolved:", obj.absolute_url(), mo.group(1) return path + scale # see if it's there try: ref_obj = site.restrictedTraverse(str((orig_path))) except (AttributeError, KeyError): # try redirect ref_obj = ref_obj.restrictedTraverse(redirector.get(str(orig_path))) setSite(target_site) new_path = orig_path.replace('/Main', '/colonialart').replace('/images', '/artworks') try: new_obj = target_site.restrictedTraverse(str(new_path)) except (AttributeError, KeyError): newer_path = new_path.replace('.jpg', '').replace('.jpeg', '') try: new_obj = target_site.restrictedTraverse(str(newer_path)) except (AttributeError, KeyError): print "NOT resolved:", obj.absolute_url(), orig_path return new_path setSite(target_site) uid = IUUID(new_obj) return "resolveuid/%s%s%s" % (uid, anchor, scale)
def create(self, data): """ Since content rules expects paths, we're transforming UUID, which is what the z3c form widget uses, to paths. """ a = self.Type() if data.get('target_folder', None): site = getSite() site_path = '/'.join(site.getPhysicalPath()) path = uuidToPhysicalPath(data['target_folder']) if path: data['target_folder'] = path[len(site_path):] form.applyChanges(self, a, data) return a
def test_uuidToPhysicalPath(self): from plone.uuid.interfaces import IUUID from plone.app.uuid.utils import uuidToPhysicalPath portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ['Manager']) portal.invokeFactory('Document', 'd1') portal.invokeFactory('Document', 'd2') d1 = portal['d1'] uuid = IUUID(d1) self.assertEqual('/'.join(d1.getPhysicalPath()), uuidToPhysicalPath(uuid))
def get_base_path(context=None): search_base = api.portal.get_registry_record('collective.venue.search_base') # noqa path = get_site(context) if search_base: path = uuidToPhysicalPath(search_base) return path
def resolve_item(self, uid): context = aq_inner(self.context) item_path = uuidToPhysicalPath(uid) item = context.unrestrictedTraverse(item_path) return item
def resolveUID(mo): setSite(site) new_path = uuid_utils.uuidToPhysicalPath(mo.group(1)) setSite(target_site) new_path = new_path.replace('/Main', '').replace('/images', '/artworks').replace('.jpg', '').replace('.jpeg', '') return new_path