def format_video_url(view, context, model, name): model = model if isinstance(model, dict) else model_to_dict(model) _value = model.get(name, None) video_src = urljoin(app.config.get('VIDEO_URL'), _value) if _value else '#' img_src = urljoin(app.config.get("MEDIA_URL"), model.get('cover')) if model.get('cover') else '#' html = u""" <div style="text-align:center">视频ID(%s)</div> <div style="text-align:center; width:300px; word-wrap:break-word;">%s</div> <div style="text-align:center"> <video src="%s" controls="controls" poster="%s" width="300px" preload="none"></video> </div> """ % (model.get('_id'), model.get('title'), video_src, img_src) _value = widgets.HTMLString(html) return _value
def format_model(model, name, model_view, url='', extend_name=None): _value = model.get(name, None) obj = model_view.get_one(str(_value), check_online=False) if obj: if extend_name is None: _value = '%s (%s)' % (obj.name, _value) else: # 显示组合字段 _value = '%s(%s) (%s)' % (obj.name, obj.get(extend_name), _value) if url: html = u'<a href="%s=%s">%s</a>' % (url, str(obj._id), _value) _value = widgets.HTMLString(html) else: _value = u'ID不存在' return _value
def __call__(self, field, **kwargs): if getattr(field, 'checked', field.data): kwargs['checked'] = True kwargs.setdefault('id', field.id) kwargs.setdefault('type', self.input_type) if 'value' not in kwargs: kwargs['value'] = field._value() label_class = u' ' if 'class' in kwargs: label_class = (u'%s="%s"' % (unicode('class'), escape(unicode(kwargs['class']), quote=True))) return widgets.HTMLString( u'<label %s><input %s> %s</label>' % (label_class, widgets.html_params(name=field.name, ** kwargs), field.label.text))
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) sub_kwargs = dict((k[4:], v) for k, v in kwargs.iteritems() if k.startswith(self.sub_startswith)) kwargs = dict( filter(lambda x: not x[0].startswith(self.sub_startswith), kwargs.iteritems())) sub_html = '%s %s' % (self.sub_tag, widgets.html_params(**sub_kwargs)) html = ['<%s %s>' % (self.html_tag, widgets.html_params(**kwargs))] for subfield in field: if self.prefix_label: html.append( '<%s>%s %s</%s>' % (sub_html, subfield.label, subfield(), self.sub_tag)) else: html.append( '<%s>%s %s</%s>' % (sub_html, subfield(), subfield.label, self.sub_tag)) html.append('</%s>' % self.html_tag) return widgets.HTMLString(''.join(html))
def forecast_widget(field, **kwargs): field_id = kwargs.pop("id", field.id) errors = {"city_name": ""} if field.errors: if "city_name" in field.errors: errors["city_name"] = "".join( '<p class="help-block">{}</p>'.format(error) for error in field.errors["city_name"]) html = [ "<div {}>".format(widgets.html_params(id=field_id, class_="col-xs-2")), '<label for="{}">{}</label> '.format(field_id, field.label), field.city_name(), field.stack_order(), '</div><div class="col-xs-8 js-grid-target {}"></div>'.format( field.id), ] if errors["city_name"]: html.append('<div class="col-xs-4">{}</div>'.format( errors["city_name"])) return widgets.HTMLString("".join(html))
def __call__(self, **kwargs): html = super(BetterBooleanField, self).__call__(**kwargs) html += u'<input type="hidden" name="{}" value="false">'.format( self.name) return widgets.HTMLString(html)
def __call__(self, text=None, **kwargs): kwargs['for'] = self.field_id attributes = widgets.html_params(**kwargs) return widgets.HTMLString(u'<label %s>%s</label>' % (attributes, text or self.text))
def __call__(self, field, **kwargs): kwargs.update({"class_": "checkbox-field"}) rendered_field = super().__call__(field, **kwargs) return widgets.HTMLString(""" %s<label class="state" for="%s"> </label> """ % (rendered_field, field.id))
def __call__(self, field, **kwargs): from cgi import escape input_file = '<input %s>' % widgets.html_params(name=field.name, type='file') return widgets.HTMLString('%s<br />Current: %s<br />%s <label for="%s">Clear file</label>'%(input_file, escape(field._value()), self.widget_checkbox(field._clear), field._clear.id))
def __call__(self, field, **kwargs): if 'value' not in kwargs: kwargs['value'] = field._value() html = '<div id="editor">%s</div>' % kwargs['value'] + '\n' + self.js return widgets.HTMLString(html)
def __call__(self, field, **kwargs): kwargs.setdefault("value", "") kwargs.setdefault("id", FIELD_NAME) return widgets.HTMLString("<input {params}></input>".format( params=widgets.html_params(name=field.name, **kwargs)))
def __call__(self, field, **kwargs): rendered_field = super().__call__(field, **kwargs) return widgets.HTMLString(""" %s<label class="state" for="%s"> </label> """ % (rendered_field, field.id))
def __call__(self, field, **kwargs): if 'value' not in kwargs: kwargs['value'] = field._value() html = '{css}<div id="editor">{value}</div>\n {js}'.format( css=self.custom_css, value=kwargs['value'], js=self.js) return widgets.HTMLString(html)
def __call__(self, text=None, **kwargs): from dtg.transtools import _ kwargs['for'] = self.field_id attributes = widgets.html_params(**kwargs) return widgets.HTMLString(u'<label %s>%s</label>' % (attributes, unicode(_(text or self.text))))
def format_image(view, context, model, name): model = model if isinstance(model, dict) else model_to_dict(model) _value = model.get(name, None) img_src = urljoin(app.config.get("MEDIA_URL"), _value) if _value else '#' _value = widgets.HTMLString('<img src="%s" width="100px"/>' % (img_src)) return _value
def __call__(self, field, **kwargs): kwargs.setdefault('id', field.id) return widgets.HTMLString( '<div %s></div>' % widgets.html_params(name=field.name, **kwargs))
def decorator(*args, **kwargs): return widgets.HTMLString(func(*args, **kwargs)[:-1] + '/>')