Module: document.py

Author:

Stefan Eletzhofer

Date:

2012-07-10

Abstract

This module offers functions to create, update and delete WTDocument business objects.

Example Usage

The document.py module works on document resources. In order to use its API we need to get the api object and the document resource:

>>> from nexiles.tools.api import get_api, get_resource
>>> api = get_api("http://example.com/Windchill", "fred", "secret")
>>> resource = get_resource(api, "documents")

Now we’re able to use the nexiles.tools.api.document.create() API:

>>> from nexiles.tools.api import document
>>> doc = document.create(resource, "4711", "TestDoc", "FooProduct")
>>> print doc.name, doc.oid
u'TestDoc', u'OR:wt.doc.WTDocument:12345'

Module Documentation

class nexiles.tools.api.document.Manifest(**kw)

Document Manifest

This object is used to read, parse and validate a manifest file used by the document create API.

The manifest is a simple JSON file.

Manifest Format:

{
    "number":       "4711",
    "name":         "document_name",
    "container":    "TestProduct",
    "folder":       "/Defaults/foo",
    "description":  "A Test Document"
    "attributes": {
        "CUSTOMER":        "nexiles",
        "DESCRIPTION_GER": "foo bar baz"
    },
    "files": [
        {"role": "PRIMARY", "file_path": "local_file.txt"},
        {"role": "SECONDARY", "file_path": "foo.jpg"},
        {"role": "SECONDARY", "file_path": "woot.json", "mimetype": "application/json"},
    ]
}
property content

The processed content info structure.

classmethod from_file(klass, path) new manifest object

Create a new manifest from the file specified.

Parameters:

path – the path to a manifest JSON file

Returns:

new manifest object

get_content_info() mapping

Processes the files attribute of the manifest and creates a content info structure from it.

Note

processing is done only once, the result is cached

Returns:

content info mapping

validate() None

Validate manifest. Raises AssertionError on validation errors.

nexiles.tools.api.document.create(resource, number, name, container, description=None, folder=None, attributes=None, content=None)

upload_content(resource, number, name, container, description, folder, attributes, content) -> new document

Create a new WTDocument.

The new document is created in the context of the container given.

If description is used, then this string is set as the description of the new document.

If folder is given, then it is deemed to be a path to a existing folder inside the container – e.g something like /Default/foo/bar/baz. Please note that the /Default part is mandatory.

If attributes is given, then it is deemed to be a mapping of IBA values to be set on the new document.

If content is given, then it is deemed to be a content info mapping which contains content to be set (upload) on the new document. See nexiles.tools.api.content.create_content_info()

Parameters:
  • number – the new number of the document

  • name – the new name of the document

  • container – the name of a container for the new document

optional:

Parameters:
  • folder – the name of a folder inside the container

  • description – the description of the new document

  • content – content info structure

  • attributes – a mapping of key/value pairs to be set as IBA attributes

Returns:

new business object iteration