summaryrefslogtreecommitdiff
path: root/ricky/param/multiselect.py
blob: 8da537475a234b5c4cb19108cffe461419e94475 (plain)
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
import random
from ricky.param import Param


class MultiSelect(Param):
    def __init__(self, **kwargs):
        super(MultiSelect, self).__init__(**kwargs)
        self._options = kwargs.get('options') or []
        if len(self._options):
            self._validate_options()

    def options(self):
        return self._options

    def _validate_options(self):
        try:
            pass
        except Exception:
            raise ValueError('Unable to validate %s\n:' % self.name)

    def value_get(self):
        return super(MultiSelect, self).value_get()

    def value_set(self, value):
        if value not in self._options and value is not None:
            raise ValueError
        super(MultiSelect, self).value_set(value)

    value = property(value_get, value_set)

    def randomize(self):
        self.value_set(random.choice(self.options))