DFBase

All DesignFormat schema classes inherit from DFBase, so they all have the same core properties:

{
    "id": "my_id",
    "description": "Free-form description of this node",
    "attributes": {
        "key_a": "value_a",
        "key_b": 2,
        "key_c": true
    }
}
Property Usage
id The node's ID formed of alphanumeric characters and '_'
description Free-form human readable description, not machine parseable
attributes A key-value mapping. Values can be any serialisable object, even other DesignFormat nodes!

Note

If a complex type like a DesignFormat node is stored as an attribute value, then it will be encapsulated using the same method as described in the Storage Format section.

Python API

class designformat.base.DFBase(id, description=None)

Base class of DesignFormat

__init__(id, description=None)

Initialisation for DFBase

Parameters
  • id – Identifier for the object

  • description – Human-readable description for the object

__repr__(depth=0, max_depth=2, max_list=2)

Generate an automatic representation of this block when it is converted to a string.

Parameters
  • depth – The current depth we’re printing at

  • max_depth – The maximum depth we should print to

  • max_list – The maximum number of array or dictionary entries to print

Returns

Readable representation of this block

Return type

str

__str__()

Create a representation of this block

Returns

Readable representation of this block

Return type

str

__weakref__

list of weak references to the object (if defined)

dumpObject(project)

Serialise the object into a dictionary

Parameters

project – Reference to the root DFProject for resolving values

Returns

Serialised dictionary

Return type

dict

getAttribute(key)

Return the value matching the provided key.

Parameters

key – The key to lookup

Returns

The item that was associated

Return type

any

loadObject(obj, root)

Load-up a serialised object from a dictionary

Parameters
  • obj – The serialised dictionary

  • root – Reference to the root node for resolving references

Returns

Returns this instance of DFBase after population (for chaining)

Return type

DFBase

removeAttribute(key)

Remove a particular attribute

Parameters

key – Remove associated value for key

setAttribute(key, value)

Set the value of a particular attribute

Parameters
  • key – Key to set

  • value – Value to associate (any serialisable item, including a class instance that inherits from DFBase)

Javascript API

class DFBase(id, description)

Base class of DesignFormat

Construct the base object

Arguments
  • id (string) – Identifier of the object (alphanumeric and ‘_’ only)

  • description (string) – Human-readable description of the object

DFBase.dumpObject(project)

Dump out this object into a plain JSON dictionary, encapsulating any nested objects. Encapsulation takes note of the object type as well as the data it contains, allowing it to be reloaded correctly.

Arguments
  • project (DFProject) – The project definition, used for calculating references

DFBase.getAttribute(key)

Return the current value for a named attribute

Arguments
  • key (string) – The key to lookup

DFBase.loadObject(obj, root, types)

Reload the base object parameters from the passed in object. Where encapsulation is detected within attributes, a special loader is used to evaluate any nested objects.

Arguments
  • obj (object) – Description of this node

  • root (DFBase) – Root object in the tree

  • types (object) – Map from class name to class definition

DFBase.removeAttribute(key)

Remove a named attribute from this node

Arguments
  • key (string) – Key for the attribute to remove

DFBase.setAttribute(key, value)

Add a named attribute to this node

Arguments
  • key (string) – Key for the attribute

  • value (*) – Any serialisable object