Пример #1
0
def create_content_slugs(parent, parent_path, context):
    """Helper function to create initial content slugs
    """
    logger.info("create_content_slugs: parent={} parent_path={}".format(
        repr(parent), parent_path))
    path = "%s%s" % (parent_path, get_id(parent))
    filename = "%s.xml" % (path)
    items = dict(parent.objectItems())

    xml = context.readDataFile(filename)

    if xml is None:
        logger.warn("File not exists: '{}'".format(filename))
        return

    node = parseString(xml)

    if node.nodeName == "#document":
        node = node.firstChild

    name = node.getAttribute("name")
    uid = node.getAttribute("uid")
    logger.info("Processing ID '{}' (UID {}) in path '{}'".format(
        name, uid, path))

    # remember the UID mapping
    UID_MAP[uid] = api.get_uid(parent)

    # set the UID
    if uid and api.is_at_content(parent):
        parent._setUID(uid)
        # avoid renaming after edit
        parent.unmarkCreationFlag()
    elif uid and api.is_dexterity_content(parent):
        logger.warn("Set UID for Dexterity contents is not implemented")

    def is_object_node(n):
        return getattr(n, "nodeName", "") == "object"

    def get_child_nodes(n):
        return getattr(n, "childNodes", [])

    for child in get_child_nodes(node):
        if not is_object_node(child):
            continue

        child_id = child.getAttribute("name")
        portal_type = child.getAttribute("meta_type")
        obj = items.get(child_id)

        if not obj:
            # get the fti
            types_tool = api.get_tool("portal_types")
            fti = types_tool.getTypeInfo(portal_type)
            if fti and fti.product:
                obj = _createObjectByType(portal_type, parent, child_id)
            else:
                continue

        create_content_slugs(obj, path + "/", context)
Пример #2
0
def get_download_url(obj, fieldname, field=_marker, default=None):
    """Calculate the download url

    :param obj: Content object
    :type obj: ATContentType/DexterityContentType
    :param fieldname: Schema name of the field
    :type fieldname: str/unicode
    :param field: The file field
    :type field: object
    :returns: The file download url
    :rtype: str
    """

    # extract the file field from the object if omitted
    if field is _marker:
        field = IDataManager(obj).get(fieldname)

    # check if we have a file field
    if not is_file_field(field):
        return default

    download = None
    if api.is_dexterity_content(obj):
        # calculate the download url
        filename = getattr(field, "filename", "")
        download = "{url}/@@download/{fieldname}/{filename}".format(
            url=obj.absolute_url(),
            fieldname=fieldname,
            filename=filename,
        )
    else:
        # calculate the download url
        download = "{url}/download".format(url=obj.absolute_url(), )
    return download
Пример #3
0
def _get_object(context, value):
    """Resolve a UID to an object.

    :param context: context is the object containing the field's schema.
    :type context: BaseContent
    :param value: A UID.
    :type value: string
    :return: Returns a Content object.
    :rtype: BaseContent
    """

    if api.is_at_content(value) or api.is_dexterity_content(value):
        return value
    elif value and is_uid(context, value):
        uc = api.get_tool('uid_catalog', context=context)
        brains = uc(UID=value)
        assert len(brains) == 1
        return brains[0].getObject()
Пример #4
0
    def get_uid(self, context, value):
        """Takes a brain or object (or UID), and returns a UID.

        :param context: context is the object who's schema contains this field.
        :type context: BaseContent
        :param value: Brain, object, or UID.
        :type value: Any
        :return: resolved UID.
        :rtype: string
        """
        # Empty string or list with single empty string, are commonly
        # passed to us from form submissions
        if not value or value == ['']:
            ret = ''
        elif api.is_brain(value):
            ret = value.UID
        elif api.is_at_content(value) or api.is_dexterity_content(value):
            ret = value.UID()
        elif api.is_uid(value):
            ret = value
        else:
            raise ReferenceException("{}.{}: Cannot resolve UID for {}".format(
                context, self.getName(), value))
        return ret
Пример #5
0
    def get_uid(self, context, value):
        """Takes a brain or object (or UID), and returns a UID.

        :param context: context is the object who's schema contains this field.
        :type context: BaseContent
        :param value: Brain, object, or UID.
        :type value: Any
        :return: resolved UID.
        :rtype: string
        """
        # Empty string or list with single empty string, are commonly
        # passed to us from form submissions
        if not value or value == ['']:
            ret = ''
        elif api.is_brain(value):
            ret = value.UID
        elif api.is_at_content(value) or api.is_dexterity_content(value):
            ret = value.UID()
        elif is_uid(context, value):
            ret = value
        else:
            raise ReferenceException("{}.{}: Cannot resolve UID for {}".format(
                context, self.getName(), value))
        return ret
Пример #6
0
def is_dexterity_content(brain_or_object):
    """Proxy to bika.lims.api.is_dexterity_content
    """
    return api.is_dexterity_content(brain_or_object)
Пример #7
0
def is_dexterity_content(brain_or_object):
    """Proxy to bika.lims.api.is_dexterity_content
    """
    return api.is_dexterity_content(brain_or_object)
Пример #8
0
def is_dexterity_content(brain_or_object):
    """Proxy to senaite.api.is_dexterity_content
    """
    return api.is_dexterity_content(brain_or_object)