def findObject(base, path):
    """ traverse to given path and find the upmost object """
    if path.startswith('/'):
        obj = getToolByName(base, 'portal_url').getPortalObject()
        portal_path = '/'.join(obj.getPhysicalPath())
        components = path.lstrip(portal_path + '/').split('/')
    else:
        obj = aq_parent(base)   # relative urls start at the parent...
        components = path.split('/')
    while components:
        child_id = unquote(components[0])
        try:
            try:
                child = obj.unrestrictedTraverse(child_id)
            except AttributeError:
                request = aq_get(obj, 'REQUEST')
                child = request.traverseName(obj, child_id)
        except ConflictError:
            raise
        except (AttributeError, KeyError, NotFound, ztkNotFound):
            return None, None
        if not IItem.providedBy(child):
            break
        obj = child
        components.pop(0)
    return obj, '/'.join(components)
示例#2
0
def updateReferences(obj, relationship, newrefs):

    # This for sure looks ugly, but is necessary to maintian AT compatibility
    # newrefs are wrapped objects, but getRefreences returns the real objects
    # to generate a difference, we must do the difference with the objects
    # the adapters wrapped. This is what real_newrefs is about
    # next, when adding references, we have to provide the wrapped object
    # again, so we create a mapping, newref_r_a_mapping to get the
    # wrapped object.

    real_newrefs = set()
    newref_r_a_mapping = {}
    for newref in newrefs:
        # Checking for IItem is a hack to check wether this reference
        # is an adapter or a real object. Real Objects from AT are IItem
        if not IItem.providedBy(newref):
            real_newrefs.add(newref.context)
            newref_r_a_mapping[newref.context] = newref
        else:
            real_newrefs.add(newref)

    existing = set(obj.getReferences(relationship=relationship))

    for ref in real_newrefs.difference(existing):   # add new references and...
        try:
            obj.addReference(newref_r_a_mapping.get(ref, ref), 
                             relationship=relationship)
        except (ReferenceException, AttributeError):
            pass
    for ref in existing.difference(real_newrefs):   # removed leftovers
        try:
            obj.deleteReference(newref_r_a_mapping.get(ref, ref),
                                relationship=relationship)
        except ReferenceException:
            removeDanglingReference(obj, relationship)
示例#3
0
def is_zope_object(obj):
    """Return only true for acquisition wrapped obj."""
    try:
        return (
            IItem.providedBy(obj)
            and not aq_parent(obj) is None
        )
    except Exception:
        return False
示例#4
0
    def make_json_serializable(self, value):
        if isinstance(value, (datetime, date)):
            return value.isoformat()

        if IItem.providedBy(value):
            return IUUID(value)

        if isinstance(value, (list, tuple)):
            return map(self.make_json_serializable, value)

        if isinstance(value, dict):
            return dict(zip(*map(self.make_json_serializable,
                                 zip(*value.items()))))

        return value
示例#5
0
def prevent_accessing_trashed_content_after_traversal(event):
    context = filter(lambda item: IItem.providedBy(item), event.request.PARENTS)[0]

    if not ITrashed.providedBy(context):
        return

    if getSecurityManager().getUser().has_role('Manager'):
        IStatusMessage(event.request).addStatusMessage(
            _(u'statusmessage_content_trashed',
              default=u'The content "${title}" is trashed.',
              mapping={u'title': safe_unicode(context.Title())}),
            type='warning')
        return

    raise NotFound()
示例#6
0
def findObject(base, path):
    """ traverse to given path and find the upmost object """
    obj = base
    components = path.split('/')
    while components:
        child_id = unquote(components[0])
        try:
            child = obj.restrictedTraverse(child_id)
        except ConflictError:
            raise
        except:
            return None, None
        if not IItem.providedBy(child):
            break
        obj = child
        components.pop(0)
    return obj, '/'.join(components)
示例#7
0
def findObject(base, path):
    """ traverse to given path and find the upmost object """
    obj = base
    components = path.split('/')
    while components:
        child_id = unquote(components[0])
        try:
            child = obj.restrictedTraverse(child_id)
        except ConflictError:
            raise
        except:
            return None, None
        if not IItem.providedBy(child):
            break
        obj = child
        components.pop(0)
    return obj, '/'.join(components)
def findObject(base, path):
    """ traverse to given path and find the upmost object """
    if path.startswith('/'):
        # Make an absolute path relative to the portal root
        obj = getToolByName(base, 'portal_url').getPortalObject()
        portal_path = '/'.join(obj.getPhysicalPath()) + '/'
        if path.startswith(portal_path):
            path = path[len(portal_path):]
        else:
            return None, None
    else:
        obj = aq_parent(base)   # relative urls start at the parent...

    components = path.split('/')

    # Support resolveuid/UID paths explicitely, without relying
    # on a view or skinscript to do this for us.
    if 'resolveuid' in components:
        uid = components[components.index('resolveuid') + 1]
        obj = _resolveUID(uid)
        if obj:
            return obj, path

    while components:
        child_id = unquote(components[0])
        try:
            try:
                child = obj.unrestrictedTraverse(child_id)
            except AttributeError:
                request = aq_get(obj, 'REQUEST')
                child = request.traverseName(obj, child_id)
        except ConflictError:
            raise
        except (AttributeError, KeyError,
                NotFound, ztkNotFound, UnicodeEncodeError):
            return None, None
        if not IItem.providedBy(child):
            break
        obj = child
        components.pop(0)
    return obj, '/'.join(components)
示例#9
0
def findObject(base, path):
    """ traverse to given path and find the upmost object """
    obj = base
    components = path.split("/")
    while components:
        child_id = unquote(components[0])
        try:
            try:
                child = obj.restrictedTraverse(child_id)
            except AttributeError:
                request = aq_get(obj, "REQUEST")
                child = request.traverseName(obj, child_id)
        except ConflictError:
            raise
        except (AttributeError, KeyError, NotFound, ztkNotFound):
            return None, None
        if not IItem.providedBy(child):
            break
        obj = child
        components.pop(0)
    return obj, "/".join(components)
示例#10
0
def findObject(base, path):
    """ traverse to given path and find the upmost object """
    if path.startswith('/'):
        # Make an absolute path relative to the portal root
        obj = getToolByName(base, 'portal_url').getPortalObject()
        portal_path = '/'.join(obj.getPhysicalPath()) + '/'
        if path.startswith(portal_path):
            path = path[len(portal_path):]
    else:
        obj = aq_parent(base)  # relative urls start at the parent...

    components = path.split('/')

    # Support resolveuid/UID paths explicitely, without relying
    # on a view or skinscript to do this for us.
    if 'resolveuid' in components:
        uid = components[components.index('resolveuid') + 1]
        obj = _resolveUID(uid)
        if obj:
            return obj, path

    while components:
        child_id = unquote(components[0])
        try:
            try:
                child = obj.unrestrictedTraverse(child_id)
            except AttributeError:
                request = aq_get(obj, 'REQUEST')
                child = request.traverseName(obj, child_id)
        except ConflictError:
            raise
        except (AttributeError, KeyError, NotFound, ztkNotFound,
                UnicodeEncodeError):
            return None, None
        if not IItem.providedBy(child):
            break
        obj = child
        components.pop(0)
    return obj, '/'.join(components)
示例#11
0
def _serialize_arg(val):
    if IItem.providedBy(val):
        val = '%s%s' % (
            _object_marker,
            '/'.join(val.getPhysicalPath()))
    return val
示例#12
0
def safe_callable(ob):
    if IItem.providedBy(ob):
        logger.warning("invalid: try to use %s as index", ob)
        return False
    return Catalog.safe_callable_orig(ob)
示例#13
0
def _serialize_arg(val):
    if IItem.providedBy(val):
        val = '%s%s' % (
            _object_marker,
            '/'.join(val.getPhysicalPath()))
    return val
示例#14
0
def redirect(event):
    white_list_name = [
        'portal_javascripts',
        'portal_css',
    ]
    white_list_end = (
        '.png',
        '.gif',
        '.ico',
        # '.jpeg',
        # '.jpg',
    )
    request = event.request
    parents = request['PARENTS']

    minisite_obj = get_minisite_object(request)
    if not minisite_obj:
        return

    minisite_index = parents.index(minisite_obj)
    first_child = parents[minisite_index - 1]
    if not safe_hasattr(first_child, 'getId'):
        return

    first_name = first_child.getId()
    if not first_name:
        return

    if first_name in white_list_name \
            or first_name.startswith('++') \
            or first_name.endswith(white_list_end):
        logger.debug('Found a white list {0}'.format(first_name))
        return

    if safe_hasattr(aq_base(minisite_obj), first_name):
        # no acquisition used here, object is in minisite
        logger.debug('No acquisition detected to {0}'.format(first_name))
        return

    obj = queryMultiAdapter((minisite_obj, request), name=first_name)
    if obj and not IItem.providedBy(obj):
        # it's a view
        logger.debug('Found a view for {0}'.format(first_name))
        return
    end_of_url = request['ACTUAL_URL'].replace(minisite_obj.absolute_url(), '')
    # sample : '/agenda/rss_feed_view'
    base_object = None
    if "/" in end_of_url:
        # we need to remove views / attribute from minisite object calculation
        context_end_url = end_of_url.split('@@')[0].strip("/")
        ends = context_end_url.split("/")
        ends.reverse()
        for end in ends:
            base_object = get_acquired_base_object(minisite_obj, end)
            if base_object is not None:
                break
    else:
        base_object = get_acquired_base_object(minisite_obj, end_of_url)
    redirect_base_url = url_in_portal_mode(base_object, request)
    redirect_base_url = redirect_base_url.rstrip('/')
    redirect_url = '{0}{1}'.format(redirect_base_url, end_of_url)

    logger.info('Redirecting to {0} {1}'.format(redirect_url, first_name))
    if redirect_url.endswith('/index_html'):
        redirect_url = redirect_url.replace('/index_html', '')
    raise Redirect(redirect_url)
示例#15
0
def _is_item(context):
    try:
        return IItem.providedBy(context)
    except:
        return False