Skip to content

Instantly share code, notes, and snippets.

@techniq
Created November 13, 2012 14:47
Show Gist options
  • Save techniq/4066098 to your computer and use it in GitHub Desktop.
Save techniq/4066098 to your computer and use it in GitHub Desktop.
Flask-Admin WTForms boostrap-wysihtml5
<!DOCTYPE html>
<html lang="en">
<head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
<link href='/static/bootstrap/css/bootstrap.css' rel='stylesheet' type='text/css' />
<link href='/static/wysihtml5/bootstrap-wysihtml5.css' rel='stylesheet' type='text/css' />
</head>
<body>
...
<script src="/static/wysihtml5/wysihtml5-0.3.0.min.js"></script>
<script type="text/javascript">
$('[data-role="wysihtml5"]').wysihtml5();
</script>
<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
NREUMQ.push(["load",new Date().getTime()]);
var e=document.createElement("script");
e.type="text/javascript";
e.src=(("http:"===document.location.protocol)?"http:":"https:") + "//" +
"d1ros97qkrwjf5.cloudfront.net/42/eum/rum.js";
document.body.appendChild(e);
if(NREUMQ.a)NREUMQ.a();
};
NREUMQ.a=window.onload;window.onload=NREUMQ.f;
};
NREUMQ.push(["nrfj","beacon-3.newrelic.com","5fea191aea","2478111","dVdXRUsJXllcERtQEl8XXlhKEh1HWBQ=",17,189,new Date().getTime(),"","","","",""]);</script></body>
</html>
from flask.ext.admin.contrib.sqlamodel import ModelView
from application.helpers.forms.fields import WysiHtml5TextAreaField
class ExampleModelView(AdminModelView):
form_overrides = dict(
body=WysiHtml5TextAreaField
)
from wtforms import fields
from .widgets import WysiHtml5Widget
class WysiHtml5TextAreaField(fields.TextAreaField):
widget = WysiHtml5Widget()
from wtforms.widgets import TextArea, HTMLString, html_params
from cgi import escape
class WysiHtml5Widget(TextArea):
def __call__(self, field, **kwargs):
kwargs['data-role'] = u'wysihtml5'
kwargs['class'] = u'span8'
kwargs['rows'] = 10
return super(WysiHtml5Widget, self).__call__(field, **kwargs)
@charlesmims
Copy link

this would be so much easier to read without all that newrelic tracking crud in it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment