Item#

class ansys.dynamicreporting.core.serverless.item.Item(*args, **kwargs)#

Bases: BaseModel

Base class for all persisted report items.

Items are typed containers of content linked to a Session and a Dataset. Concrete subclasses define the content validator and type string and are registered automatically so that _from_db() and create() can dispatch to the correct subclass based on the stored type.

Methods

Item.add_tag(tag[, value])

Add or update a single tag.

Item.as_dict([recursive])

Serialize the model into a plain dictionary.

Item.create(**kwargs)

Factory-style creation that dispatches to the correct subclass.

Item.delete()

Delete this object from the database.

Item.filter(**kwargs)

Return a collection of items, scoped by subclass type.

Item.find([query])

Search for items using an ADR query string.

Item.get(**kwargs)

Retrieve a single item instance, scoped by subclass type.

Item.get_tags()

Return the raw tag string stored on this object.

Item.reinit()

Reset the in-memory ORM state for this object.

Item.rem_tag(tag)

Remove a tag by key, if it exists.

Item.remove_tag(tag)

Alias for rem_tag() for backwards compatibility.

Item.render(*[, context, request])

Render the item as HTML.

Item.save(**kwargs)

Save the item, enforcing that session and dataset are persisted.

Item.set_tags(tag_str)

Replace all tags with the given tag string.

Attributes

Item.content

Payload content for the item.

Item.dataset

Dataset associated with this item.

Item.db

Database alias in which this object is stored.

Item.name

Human-readable name for the item.

Item.saved

Whether this object has been successfully saved to the database.

Item.sequence

Sequence index for ordering items within a dataset/session.

Item.session

Session that owns this item.

Item.source

Optional free-form source identifier for this item.

Item.tags

Tag string used to group and filter objects.

Item.type

Item type identifier, normally set by subclasses.

Item.date

Timestamp when the item was created.

Item.guid

Globally unique identifier for this object.

exception DoesNotExist(extra_detail: str = None)#

Bases: ObjectDoesNotExistError

exception IntegrityError(extra_detail: str = None)#

Bases: IntegrityError

exception MultipleObjectsReturned(extra_detail: str = None)#

Bases: MultipleObjectsReturnedError

exception NotSaved(extra_detail: str = None)#

Bases: ObjectNotSavedError

content: ItemContent = None#

Payload content for the item.

classmethod create(**kwargs)#

Factory-style creation that dispatches to the correct subclass.

When invoked on Item, the caller must provide a type keyword argument identifying the desired item type. For concrete subclasses, type is injected automatically.

Parameters:
**kwargs

Fields required by the concrete item type. When called on Item, must include type. Eg: type="table", content=my_array.

Returns:
Item

Newly created and saved item instance.

Raises:
ADRException

If type is missing when called on Item.

dataset: Dataset = None#

Dataset associated with this item.

date: datetime#

Timestamp when the item was created.

classmethod filter(**kwargs)#

Return a collection of items, scoped by subclass type.

Parameters:
**kwargs

Key-value filters to find matching items. Eg: source="Simulation 1"

Returns:
ObjectSet

Collection of matching items.

classmethod find(query='')#

Search for items using an ADR query string.

For typed subclasses, an i_type filter is not allowed.

Parameters:
querystr, default: “”

Free-text or domain-specific search query.

Returns:
ObjectSet

Collection of matching items.

Raises:
ADRException

If an explicit i_type filter is provided when using a subclass of Item.

classmethod get(**kwargs)#

Retrieve a single item instance, scoped by subclass type.

Parameters:
**kwargs

Key-value filters to find the item. Eg: name="My Item"

Returns:
Item

Newly created and saved item instance.

Raises:
ADRException

If type is missing when called on Item.

name: str = ''#

Human-readable name for the item.

render(*, context=None, request=None) str | None#

Render the item as HTML.

Parameters:
contextdict or None, optional

Context dictionary passed to the underlying rendering logic. The plotly and format keys may be used to control output. If omitted, a minimal default is used.

requestHttpRequest or None, optional

Django request object, if available.

Returns:
str or None

Rendered HTML string for the item.

save(**kwargs)#

Save the item, enforcing that session and dataset are persisted.

Parameters:
**kwargs

Keyword arguments forwarded to the database save method of the underlying ORM instance. For eg: The using argument can be used to select the target database alias.

Raises:
ADRException

If the session or dataset is missing.

Session.NotSaved

If the associated session has not been saved.

Dataset.NotSaved

If the associated dataset has not been saved.

sequence: int = 0#

Sequence index for ordering items within a dataset/session.

session: Session = None#

Session that owns this item.

source: str = ''#

Optional free-form source identifier for this item.

type: str = 'none'#

Item type identifier, normally set by subclasses.