django-markdownx/markdownx/widgets.py

43 lines
1.1 KiB
Python
Raw Normal View History

2015-09-06 07:41:45 +00:00
from django import forms
2014-11-01 21:02:31 +00:00
from django.template import Context
from django.template.loader import get_template
2015-09-06 07:41:45 +00:00
from django.contrib.admin import widgets
2014-11-01 21:02:31 +00:00
2015-09-06 21:13:50 +00:00
from .settings import MARKDOWNX_EDITOR_RESIZABLE
2014-11-01 21:02:31 +00:00
2015-09-06 07:41:45 +00:00
class MarkdownxWidget(forms.Textarea):
2014-11-01 21:02:31 +00:00
def render(self, name, value, attrs=None):
2015-09-06 21:13:50 +00:00
if attrs.has_key('class'):
attrs['class'] += ' markdownx-editor'
else:
attrs.update({'class':'markdownx-editor'})
attrs['data-markdownx-editor-resizable'] = MARKDOWNX_EDITOR_RESIZABLE
2015-09-06 07:41:45 +00:00
widget = super(MarkdownxWidget, self).render(name, value, attrs)
2014-11-01 21:02:31 +00:00
t = get_template('markdownx/widget.html')
c = Context({
2015-09-06 07:41:45 +00:00
'markdownx_editor': widget,
2014-11-01 21:02:31 +00:00
})
return t.render(c)
class Media:
js = (
2015-09-06 07:41:45 +00:00
'markdownx/js/markdownx.js',
)
class AdminMarkdownxWidget(MarkdownxWidget, widgets.AdminTextareaWidget):
class Media:
css = {
'all': ('markdownx/admin/css/markdownx.css',)
}
js = (
'markdownx/js/markdownx.js',
2014-11-01 21:02:31 +00:00
)