Wizard

A wizard describes a series of steps defined as trytond.wizard.State. The wizard uses a trytond.wizard.Session to store data between states.

The basics:

Example

This example defines a wizard which export translations:

from trytond.wizard import Wizard, StateView, StateTransition, Button

class TranslationExport(Wizard):
    "Export translation"
    _name = "ir.translation.export"

    start = StateView('ir.translation.export.start',
        'ir.translation_export_start_view_form', [
            Button('Cancel', 'end', 'tryton-cancel'),
            Button('Export', 'export', 'tryton-ok', default=True),
            ])
    export = StateTransition()
    result = StateView('ir.translation.export.result',
        'ir.translation_export_result_view_form', [
            Button('Close', 'end', 'tryton-close'),
            ])

    def transition_export(self, session):
        pool = Pool()
        translation_obj = pool.get('ir.translation')
        file_data = translation_obj.translation_export(
            session.start.language.code, session.start.module.name)
        session.result.file = buffer(file_data)
        return 'result'

    def default_result(self, session, fields):
        return {
            'file': session.result.file,
            }

TranslationExport()

Instantiating the class registers the wizard class in the framework. Later the class will be instantiated once per database and stored in the Pool.

Table Of Contents

Previous topic

Extending View

Next topic

Reports

This Page