Skip to content

Commit a179d8e

Browse files
akadan47mazelife
authored andcommitted
Version 1.2.7 - Support redactor fields in django admin inlines
* Tweak admin style * Fork setup.js for use in the admin to get inlines working * Bumps minor version number, updates AUTHORS and changelog
1 parent 17df036 commit a179d8e

File tree

6 files changed

+74
-8
lines changed

6 files changed

+74
-8
lines changed

AUTHORS.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
James Stevenson <[email protected]>
22
Henrique Carvalho Alves <[email protected]>
33
James Stevenson <[email protected]>
4-
5-
New due to cherry picking
6-
74
Daniel Lemos <[email protected]> (xspager)
85
Riley Strong <[email protected]> (strongriley)
9-
Ryan Blunden <[email protected]> (ryan-blunden)
6+
Ryan Blunden <[email protected]> (ryan-blunden)
7+
Denis Popov <[email protected]> (akadan47)

CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ v1.2.2, Nov 1, 2012 -- Fixes a bug where adding custom CSS file to the editable
1111
v1.2.5, Jan 16, 2014 -- Updates Redactor to 9.1.9
1212

1313
v1.2.6, Apr 24, 2014 -- Python 3 compatibility added, bug with translations fixed.
14+
15+
v1.2.7, June 10, 2014 -- Fixes bug in adding inlines using a redactor widget in the Django admin.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var Redactor = (function ($) {
2+
// Redactor palette attributes will accumulate here.
3+
var redactor_attrs = [];
4+
// Initialize all textareas with the ``redactor_content`` class
5+
// as a Redactor rich text area.
6+
$(document).ready(function () {
7+
var redactor_fields = $("textarea.redactor_content");
8+
if (redactor_fields.length !== redactor_attrs.length) {
9+
window.alert("Number of registered attributes does not match the widget count.");
10+
}
11+
12+
// Model fields
13+
var model_redactor_fields = $("form > div > .module textarea.redactor_content");
14+
model_redactor_fields.each(function (i) {
15+
var settings = redactor_attrs[i];
16+
$(this).parent("div").find("label").addClass("redactor_label");
17+
$(this).redactor(settings);
18+
});
19+
20+
// Inlines
21+
var inline_groups_with_redactor = [];
22+
var count_inline_fields = 0;
23+
24+
// Fill inline groups with redactor widgets
25+
$("form > div > .inline-group").each(function() {
26+
if ($(this).find('.module textarea.redactor_content').length)
27+
inline_groups_with_redactor.push($(this));
28+
});
29+
30+
// Init redactor on inlines
31+
$.each(inline_groups_with_redactor, function () {
32+
var inline_fields = $(this).find("textarea.redactor_content");
33+
var last_inline_field_num = model_redactor_fields.length + (count_inline_fields + inline_fields.length);
34+
var settings = redactor_attrs[last_inline_field_num-1];
35+
count_inline_fields += inline_fields.length;
36+
37+
// Init redactor on displayed (or extra) inlines
38+
$(this).find(".inline-related:not(.empty-form) textarea.redactor_content").each(function () {
39+
$(this).parent("div").find("label").addClass("redactor_label");
40+
$(this).redactor(settings);
41+
});
42+
43+
// Init redactor on new added inline
44+
$(this).on('DOMNodeInserted', '.inline-related:not(.redactor_label)', function() {
45+
$(this).addClass('redactor_label');
46+
$(this).find('textarea.redactor_content').redactor(settings);
47+
});
48+
49+
});
50+
});
51+
52+
return {
53+
register: function () {
54+
var attrs = arguments.length !== 0 ? arguments[0] : null;
55+
redactor_attrs.push(attrs);
56+
}
57+
};
58+
})(jQuery);
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
.redactor_box {
2+
display: inline-block;
23
width: 900px;
34
}
45
.redactor_box.wide {
5-
width: 1200px
6+
width: 1200px;
67
}
78
label.redactor_label {
9+
display: inline-block;
810
float: none;
911
padding-bottom: 10px;
12+
padding-right: 5px;
13+
vertical-align: top;
14+
}
15+
form .aligned .redactor_editor p {
16+
margin-left: 0;
17+
padding-left: 0;
1018
}

redactor/widgets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from urllib.parse import urljoin
1212

1313

14-
1514
from django.conf import settings
1615
from django.forms import Media, Textarea
1716
from django.utils.safestring import mark_safe
@@ -86,7 +85,6 @@ def __init__(self, attrs=None, redactor_css=None, redactor_settings=None, includ
8685
def _get_js_media(self):
8786
js = (
8887
'django-redactor/redactor/redactor.min.js',
89-
'django-redactor/redactor/setup.js',
9088
)
9189
if self.include_jquery:
9290
js = ('django-redactor/lib/jquery-1.9.0.min.js',) + js
@@ -107,6 +105,7 @@ def media(self):
107105
js = self._get_js_media()
108106
if self.redactor_settings['lang'] != 'en':
109107
js += ('django-redactor/redactor/langs/%s.js' % self.redactor_settings['lang'],)
108+
js += ('django-redactor/redactor/setup.js',)
110109
css = {
111110
'screen': [
112111
'django-redactor/redactor/css/redactor.css',
@@ -133,6 +132,7 @@ def media(self):
133132
js = self._get_js_media()
134133
if self.redactor_settings['lang'] != 'en':
135134
js += ('django-redactor/redactor/langs/%s.js' % self.redactor_settings['lang'],)
135+
js += ('django-redactor/redactor/admin_setup.js',)
136136
css = {
137137
'screen': [
138138
'django-redactor/redactor/css/redactor.css',

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from distutils.core import setup
55

66

7-
version = '1.2.6'
7+
version = '1.2.7'
88

99
classifiers = [
1010
"Development Status :: 5 - Production/Stable",

0 commit comments

Comments
 (0)