Skip to content

Commit 6c7be8c

Browse files
author
Shaun Sephton
committed
merge sustainingtechnologies/master with cleanup(pep8)
2 parents 1bb3a91 + 4765b1a commit 6c7be8c

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

ckeditor/fields.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
class RichTextField(models.TextField):
8-
def __init__(self, config_name='default', *args, **kwargs):
9-
self.config_name = config_name
8+
def __init__(self, *args, **kwargs):
9+
self.config_name = kwargs.pop("config_name", "default")
1010
super(RichTextField, self).__init__(*args, **kwargs)
1111

1212
def formfield(self, **kwargs):
@@ -22,3 +22,9 @@ class RichTextFormField(forms.fields.Field):
2222
def __init__(self, config_name='default', *args, **kwargs):
2323
kwargs.update({'widget': CKEditorWidget(config_name=config_name)})
2424
super(RichTextFormField, self).__init__(*args, **kwargs)
25+
26+
try:
27+
from south.modelsinspector import add_introspection_rules
28+
add_introspection_rules([], ["^ckeditor\.fields\.RichTextField"])
29+
except:
30+
pass

ckeditor/management/__init__.py

Whitespace-only changes.

ckeditor/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
3+
from ckeditor.views import create_thumbnail, get_image_files, \
4+
get_thumb_filename
5+
from django.core.management.base import NoArgsCommand
6+
7+
8+
class Command(NoArgsCommand):
9+
"""
10+
Creates thumbnail files for the CKEditor file image browser.
11+
Useful if starting to use django-ckeditor with existing images.
12+
"""
13+
def handle_noargs(self, **options):
14+
for image in get_image_files():
15+
if not os.path.isfile(get_thumb_filename(image)):
16+
print "Creating thumbnail for %s" % image
17+
try:
18+
create_thumbnail(image)
19+
except Exception, e:
20+
print "Couldn't create thumbnail for %s: %s" % (image, e)
21+
print "Finished"

ckeditor/views.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,11 @@ def upload(request):
138138
</script>""" % (request.GET['CKEditorFuncNum'], url))
139139

140140

141-
def get_image_browse_urls(user=None):
141+
def get_image_files(user=None):
142142
"""
143143
Recursively walks all dirs under upload dir and generates a list of
144-
thumbnail and full image URL's for each file found.
144+
full paths for each file found.
145145
"""
146-
images = []
147-
148146
# If a user is provided and CKEDITOR_RESTRICT_BY_USER is True,
149147
# limit images to user specific path, but not for superusers.
150148
if user and not user.is_superuser and getattr(settings, \
@@ -158,13 +156,22 @@ def get_image_browse_urls(user=None):
158156
for root, dirs, files in os.walk(browse_path):
159157
for filename in [os.path.join(root, x) for x in files]:
160158
# bypass for thumbs
161-
if '_thumb' in filename:
159+
if os.path.splitext(filename)[0].endswith('_thumb'):
162160
continue
161+
yield filename
162+
163163

164-
images.append({
165-
'thumb': get_media_url(get_thumb_filename(filename)),
166-
'src': get_media_url(filename)
167-
})
164+
def get_image_browse_urls(user=None):
165+
"""
166+
Recursively walks all dirs under upload dir and generates a list of
167+
thumbnail and full image URL's for each file found.
168+
"""
169+
images = []
170+
for filename in get_image_files(user=user):
171+
images.append({
172+
'thumb': get_media_url(get_thumb_filename(filename)),
173+
'src': get_media_url(filename)
174+
})
168175

169176
return images
170177

ckeditor/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Media:
4242
def __init__(self, config_name='default', *args, **kwargs):
4343
super(CKEditorWidget, self).__init__(*args, **kwargs)
4444
# Setup config from defaults.
45-
self.config = DEFAULT_CONFIG
45+
self.config = DEFAULT_CONFIG.copy()
4646

4747
# Try to get valid config from settings.
4848
configs = getattr(settings, 'CKEDITOR_CONFIGS', None)

project/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@
165165
},
166166
'custom': {
167167
'toolbar': [
168-
['Bold','Italic','Underline',],
168+
['Bold', 'Italic', 'Underline', ],
169169
'/',
170-
['Styles','Format','Font','FontSize',],
170+
['Styles', 'Format', 'Font', 'FontSize', ],
171171
],
172172
},
173173
}

0 commit comments

Comments
 (0)