Beispiel #1
0
    def render(self, renderer, form, renderable, out, **kwargs):

        fmtmap = renderer.createFormatMap(form, renderable, **kwargs)

        opts = []
        
        if renderable.vocab:
            
            vocab = Registry.get_vocab(renderable.vocab)
            
            if callable(vocab):
                
                opts = vocab()
        else:
            opts = renderable.options

        value = form.data[renderable.bind]

        if renderable.format == "full":

            print >> out, TEMPLATES['SELECT_FULL'](
                control=renderable, 
                value=value,
                options=opts,
                extra_classes=fmtmap['extra_classes']
                )

        else:

            print >> out, TEMPLATES['SELECT_COMPACT'](
                control=renderable, 
                value=value,
                options=opts,
                extra_classes=fmtmap['extra_classes']
                )
Beispiel #2
0
    def lexVal(self, value, **kwargs):

        """ Lexical value of select should return the label of the
        matching option. """

        if type([]) == type(value):

            res = []

            for val in value:
                res.append(self.lexVal(val))

            return res

        options = []

        if self.vocab:
            vocab = Registry.get_vocab(self.vocab)

            args = []
            if self.vocab_args:
                args = self.vocab_args.split(",")

            if callable(vocab):
                options = vocab(*args, **kwargs)

        options.extend(self.options)

        for opt in options:

            if self._is_same(opt.value, value):
                return opt.label

        return value
Beispiel #3
0
    def lexVal(self, value, **kwargs):
        """ Lexical value of select should return the label of the
        matching option. """

        if type([]) == type(value):

            res = []

            for val in value:
                res.append(self.lexVal(val))

            return res

        options = []

        if self.vocab:
            vocab = Registry.get_vocab(self.vocab)

            args = []
            if self.vocab_args:
                args = self.vocab_args.split(",")

            if callable(vocab):
                options = vocab(*args, **kwargs)

        options.extend(self.options)

        for opt in options:

            if self._is_same(opt.value, value):
                return opt.label

        return value
Beispiel #4
0
    def render(self, renderer, form, renderable, out, **kwargs):

        fmtmap = renderer.createFormatMap(form, renderable, **kwargs)

        opts = []

        if renderable.vocab:

            vocab = Registry.get_vocab(renderable.vocab)

            if callable(vocab):

                args = []
                if renderable.vocab_args:
                    args = renderable.vocab_args.split(",")

                opts = vocab(*args, **kwargs)

        opts.extend(renderable.options)

        value = form.data[renderable.bind]

        # some hacking for multiple type. sometimes the saved data is just a
        # plain old type (int) and we expect a list of strings in the template
        if fmtmap['multiple'] and fmtmap['multiple'].lower() == 'true':
            value = form.getFieldValue(renderable.id, lexical=False)
            if type(value) == ListType:  # just to be sure?
                value = [str(val) for val in value]

        if renderable.format == "full":

            print >> out, get_template('select_full')(control=renderable,
                                                      value=value,
                                                      options=opts,
                                                      fmtmap=fmtmap)

        else:

            print >> out, get_template('select')(control=renderable,
                                                 value=value,
                                                 options=opts,
                                                 multiple=fmtmap['multiple'],
                                                 fmtmap=fmtmap)
    def render(self, renderer, form, renderable, out, **kwargs):

        fmtmap = renderer.createFormatMap(form, renderable, **kwargs)

        opts = []

        if renderable.vocab:

            vocab = Registry.get_vocab(renderable.vocab)

            if callable(vocab):

                args = []
                if renderable.vocab_args:
                    args = renderable.vocab_args.split(",")

                opts = vocab(*args, **kwargs)

        opts.extend(renderable.options)

        value = form.data[renderable.bind]

        # some hacking for multiple type. sometimes the saved data is just a
        # plain old type (int) and we expect a list of strings in the template
        if fmtmap["multiple"] and fmtmap["multiple"].lower() == "true":
            value = form.getFieldValue(renderable.id, lexical=False)
            if type(value) == ListType:  # just to be sure?
                value = [str(val) for val in value]

        if renderable.format == "full":

            print >> out, get_template("select_full")(control=renderable, value=value, options=opts, fmtmap=fmtmap)

        else:

            print >> out, get_template("select")(
                control=renderable, value=value, options=opts, multiple=fmtmap["multiple"], fmtmap=fmtmap
            )