def migrateObjects(self, objects): paths = [] for obj in objects: objpath = self.getRelativePath(obj) if objpath not in self.imported and not \ (self.onlyNew and objpath in self.site._import_results): paths.append(objpath) if paths: # only if there are ones to migrate migr = MultiContentObjectMigrator(self.site, self.site, paths, self.attributes) response = requests.post(self.source, data={ 'migrator': migr.title, 'args': json.dumps({ 'attributes': self.attributes, 'paths': paths}) }) objectsData = json.loads(response.content) for path, content in objectsData.items(): path = str(path) object = safeTraverse(self.site, path) self._migrateObject(object, path, content=content) for obj in objects: # then need to check if any are folders... if IBaseFolder.providedBy(obj): migr = FolderContentsMigrator(self.site, obj) folderdata = requests.post(self.source, data={ 'migrator': FolderContentsMigrator.title, 'path': '/'.join(obj.getPhysicalPath() )[len(self.sitepath) + 1:] }) self(migr, json.loads(folderdata.content))
def __init__(self, context, request): super(CompetitionDetail, self).__init__(context, request) if IBaseFolder.providedBy(context): self.parent = aq_parent(aq_inner(context)) else: self.parent = aq_parent(aq_parent(aq_inner(context))) self.parent = '/'.join(self.parent.getPhysicalPath())
def is_folderish(self): if HAS_PLONE_5_2: raise NotImplementedError("Archetypes was removed from Plone 5.2") else: from Products.Archetypes.interfaces.base import IBaseFolder return IBaseFolder.providedBy(self.real_context)
def __init__(self, context, request): super(CompetitionDetail, self).__init__(context, request) if IBaseFolder.providedBy(context): self.parent = aq_parent(aq_inner(context)) else: self.parent = aq_parent(aq_parent(aq_inner(context))) self.parent = '/'.join(self.parent.getPhysicalPath())
def __call__(self): parent = self.context.aq_parent try: IRenameProtected(parent) raise Unauthorized() except TypeError: if HAS_AT: # This will be true if AT and pw-protected enabled if IBaseFolder.providedBy(parent) and\ IATRenameProtected.providedBy(parent): raise Unauthorized() title = safe_unicode(self.context.title_or_id()) mtool = getToolByName(self.context, 'portal_membership') if not mtool.checkPermission('Copy or Move', self.context): raise Unauthorized, _(u'Permission denied to rename ${title}.', mapping={u'title': title}) pathName = url_quote_plus('paths:list') safePath = '/'.join(self.context.getPhysicalPath()) orig_template = self.request['HTTP_REFERER'].split('?')[0] url = '%s/folder_rename_form?orig_template=%s&%s=%s' % (self.context.absolute_url(), orig_template, pathName, safePath) self.request.response.redirect(url)
def __init__(self, context, request): self.context = context self.request = request self.now = DateTime() if IBaseFolder.providedBy(context): self.parent = context else: self.parent = aq_parent(aq_inner(context)) self.path = '/'.join(self.parent.getPhysicalPath())
def __init__(self, context, request): self.context = context self.request = request self.now = DateTime() if IBaseFolder.providedBy(context): self.parent = context else: self.parent = aq_parent(aq_inner(context)) self.path = '/'.join(self.parent.getPhysicalPath())
def can_enable_at_delete_protection(self): can_enable = False if IBaseFolder.providedBy(self.context) and not\ IATDeleteProtected.providedBy(self.context): pm = self.context.portal_membership roles = pm.getAuthenticatedMember().getRolesInContext(self.context) if ('Manager' in roles or 'Owner' in roles): can_enable = True return can_enable
def __call__(self): if IBaseFolder.providedBy(self.context) and\ IATDeleteProtected.providedBy(self.context): pm = self.context.portal_membership roles = pm.getAuthenticatedMember().getRolesInContext(self.context) if not ('Manager' in roles or 'Owner' in roles): raise Unauthorized("You are not authorized to disable delete protection for this item") noLongerProvides(self.context, IATDeleteProtected) messages = IStatusMessage(self.request) messages.add(_(u"Delete protection has been disabled"), type=u"info") self.request.response.redirect(self.context.absolute_url())
def migrateObject(self, obj, content=None): objpath = self.getRelativePath(obj) if objpath not in self.imported and not \ (self.onlyNew and objpath in self.site._import_results): self._migrateObject(obj, objpath, content=content) if IBaseFolder.providedBy(obj): migr = FolderContentsMigrator(self.site, obj) folderdata = requests.post(self.source, data={ 'migrator': FolderContentsMigrator.title, 'path': '/'.join(obj.getPhysicalPath() )[len(self.sitepath) + 1:] }) self(migr, json.loads(folderdata.content))
def migrateObject(self, obj, content=None): objpath = self.getRelativePath(obj) if objpath not in self.imported and not \ (self.onlyNew and objpath in self.site._import_results): self._migrateObject(obj, objpath, content=content) if IBaseFolder.providedBy(obj): migr = FolderContentsMigrator(self.site, obj) folderdata = requests.post( self.source, data={ 'migrator': FolderContentsMigrator.title, 'path': '/'.join(obj.getPhysicalPath())[len(self.sitepath) + 1:] }) self(migr, json.loads(folderdata.content))
def migrateObjects(self, objects): paths = [] for obj in objects: objpath = self.getRelativePath(obj) if objpath not in self.imported and not \ (self.onlyNew and objpath in self.site._import_results): paths.append(objpath) if paths: # only if there are ones to migrate migr = MultiContentObjectMigrator(self.site, self.site, paths, self.attributes) response = requests.post(self.source, data={ 'migrator': migr.title, 'args': json.dumps({ 'attributes': self.attributes, 'paths': paths }) }) objectsData = json.loads(response.content) for path, content in objectsData.items(): path = str(path) object = safeTraverse(self.site, path) self._migrateObject(object, path, content=content) for obj in objects: # then need to check if any are folders... if IBaseFolder.providedBy(obj): migr = FolderContentsMigrator(self.site, obj) folderdata = requests.post( self.source, data={ 'migrator': FolderContentsMigrator.title, 'path': '/'.join(obj.getPhysicalPath())[len(self.sitepath) + 1:] }) self(migr, json.loads(folderdata.content))
def is_folderish(self): return IBaseFolder.providedBy(self.real_context)
def is_folderish(self): return IBaseFolder.providedBy(self.real_context)
def doSetLanguage(obj, language): obj.setLanguage(language) if IBaseFolder.providedBy(obj): for item in obj.objectValues(): doSetLanguage(item, language)
def cut_and_paste(ob, *args, **kw): """ Uses OFS to cut and paste an object. """ err = list() targetpath = kw['target_path'] if not targetpath: err.append('You must specify a target path') id = kw['id_to_move'] if not id: err.append(u'You must select an object to move') targetpath = targetpath.encode('utf-8') id = id.encode('utf-8') lang = kw['lang'] portal_path = kw['portal_path'] if not err: if targetpath.startswith('/'): if not targetpath.startswith(portal_path): targetpath = portal_path + targetpath target_base = ob.restrictedTraverse(targetpath, None) if target_base is None: err.append(u'No object was found at the given taget path %s' \ % targetpath) return err if ITranslatable.providedBy(target_base): target = target_base.getTranslation(lang) else: err.append(u'The target object is not translatable. Please '\ 'choose a different target that is translatable.') return err if target is None: err.append(u'No translation in language "%s" was found of '\ 'the target %s' % (lang, targetpath)) return err if not IBaseFolder.providedBy(target): err.append(u'The target object is not folderish - pasting is '\ 'not possible.') return err name = None if id in ob.objectIds(): name = id trans_object = getattr(ob, name) else: # look for translation via getTranslation target_object = kw.get('target_object', None) if target_object: trans_object = target_object.getTranslation(lang) if trans_object: if Acquisition.aq_parent(trans_object) == ob: name = trans_object.getId() if name is None: err.append(u'No translation of the requested object for language '\ '%s found in %s' % ( lang, '/'.join(ob.getPhysicalPath()))) return err if target == trans_object: err.append(u'The target cannot be identical to the object you '\ 'want to move') return err ob._delObject(name, suppress_events=True) target._setObject(id, trans_object, set_owner=0, suppress_events=True) trans_object = target._getOb(id) notify(ObjectMovedEvent(trans_object, ob, id, target, id)) notifyContainerModified(ob) if Acquisition.aq_base(ob) is not Acquisition.aq_base(target): notifyContainerModified(target) trans_object._postCopy(target, op=1) trans_object.reindexObject() return err