Пример #1
0
def create(parent, slug=None, **kwargs):
    r"""
    Mint a new UID and create a resource.

    The UID is computed from a given parent UID and a "slug", a proposed path
    relative to the parent. The application will attempt to use the suggested
    path but it may use a different one if a conflict with an existing resource
    arises.

    :param str parent: UID of the parent resource.
    :param str slug: Tentative path relative to the parent UID.
    :param \*\*kwargs: Other parameters are passed to the
      :py:meth:`~lakesuperior.model.ldp.ldp_factory.LdpFactory.from_provided`
      method.

    :rtype: tuple(str, lakesuperior.model.ldp.ldpr.Ldpr)
    :return: A tuple of:
        1. Event type (str): whether the resource was created or updated.
        2. Resource (lakesuperior.model.ldp.ldpr.Ldpr): The new or updated resource.
    """
    uid = LdpFactory.mint_uid(parent, slug)
    logger.debug('Minted UID for new resource: {}'.format(uid))
    rsrc = LdpFactory.from_provided(uid, **kwargs)

    rsrc.create_or_replace(create_only=True)

    return rsrc
Пример #2
0
def create_or_replace(uid, **kwargs):
    r"""
    Create or replace a resource with a specified UID.

    :param string uid: UID of the resource to be created or updated.
    :param \*\*kwargs: Other parameters are passed to the
        :py:meth:`~lakesuperior.model.ldp.ldp_factory.LdpFactory.from_provided`
        method.

    :rtype: tuple(str, lakesuperior.model.ldp.ldpr.Ldpr)
    :return: A tuple of:
        1. Event type (str): whether the resource was created or updated.
        2. Resource (lakesuperior.model.ldp.ldpr.Ldpr): The new or updated
            resource.
    """
    rsrc = LdpFactory.from_provided(uid, **kwargs)
    return rsrc.create_or_replace(), rsrc