File: selection.py

package info (click to toggle)
tryton-server 1.6.1-2%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 2,440 kB
  • ctags: 3,017
  • sloc: python: 24,380; xml: 3,771; sql: 506; sh: 126; makefile: 74
file content (35 lines) | stat: -rw-r--r-- 1,537 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#This file is part of Tryton.  The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.

from trytond.model.fields.field import Field


class Selection(Field):
    '''
    Define a selection field (``str``).
    '''
    _type = 'selection'

    def __init__(self, selection, string='', sort=True, translate=True,
            help='', required=False, readonly=False, domain=None, states=None,
            priority=0, change_default=False, select=0, on_change=None,
            on_change_with=None, depends=None, order_field=None, context=None):
        '''
        :param selection: A list or a function name that returns a list.
            The list must be a list of tuples. First member is the value
            to store and the second is the value to display.
        :param sort: A boolean to sort or not the selections.
        '''
        super(Selection, self).__init__(string=string,  help=help,
                required=required, readonly=readonly, domain=domain,
                states=states, priority=priority, change_default=change_default,
                select=select, on_change=on_change,
                on_change_with=on_change_with, depends=depends,
                order_field=order_field, context=context)
        if hasattr(selection, 'copy'):
            self.selection = selection.copy()
        else:
            self.selection = selection
        self.sort = sort
        self.translate_selection = translate
    __init__.__doc__ += Field.__init__.__doc__