def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) kwargs.setdefault('name', field.name) template = self.data_template if field.data else self.empty_template if field.errors: template = self.empty_template if field.data and isinstance(field.data, FileStorage): value = field.data.filename else: value = field.data or '' return Markup( template % { 'text': html_params(type='text', readonly='readonly', value=value, name=field.name), 'file': html_params(type='file', value=value, **kwargs), 'marker': '_%s-delete' % field.name })
def __call__(self, field, **kwargs): items = [] for val, label, selected in field.iter_choices(): args = { 'id': val, 'name': field.name, 'label': escape(label), 'selected': ' checked' if selected else '', } items.append(self.template % args) return Markup(''.join(items))
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) placeholder = '' if field.data and isinstance(field.data, ImageGridFsProxy): args = helpers.make_thumb_args(field.data) placeholder = self.template % { 'thumb': get_url('.api_file_view', **args), 'marker': '_%s-delete' % field.name } return Markup( '%s<input %s>' % (placeholder, html_params(name=field.name, type='file', **kwargs)))
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) placeholder = '' if field.data and isinstance(field.data, GridFSProxy): data = field.data placeholder = self.template % { 'name': escape(data.name), 'content_type': escape(data.content_type), 'size': data.length // 1024, 'marker': '_%s-delete' % field.name } return Markup( '%s<input %s>' % (placeholder, html_params(name=field.name, type='file', **kwargs)))
def __call__(self, field, **kwargs): kwargs.setdefault('data-role', 'select2-ajax') kwargs.setdefault('data-url', get_url('.ajax_lookup', name=field.loader.name)) allow_blank = getattr(field, 'allow_blank', False) if allow_blank and not self.multiple: kwargs['data-allow-blank'] = u'1' kwargs.setdefault('id', field.id) kwargs.setdefault('type', 'hidden') if self.multiple: result = [] ids = [] for value in field.data: data = field.loader.format(value) result.append(data) ids.append(as_unicode(data[0])) separator = getattr(field, 'separator', ',') kwargs['value'] = separator.join(ids) kwargs['data-json'] = json.dumps(result) kwargs['data-multiple'] = u'1' else: data = field.loader.format(field.data) if data: kwargs['value'] = data[0] kwargs['data-json'] = json.dumps(data) placeholder = field.loader.options.get('placeholder', gettext('Please select model')) kwargs.setdefault('data-placeholder', placeholder) minimum_input_length = int( field.loader.options.get('minimum_input_length', 1)) kwargs.setdefault('data-minimum-input-length', minimum_input_length) return Markup('<input %s>' % html_params(name=field.name, **kwargs))
def __call__(self, field, **kwargs): display_value = kwargs.pop('display_value', '') kwargs.setdefault('data-value', display_value) kwargs.setdefault('data-role', 'x-editable') kwargs.setdefault('data-url', './ajax/update/') kwargs.setdefault('id', field.id) kwargs.setdefault('name', field.name) kwargs.setdefault('href', '#') if not kwargs.get('pk'): raise Exception('pk required') kwargs['data-pk'] = str(kwargs.pop("pk")) kwargs['data-csrf'] = kwargs.pop("csrf", "") kwargs = self.get_kwargs(field, kwargs) return Markup('<a %s>%s</a>' % (html_params(**kwargs), escape(display_value)))
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) kwargs.setdefault('name', field.name) args = { 'text': html_params(type='hidden', value=field.data, name=field.name), 'file': html_params(type='file', **kwargs), 'marker': '_%s-delete' % field.name } if field.data and isinstance(field.data, string_types): url = self.get_url(field) args['image'] = html_params(src=url) template = self.data_template else: template = self.empty_template return Markup(template % args)