Module ncs.template

This module implements classes to simplify template processing.

Classes

class Template (service, path=None)

Class to simplify applying of templates in a NCS service callback.

Initialize a Template object.

The 'service' argument is the 'service' variable received in decorated cb_create and cb_pre_lock_create methods in a service class. ('service' can in fact be any maagic.Node (except a Root node) instance with an underlying Transaction). It is also possible to provide a maapi.Transaction instance for the 'service' argument in which case 'path' must also be provided.

Methods

def apply(self, name, vars=None, flags=0)

Apply the template 'name'.

The optional argument 'vars' may be provided in form of a Variables instance.

class Variables (init=None)

Class to simplify passing of variables when applying a template.

Initialize a Variables object.

The optional argument 'init' can be any iterable yielding a 2-tuple in the form (name, value).

Ancestors

Methods

def add(self, name, value)

Add a value for the variable 'name'.

The value will be quoted before adding it to the internal list.

Quoting works like this: If value contains ' all occurrences of " will be replaced by ' and the final value will be quoted with ". Otherwise, the final value will be quoted with '.

def add_plain(self, name, value)

Add a value for the variable 'name'.

It's up to the caller to do proper quoting of value.