forked from darklow/django-suit-redactor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Merge PR darklow#14 and darklow#15 manually
- Fix constructor for render
- Loading branch information
Amos Vryhof
committed
Feb 19, 2020
1 parent
492ca01
commit 803b3b2
Showing
5 changed files
with
136 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='django-suit-redactor', | ||
version='0.0.4', | ||
description='Imperavi Redactor (WYSIWYG editor) integration app for Django admin. http://imperavi.com/redactor/', | ||
author='Kaspars Sprogis (darklow)', | ||
author_email='[email protected]', | ||
url='https://github.com/darklow/django-suit-redactor', | ||
packages=['suit_redactor'], | ||
name="django-suit-redactor", | ||
version="0.0.5", | ||
description="Imperavi Redactor (WYSIWYG editor) integration app for Django admin. http://imperavi.com/redactor/", | ||
author="Kaspars Sprogis (darklow)", | ||
author_email="[email protected]", | ||
url="https://github.com/darklow/django-suit-redactor", | ||
packages=["suit_redactor"], | ||
zip_safe=False, | ||
include_package_data=True, | ||
install_requires=["django<3.0", "django-suit"], | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Framework :: Django', | ||
'License :: Free for non-commercial use', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'Programming Language :: Python', | ||
'Environment :: Web Environment', | ||
'Topic :: Software Development :: User Interfaces', | ||
] | ||
"Development Status :: 5 - Production/Stable", | ||
"Framework :: Django", | ||
"License :: Free for non-commercial use", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: System Administrators", | ||
"Programming Language :: Python", | ||
"Environment :: Web Environment", | ||
"Topic :: Software Development :: User Interfaces", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from django.conf.urls import patterns, include, url | ||
from django.conf.urls import include | ||
from django.contrib import admin | ||
from django.urls import path | ||
|
||
admin.autodiscover() | ||
|
||
urlpatterns = patterns('', | ||
url(r'^admin/', include(admin.site.urls)), | ||
) | ||
urlpatterns = [ | ||
path("admin/", include(admin.site.urls)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
# from django.core.serializers import json | ||
import json | ||
|
||
from django.forms import Textarea | ||
from django.utils.safestring import mark_safe | ||
from django.contrib.staticfiles.templatetags.staticfiles import static | ||
|
||
try: | ||
import json | ||
except ImportError: | ||
import django.utils.simplejson as json | ||
|
||
|
||
class RedactorWidget(Textarea): | ||
class Media: | ||
css = { | ||
'all': (static('suit-redactor/redactor/redactor.css'),) | ||
} | ||
css = {"all": ("suit-redactor/redactor/redactor.css",)} | ||
js = ( | ||
static('suit-redactor/redactor/ensure.jquery.js'), | ||
static('suit-redactor/redactor/redactor.min.js'), | ||
"suit-redactor/redactor/ensure.jquery.js", | ||
"suit-redactor/redactor/redactor.min.js", | ||
) | ||
|
||
def __init__(self, attrs=None, editor_options={}): | ||
def __init__(self, attrs=None, editor_options=None): | ||
super(RedactorWidget, self).__init__(attrs) | ||
if editor_options is None: | ||
editor_options = {} | ||
self.editor_options = editor_options | ||
|
||
def render(self, name, value, attrs=None): | ||
def render(self, name, value, attrs=None, renderer=None): | ||
output = super(RedactorWidget, self).render(name, value, attrs) | ||
output += mark_safe( | ||
'<script type="text/javascript">$("#id_%s").redactor(%s);</script>' | ||
% (name, json.dumps(self.editor_options))) | ||
blank_element = "-__prefix__-" | ||
editor_options = json.dumps(self.editor_options) | ||
if blank_element in name: | ||
try: | ||
prefix, suffix = name.split(blank_element) | ||
except KeyError: | ||
return output | ||
dom_id = r"/id_{}-\d+-{}/g".format(prefix, suffix) | ||
output += mark_safe( | ||
""" | ||
<script type="text/javascript"> | ||
document.addEventListener("DOMContentLoaded", function() { | ||
Suit.after_inline.register('%s', function (prefix, row) { | ||
if(row === undefined || row[0] === undefined || !row[0].childNodes){ | ||
return; | ||
} | ||
row[0].childNodes.forEach(function(child) { | ||
if(!child.childNodes){ | ||
return; | ||
} | ||
child.childNodes.forEach(function(subChild) { | ||
if(subChild.id){ | ||
var id = subChild.id.match(%s); | ||
if(id !== null && id[0] !== undefined){ | ||
$('#' + id[0]).redactor(%s); | ||
}; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
""" | ||
% (prefix, dom_id, editor_options) | ||
) | ||
else: | ||
output += mark_safe( | ||
'<script type="text/javascript">$("#id_%s").redactor(%s);</script>' % (name, editor_options) | ||
) | ||
return output |