Ejemplo n.º 1
0
    def to_dict(self):
        fields = []
        for field in self:
            choices = []
            for v in (hasattr(field, 'choices') and field.choices or []):
                choices.append(dict(
                    label = v[1],
                    value = v[0],
                )) 

            item = dict(
                name = field.name,
                label = field.label.text,
                type = field.type, 
                data = field.data,
                choices = choices,
                required = field.flags.required,
                disabled = False,
                description = field.description,
            )

            if len(choices) > 0 and str(field.data).strip() == 'None':
                item['data'] = choices[0]['value']

            fields.append(item)
        return fields
Ejemplo n.º 2
0
 def field_list(self):
     self.clear_defaults()
     if not self.included: return self._fields.values()
     fields = []
     for f in self.included: fields.append(self._fields[f])
     return fields