diff --git a/Makefile b/Makefile index 6607754..19ca237 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ t: clean $(VIRTUALENV)/bin/py.test @$(VIRTUALENV)/bin/py.test $(CURDIR)/example/db.sqlite3: $(VIRTUALENV) - $(VIRTUALENV)/bin/python example/manage.py syncdb --noinput + $(VIRTUALENV)/bin/python example/manage.py migrate --noinput .PHONY: run run: $(CURDIR)/example/db.sqlite3 diff --git a/django_markdown/fields.py b/django_markdown/fields.py index 05f8d94..02e45b1 100644 --- a/django_markdown/fields.py +++ b/django_markdown/fields.py @@ -1,10 +1,5 @@ from django import forms -from .widgets import MarkdownWidget class MarkdownFormField(forms.CharField): - def __init__(self, *args, **kwargs): - # Django admin overrides the 'widget' value so this seems the only way - # to scupper it! - super(MarkdownFormField, self).__init__(*args, **kwargs) - self.widget = MarkdownWidget() + pass diff --git a/django_markdown/migrations/__init__.py b/django_markdown/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_markdown/models.py b/django_markdown/models.py index 1f40f94..c3585d2 100644 --- a/django_markdown/models.py +++ b/django_markdown/models.py @@ -1,10 +1,9 @@ from django.db import models -from .fields import MarkdownFormField from .widgets import MarkdownWidget class MarkdownField(models.TextField): def formfield(self, **kwargs): - defaults = {'form_class': MarkdownFormField} + defaults = {'widget': MarkdownWidget} defaults.update(kwargs) return super(MarkdownField, self).formfield(**defaults) diff --git a/django_markdown/static/django_markdown/jquery.init.js b/django_markdown/static/django_markdown/jquery.init.js index 4af7e96..54a9266 100644 --- a/django_markdown/static/django_markdown/jquery.init.js +++ b/django_markdown/static/django_markdown/jquery.init.js @@ -35,4 +35,12 @@ jQuery = jQuery || django.jQuery; } }); - })(jQuery); + $(document).ready(function() { + var extra_settings = (extra_markitup_settings === undefined) ? {} : extra_markitup_settings; + + $("[data-widget='markItUpEditor']") + .markItUp(mySettings, extra_settings) + .removeData('data-widget'); + }); + +})(jQuery); diff --git a/django_markdown/templates/django_markdown/editor_init.html b/django_markdown/templates/django_markdown/editor_init.html index 5c8ff7a..7e1e4b9 100644 --- a/django_markdown/templates/django_markdown/editor_init.html +++ b/django_markdown/templates/django_markdown/editor_init.html @@ -1,12 +1,4 @@ diff --git a/django_markdown/urls.py b/django_markdown/urls.py index ca80d4b..f942283 100644 --- a/django_markdown/urls.py +++ b/django_markdown/urls.py @@ -1,8 +1,9 @@ """ Define preview URL. """ -from django.conf.urls import patterns, url +from django.conf.urls import url from .views import preview -urlpatterns = patterns( - '', url('preview/$', preview, name='django_markdown_preview')) +urlpatterns = [ + url('preview/$', preview, name='django_markdown_preview') +] diff --git a/django_markdown/views.py b/django_markdown/views.py index dbf352f..ef29860 100644 --- a/django_markdown/views.py +++ b/django_markdown/views.py @@ -19,6 +19,6 @@ def preview(request): return render( request, settings.MARKDOWN_PREVIEW_TEMPLATE, dict( - content=request.REQUEST.get('data', 'No content posted'), + content=request.POST.get('data', 'No content posted'), css=settings.MARKDOWN_STYLE )) diff --git a/django_markdown/widgets.py b/django_markdown/widgets.py index 43174f5..647edeb 100644 --- a/django_markdown/widgets.py +++ b/django_markdown/widgets.py @@ -24,17 +24,19 @@ class MarkdownWidget(forms.Textarea): """ - def __init__(self, attrs=None): - super(MarkdownWidget, self).__init__(attrs) - def render(self, name, value, attrs=None): """ Render widget. :returns: A rendered HTML """ - html = super(MarkdownWidget, self).render(name, value, attrs) - attrs = self.build_attrs(attrs) + + final_attrs = {'data-widget': 'markItUpEditor'} + if attrs is not None: + final_attrs.update(attrs) + + html = super(MarkdownWidget, self).render(name, value, final_attrs) + final_attrs = self.build_attrs(final_attrs) html += editor_js_initialization("#%s" % attrs['id']) return mark_safe(html)