wiki:ExportMethodArgs
Last modified 8 years ago Last modified on 08/12/08 15:29:02

Howto export your func modules to be rendered in other applications?

We prepared an API which gives the ability for users to use some useful information about written modules in func. Funcweb is an example that uses all that structure to render some widgets according to info that it recieves about the module methods. Therefore it is good all module writers to be aware of that feature to export their methods to Funcweb and other useful apps that uses func.

Exporting the meta info about your methods is really easy :

*Write your func module.

*Override method register_method_args in your module according to its rules and you're done.

Overriding that method is actually done by returning back a 4 level hash data structure and nothing more ...

The basic types :

'int': A Python integer (Rendered as TextField? in Funcweb)

'string': A Python String (Rendered as TextField? in Funcweb)

'boolean': A True,False Python boolean (Rendered as CheckBox? in Funcweb)

'float': A Python float number(Rendered as TextField? in Funcweb)

'hash': A Python dict(Rendered as an expanding Field in Funcweb)

'list': A Python list(Rendered as an expanding Field in Funcweb)

'list*': A Python list for methods that accept sth like def foo(*args)(Rendered as an expanding Field in Funcweb)

The common options that can be used for all types :

'optional' : Describes if the argument is necessary or not

'default': The default value for the argument

'description' : The description for the argument

The specific options matched with their types that can be used :

'int':

'range': 'Describes the range for given int argument ex : [1,100] '

'min': 'The min value for that integer'

'max': 'The max value for that integer'

'string':

'options': 'Describes what are the possibilities that can be used for that argument.It is a list ex : ['foo','boo','some'] and will be rendered as a dropdown box in Funcweb. It is good idea o supply options for your methods because it makes the usage of the method easier.'

'min_length':'The min length of the string there (good for server side validation)'

'max_length':'The max length of the string there'

'validator': 'Validator keyword is a useful one because it prevents your app to send some weird data to your method. It is just a simple and powerfull re string ex : '[a-z]+$

'boolean':

'float':('range','min','max') : Same as integer field

'hash':

'validator': The same meaning as string

'list':

'validator': Same as string but here all values of the list are validated against the re string

'list*':

'validator': Same as above

Examples :

class Service(func_module.FuncModule):
    #snip snip ..

    def start(self, service_name):
        #snip snip ...

    def register_method_args(self):
        service_name =  {
                'type':'string',
                'optional':False,
                'description':'The name of the running services',
                'validator':'^[a-z\-\_0-9]+$'
                }

         return {
                'start':{
                    'args':{'service_name':service_name}
                    'description':"Method to start a specific service"
                    },
            }

After you exported all your methods run the unittests to see if everything is ok and also test the method in Funcweb. You can also get the info about module info from command line :

    func "some*" call module_name get_method_args

For more examples you can check other modules' register_method_args methods.