Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions django_markdown/fields.py
Original file line number Diff line number Diff line change
@@ -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
Empty file.
3 changes: 1 addition & 2 deletions django_markdown/models.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 9 additions & 1 deletion django_markdown/static/django_markdown/jquery.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 1 addition & 9 deletions django_markdown/templates/django_markdown/editor_init.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
<script type="text/javascript">
(function($) {
$(document).ready(function() {
$("{{ selector }}").each(function (k, el) {
var el = $(el);
if(!el.hasClass("markItUpEditor")) el.markItUp(
mySettings, {{ extra_settings|default:"{}" }});
});
});
})(jQuery);
var extra_markitup_settings = {{ extra_settings|default:"{}"|safe }};
</script>

7 changes: 4 additions & 3 deletions django_markdown/urls.py
Original file line number Diff line number Diff line change
@@ -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')
]
2 changes: 1 addition & 1 deletion django_markdown/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
12 changes: 7 additions & 5 deletions django_markdown/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down