Exemplo n.º 1
0
    def uiValue2DataValue(self, valuedict):
        # override
        uinm = self.uiName()
        keyhost = uinm + '_host[]'
        keyapi = uinm + '_apikey[]'
        keyenabled = uinm + '_enabled[]'

        res = []

        if isinstance(valuedict[keyhost], basestring):
            # there is just one set of extra options, in this case, they are saved as plain data,
            # not arrays.
            hst = str(valuedict[keyhost])
            api = str(valuedict[keyapi])
            enb = boolext(valuedict[keyenabled])

            res.append(hst)
            res.append(api)
            res.append(enb)
        else:
            ll = len(valuedict[keyhost])
            for i in xrange(ll):
                hst = str(valuedict[keyhost][i])
                api = str(valuedict[keyapi][i])
                enb = boolext(valuedict[keyenabled][i])

                res.append(hst)
                res.append(api)
                res.append(enb)

        return res
Exemplo n.º 2
0
    def uiValue(self):
        # override

        v = super(OptionExtra, self).uiValue()

        # going to convert:
        # v = [ host1, apikey1, enabled1, host2, apikey2, enabed2, ..... ]
        # =>
        # d = [
        #          {"host": str(host1), "apikey": str(apikey1), "enabled": boolext(enabled1)},
        #          {"host": str(host2), "apikey": str(apikey2), "enabled": boolext(enabled2)}
        #     ]
        #
        i = 0
        d = []
        if v:
            ll = len(v)
            while i + 2 < ll:
                h = str(v[i])
                a = str(v[i + 1])
                e = boolext(v[i + 2])

                d.append({"host": h, "apikey": a, "enabled": e})
                i += 3

        return d