The External Python API provided by the Python interpreter included in the CEI/ANSYS distributions can now be used to manipulate items and item categories as a part of ACLs.

template_editor.report_objects module


report_objects.ItemCategoryREST object

This object is a Python representation of a Nexus item category.  When this object is created, a GUID will automatically be generated for the object and the date is set to the current time/date with the current timezone.

Data members

The following attributes are available on an ItemCategoryREST object:

    • guid - string GUID.  The default is str(uuid.uuid1()).
    • date - The time & date of the creation of this category.  The default is: datetime.datetime.now(pytz.utc).
    • name - The name of the category, a string.
    • owners - a Python set()of group names that have the 'own' permission on the item category.
    • viewers - a Python set()of group names that have the 'view' permission on the item category.
    • changers - a Python set()of group names that have the 'change' permission on the item category.
    • deleters - a Python set()of group names that have the 'delete' permission on the item category.
    • perms_and_groups - a  Python dict()of permissions on the category and user groups that are assigned these permissions. This property is read-only.

Methods

category.add_owner(group_name)

Add a user group to the owners set attribute. group_name must be a valid group name string.


category.add_viewer(group_name)

Add a user group to the viewers set attribute. group_name must be a valid group name string.


category.add_changer(group_name)

Add a user group to the changers set attribute. group_name must a valid group name string.


category.add_deleter(group_name)

Add a user group to the deleters set attribute. group_name must be a valid group name string.


category.remove_owner(group_name)

Remove a user group from the owners set attribute. group_name must be a valid group name string.


category.remove_viewer(group_name)

Remove a user group from the viewers set attribute. group_name must be a valid group name string.


category.remove_changer(group_name)

Remove a user group from the changers set attribute. group_name must be a valid group name string.


category.remove_deleter(group_name)

Remove a user group from the deleters set attribute. group_name must be a valid group name string.

Query fields

Note, all fields may be used only for ItemCategory object type queries, just like in a typical Query Expression.

ItemCategory fields

ic_guid

item category guid

ic_date

item category date

ic_name

item category name


report_objects.ItemREST object

This document only covers ACLs specific information and use cases of ItemREST. Please visit the original document for detailed information on ItemREST.

Data members

ACLs is available through the following additional attributes on an ItemREST object:

    • categories - a Python set()of item categories to assign to the item. Can be a set of either string names or ItemCategoryREST objects.

Methods

item.add_category(category)

Add an item category to the categories set attribute. The value passed can either be a category name string or an ItemCategoryREST object.


item.remove_category(category)

Remove an item category from the categories set attribute. The value passed can either be a category name string or an ItemCategoryREST object.



Examples

A simple example of how this API might be used:


import cei

from template_editor import report_objects, report_remote_server

server = report_remote_server.Server(url="http://localhost:8000", username="nexus", password="cei")


### Creating categories

ic = server.create_item_category('bumper')

ic.add_owner('nexus')

ic1 = server.create_item_category('bumper1')

ic1.add_owner('cei')

ic1.add_changer('nexus')

ic2 = server.create_item_category('bumper2')

ic2.add_owner('cei')

ic2.add_viewer('nexus')

ic2.add_deleter('nexus')

categs = [ic, ic1, ic2]

# upload

error = server.put_objects(categs)


### Fetching categories with queries using Query Expressions. For example: created after 2020-02-17

categs=server.get_objects(objtype=report_objects.ItemCategoryREST, query='A|ic_date|gt|2020-02-17T05%3A59%3A00.000Z;')


### Creating items and setting categories

item = server.create_item(name="Simple header", source="My Python script")

item.set_payload_html("<h1>An Example Header</h1>")

# set categories

item.categories = categs

# removing

item.remove_category(ic2)

item.remove_category(ic)

# adding back

item.add_category(ic)

# upload

error = server.put_objects([item])