Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Sourcery refactored master branch #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 10 additions & 12 deletions elrte/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
These are the default configuration options for Django-elRTE
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 25-51 refactored with the following changes:


import os
from django.conf import settings

Expand All @@ -22,32 +23,29 @@
os.path.join(settings.STATIC_URL, 'elrte/css/'))

if ELRTE_DEBUG:
URL = getattr(settings, 'ELRTE_JS_URL', '%selrte.full.js' % JS_BASE_URL)
URL = getattr(settings, 'ELRTE_JS_URL', f'{JS_BASE_URL}elrte.full.js')
else:
URL = getattr(settings, 'ELRTE_JS_URL', '%selrte.min.js' % JS_BASE_URL)
URL = getattr(settings, 'ELRTE_JS_URL', f'{JS_BASE_URL}elrte.min.js')

LOAD_JQUERY = getattr(settings, 'ELRTE_LOAD_JQUERY', True)
LOAD_JQUERYUI = getattr(settings, 'ELRTE_LOAD_JQUERYUI', True)

JS_URL = []

if LOAD_JQUERY:
JS_URL.append("%sjquery-1.6.1.min.js" % JS_BASE_URL)
JS_URL.append(f"{JS_BASE_URL}jquery-1.6.1.min.js")

if LOAD_JQUERYUI:
JS_URL.append("%sjquery-ui-1.8.13.custom.min.js" % JS_BASE_URL)
JS_URL.append(f"{JS_BASE_URL}jquery-ui-1.8.13.custom.min.js")

JS_URL.append(URL)

CSS_URL = []
if LOAD_JQUERYUI:
CSS_URL.append(
"%ssmoothness/jquery-ui-1.8.13.custom.css" % CSS_BASE_URL
)

CSS_URL.extend([
"%selrte.full.css" % CSS_BASE_URL,
"%sdjango-elrte.css" % CSS_BASE_URL,
])
CSS_URL.append(f"{CSS_BASE_URL}smoothness/jquery-ui-1.8.13.custom.css")

CSS_URL.extend(
[f"{CSS_BASE_URL}elrte.full.css", f"{CSS_BASE_URL}django-elrte.css"]
)

ADMIN_FIELDS = getattr(settings, 'ELRTE_ADMIN_FIELDS', {})
26 changes: 9 additions & 17 deletions elrte/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
ELRTE_DEFAULT_OPTIONS = {
'doctype': '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
'cssClass': 'el-rte',
'cssfiles': ['%selrte-inner.css' % elrte.settings.CSS_BASE_URL],
'cssfiles': [f'{elrte.settings.CSS_BASE_URL}elrte-inner.css'],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 19-30 refactored with the following changes:

This removes the following comments ( why? ):

# 'fmOpen': FileManagerOpener(),

'absoluteURLs': True,
'allowSource': True,
'lang': 'en',
'styleWithCss': False,
'height': None,
'fmAllow': True,
'toolbar': 'normal',
# 'fmOpen': FileManagerOpener(),
}

ELRTE_LANG_INCLUSION = 'i18n/elrte.%s.js' % getattr(ELRTE_DEFAULT_OPTIONS, 'lang', 'en')
ELRTE_LANG_INCLUSION = (
f"i18n/elrte.{getattr(ELRTE_DEFAULT_OPTIONS, 'lang', 'en')}.js"
)


class FileManagerOpener(object):
Expand Down Expand Up @@ -68,7 +69,7 @@ def render(self, name, value, attrs=None):
final_attrs = self.build_attrs(attrs)
final_attrs['name'] = name
config = self.get_config(name)
html = [u'<textarea%s>%s</textarea>' % (flatatt(final_attrs), escape(value))]
html = [f'<textarea{flatatt(final_attrs)}>{escape(value)}</textarea>']
Comment on lines -71 to +72
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ElrteTextareaWidget.render refactored with the following changes:

html.append(u'<input type="hidden" name="%(name)s_img" id="%(name)s_img">' % {'name': name})
html.append(config)
return mark_safe(u'\n'.join(html))
Expand All @@ -91,25 +92,16 @@ class AdminElrteTextareaWidget(ElrteTextareaWidget, admin_widgets.AdminTextareaW

def get_language_config(content_language=None):
language = get_language()[:2]
if content_language:
content_language = content_language[:2]
else:
content_language = language

config = {}
config['language'] = language

content_language = content_language[:2] if content_language else language
config = {'language': language}
lang_names = SortedDict()
for lang, name in settings.LANGUAGES:
if lang[:2] not in lang_names: lang_names[lang[:2]] = []
lang_names[lang[:2]].append(_(name))
sp_langs = []
for lang, names in lang_names.items():
if lang == content_language:
default = '+'
else:
default = ''
sp_langs.append(u'%s%s=%s' % (default, ' / '.join(names), lang))
default = '+' if lang == content_language else ''
sp_langs.append(f"{default}{' / '.join(names)}={lang}")
Comment on lines -94 to +104
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_language_config refactored with the following changes:


config['spellchecker_languages'] = ','.join(sp_langs)

Expand Down