7.2.6.3.2. dataRpc

Last page update: November 23, 2011

The dataRpc belongs to dataRpc family, so it is a server-side controller.

7.2.6.3.2.1. definition

GnrDomSrc_dojo_11.dataRpc(path, method, **kwargs)

Create a dataRpc and returns it. dataRpc allows the client to make a call to the server to perform an action and returns it.

Parameters:
  • path – MANDATORY - it contains the folder path of the result of the dataRpc action; you have to write it even if you don’t return any value in the dataRpc (in this situation it will become a “mandatory but dummy” parameter)
  • method – the name of your dataRpc method
  • **kwargs_onCalling, _onResult, sync. For more information, check the rpc commons attributes section
  • in the **kwargs you have to define a parameter who allows the dataRpc to be triggered To do this, you can use _fired='^anotherFolderPath'; in this case the dataRpc is triggered whenever the value contained in anotherFolderPath changes; the “_” is used to hide the trigger parameter in the datastore.

To use a dataRpc you have to:

  1. Pass the dataRpc as a string or as a callable
  2. Create the dataRpc method that will execute a server action; you can optionally return a value. its form changes a bit according to the way you call it (string/callable)

7.2.6.3.2.1.1. passing a dataRpc as a string

passing the dataRpc:

root.dataRpc('pathOfData','RpcName',_fired='^updateTime',**kwargs)

This is an example of a dataRpc called as a string. The first parameter (pathOfData) is a string with the path of the value returned (if the dataRpc returns something). The second value (RpcName) is a string with the dataRpc name

defining the dataRpc

The syntax is:

def rpc_RpcName(self,args):
    return something

Where:

  • RpcName is the name of your dataRpc
  • args contains all the paramaters passed from the dataRpc

7.2.6.3.2.1.2. passing a dataRpc as a callable

passing the dataRpc:

root.field('id_rate',
            validate_remote=self.check_rate, validate_remote_error='Error!')

This is an example of a dataRpc passed as a callable into a field including a validation (the validate_remote) that allows to validate a form field through a dataRpc

defining the dataRpc:

@public_method
def check_rate(self,**kwargs):
    return something # Here goes the code for the validate_remote, that must
                     #    return "True" if the conditions have been satisfied,
                     #    "False" if the conditions haven't been satisfied

As you can see, to pass the method as a callable you have to use the public_method() decorator; so, you have to import:

from gnr.core.gnrdecorator import public_method