def serialize(self, field, cstruct, readonly=False): if cstruct in (null, None): cstruct = () template = readonly and self.readonly_template or self.template return field.renderer(template, field=field, cstruct=cstruct, values=_normalize_choices(self.values))
def _normalize_optgroup_choices(values): result = [] for group in values: result.append({ 'label': group['label'], 'values': _normalize_choices(group['values']), }) return result
def get_select(self, mongodb, path, field_iter, **kw): html = "" for j, item_path in enumerate(path): readonly = kw.get('readonly', self.readonly) if item_path: values = get_items_ou_children(item_path, mongodb.nodes, 'ou') values = [(item['_id'], item['name']) for item in values] if not values: continue values = [('', 'Select an Organisational Unit')] + values if j == len(path) - 1: select_value = '' else: select_value = path[j + 1] else: values = kw.get('values', self.values) select_value = item_path template = readonly and self.readonly_template or self.template kw['values'] = _normalize_choices(values) tmpl_values = self.get_template_values(field_iter, select_value, kw) html += field_iter.renderer(template, **tmpl_values) return html