示例#1
0
def update_object_with_data(content, record):
    """ update the content with the values from records
    """
    dm = IDataManager(content, None)
    if dm is None:
        raise APIError(400, "Update on this object is not allowed")
    for k, v in record.items():
        try:
            success = dm.set(k, v)
        except Unauthorized:
            raise APIError(401, "You are not allowed to set the field '%s'" % k)

        if not success:
            logger.info("update_object_with_data::skipping key=%r", k)
            continue

        logger.info("update_object_with_data::field %r updated with value=%r", k, v)

    # do a wf transition
    if record.get("transition", None):
        t = record.get("transition")
        logger.info(">>> Do Transition '%s' for Object %s", t, content.getId())
        do_action_for(content, t)

    # reindex the object
    content.reindexObject()
    return content
示例#2
0
def update_object_with_data(content, record):
    """ update the content with the values from records
    """
    dm = IDataManager(content, None)
    if dm is None:
        raise APIError(400, "Update on this object is not allowed")
    for k, v in record.items():
        try:
            success = dm.set(k, v)
        except Unauthorized:
            raise APIError(401,
                           "You are not allowed to set the field '%s'" % k)

        if not success:
            logger.info("update_object_with_data::skipping key=%r", k)
            continue

        logger.info("update_object_with_data::field %r updated with value=%r",
                    k, v)

    # do a wf transition
    if record.get("transition", None):
        t = record.get("transition")
        logger.info(">>> Do Transition '%s' for Object %s", t, content.getId())
        do_action_for(content, t)

    # reindex the object
    content.reindexObject()
    return content
示例#3
0
def update_object_with_data(content, record):
    """Update the content with the record data

    :param content: A single folderish catalog brain or content object
    :type content: ATContentType/DexterityContentType/CatalogBrain
    :param record: The data to update
    :type record: dict
    :returns: The updated content object
    :rtype: object
    """

    # ensure we have a full content object
    content = get_object(content)

    # get the proper data manager
    dm = IDataManager(content)

    if dm is None:
        raise APIError(400, "Update on this object is not allowed")

    # Iterate through record items
    for k, v in record.items():
        try:
            success = dm.set(k, v, **record)
        except Unauthorized:
            raise APIError(401, "Not allowed to set the field '%s'" % k)

        if not success:
            logger.warn("update_object_with_data::skipping key=%r", k)
            continue

        logger.debug("update_object_with_data::field %r updated", k)

    # do a wf transition
    if record.get("transition", None):
        t = record.get("transition")
        logger.debug(">>> Do Transition '%s' for Object %s", t,
                     content.getId())
        do_action_for(content, t)

    # do a sharing update
    if record.get("sharing", None):
        s = record.get("sharing")
        logger.debug(">>> Update sharing to %r for Object %s", s,
                     content.getId())
        update_sharing_for(content, s)

    # reindex the object
    content.reindexObject()
    return content
示例#4
0
def update_object_with_data(content, record):
    """Update the content with the record data

    :param content: A single folderish catalog brain or content object
    :type content: ATContentType/DexterityContentType/CatalogBrain
    :param record: The data to update
    :type record: dict
    :returns: The updated content object
    :rtype: object
    """

    # ensure we have a full content object
    content = get_object(content)

    # get the proper data manager
    dm = IDataManager(content)

    if dm is None:
        raise APIError(400, "Update on this object is not allowed")

    # Iterate through record items
    for k, v in record.items():
        try:
            success = dm.set(k, v, **record)
        except Unauthorized:
            raise APIError(401, "Not allowed to set the field '%s'" % k)

        if not success:
            logger.warn("update_object_with_data::skipping key=%r", k)
            continue

        logger.debug("update_object_with_data::field %r updated", k)

    # do a wf transition
    if record.get("transition", None):
        t = record.get("transition")
        logger.debug(">>> Do Transition '%s' for Object %s", t, content.getId())
        do_action_for(content, t)

    # do a sharing update
    if record.get("sharing", None):
        s = record.get("sharing")
        logger.debug(">>> Update sharing to %r for Object %s", s, content.getId())
        update_sharing_for(content, s)

    # reindex the object
    content.reindexObject()
    return content
示例#5
0
def update_object_with_data(content, record):
    """Update the content with the record data

    :param content: A single folderish catalog brain or content object
    :type content: ATContentType/DexterityContentType/CatalogBrain
    :param record: The data to update
    :type record: dict
    :returns: The updated content object
    :rtype: object
    :raises:
        APIError,
        :class:`~plone.jsonapi.routes.exceptions.APIError`
    """

    # ensure we have a full content object
    content = get_object(content)

    # get the proper data manager
    dm = IDataManager(content)

    if dm is None:
        fail(400, "Update for this object is not allowed")

    # https://github.com/collective/plone.jsonapi.routes/issues/77
    # filter out bogus keywords
    # XXX Maybe we should pass only values where we have identical field names?
    field_kwargs = u.omit(record, "file")

    # Iterate through record items
    for k, v in record.items():
        try:
            success = dm.set(k, v, **field_kwargs)
        except Unauthorized:
            fail(401, "Not allowed to set the field '%s'" % k)
        except ValueError, exc:
            fail(400, str(exc))

        if not success:
            logger.warn("update_object_with_data::skipping key=%r", k)
            continue

        logger.debug("update_object_with_data::field %r updated", k)
示例#6
0
        if not ploneapi.user.has_permission(
            'Modify portal content',
            user=ploneapi.user.get_current(),
            obj=content
        ):
            raise APIError(401, "You are not allowed to modify content")
    except Exception, e:
        raise APIError(401, "You are not allowed to modify content")
    dm = IDataManager(content, None)
    if dm is None:
        raise APIError(400, "Update on this object is not allowed")
    
    changed = []
    for k, v in record.items():
        try:
            success = dm.set(k, v)
        except Unauthorized:
            raise APIError(401, "You are not allowed to set the field '%s'" % k)

        if not success:
            logger.info("update_object_with_data::skipping key=%r", k)
            continue

        logger.info("update_object_with_data::field %r updated with value=%r", k, v)
        changed.append(success)

    # do a wf transition
    if record.get("transition", None):
        t = record.get("transition")
        logger.info(">>> Do Transition '%s' for Object %s", t, content.getId())
        do_action_for(content, t)