Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • beat/beat.web
1 result
Show changes
Commits on Source (5)
......@@ -192,7 +192,7 @@ class JobSplitInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -210,7 +210,7 @@ class Job(admin.ModelAdmin):
def splits(self, obj):
return obj.splits.count()
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......
......@@ -229,7 +229,7 @@ class DatabaseSetTemplateOutputInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -245,7 +245,7 @@ class DatabaseSetTemplate(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -265,7 +265,7 @@ class DatabaseSetOutputInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -286,7 +286,7 @@ class DatabaseSet(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......
......@@ -133,7 +133,7 @@ class BlockInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -268,7 +268,7 @@ class BlockInputInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -291,7 +291,7 @@ class CachedFileInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -328,7 +328,7 @@ class BlockDependentsInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -365,7 +365,7 @@ class BlockDependenciesInline(admin.TabularInline):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -457,7 +457,7 @@ class Block(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
form = BlockModelForm
......@@ -505,7 +505,7 @@ class Result(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......@@ -640,7 +640,7 @@ class CachedFile(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return False
......
......@@ -29,10 +29,10 @@
# https://github.com/lambdalisue/django-codemirror-widget
# (originally BSD-Licensed)
from itertools import chain
import re
import hashlib
import json
import re
from itertools import chain
from django import forms
from django.conf import settings
......@@ -41,31 +41,36 @@ from django.utils.safestring import mark_safe
from .. import __version__
# set default settings
CODEMIRROR_PATH = getattr(settings, 'CODEMIRROR_PATH', 'codemirror')
if CODEMIRROR_PATH.endswith('/'):
CODEMIRROR_PATH = getattr(settings, "CODEMIRROR_PATH", "codemirror")
if CODEMIRROR_PATH.endswith("/"):
CODEMIRROR_PATH = CODEMIRROR_PATH[:-1]
CODEMIRROR_MODE = getattr(settings, 'CODEMIRROR_MODE', 'javascript')
CODEMIRROR_THEME = getattr(settings, 'CODEMIRROR_THEME', 'default')
CODEMIRROR_SIZE = getattr(settings, 'CODEMIRROR_SIZE', None)
CODEMIRROR_MODE = getattr(settings, "CODEMIRROR_MODE", "javascript")
CODEMIRROR_THEME = getattr(settings, "CODEMIRROR_THEME", "default")
CODEMIRROR_SIZE = getattr(settings, "CODEMIRROR_SIZE", None)
THEME_CSS_FILENAME_RE = re.compile(r"[\w-]+")
THEME_CSS_FILENAME_RE = re.compile(r'[\w-]+')
def uniq(seq, idfun=None):
"""Order preserving, fast de-duplication for lists"""
if idfun is None:
def idfun(x): return x
def idfun(x):
return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen: continue
if marker in seen:
continue
seen[marker] = 1
result.append(item)
return result
def isstring(obj):
try:
return isinstance(obj, basestring)
......@@ -111,7 +116,7 @@ class CodeMirrorJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, CodeMirrorJavascript):
# If a Javascript object is encountered, replace it with a placeholder.
stash_id = self.stash_prefix + hashlib.md5(obj.js).hexdigest()
stash_id = self.stash_prefix + hashlib.md5(obj.js).hexdigest() # nosec
self.stash[stash_id] = obj.js
return stash_id
return super(CodeMirrorJSONEncoder, self).default(obj)
......@@ -135,7 +140,7 @@ class FingerPrintedMedia(forms.Media):
for the latest version of the application
"""
abs_path = super(FingerPrintedMedia, self).absolute_path(path)
abs_path += '?v={}'.format(__version__)
abs_path += "?v={}".format(__version__)
return abs_path
......@@ -150,14 +155,17 @@ class CodeMirrorTextarea(forms.Textarea):
mode_name = self.mode_name
js = [
"%s/lib/codemirror.js" % (CODEMIRROR_PATH,),
"%s/addon/fold/foldcode.js" % (CODEMIRROR_PATH,),
"%s/addon/fold/foldgutter.js" % (CODEMIRROR_PATH,),
"%s/addon/fold/foldcode.js" % (CODEMIRROR_PATH,),
"%s/addon/fold/foldgutter.js" % (CODEMIRROR_PATH,),
]
if not self.custom_mode:
js.append("%s/mode/%s/%s.js" % (CODEMIRROR_PATH, mode_name, mode_name))
js += ["%s/mode/%s/%s.js" % (CODEMIRROR_PATH, dependency, dependency) for dependency in self.dependencies]
js += [
"%s/mode/%s/%s.js" % (CODEMIRROR_PATH, dependency, dependency)
for dependency in self.dependencies
]
js += ["%s/addon/%s.js" % (CODEMIRROR_PATH, addon) for addon in self.addon_js]
if self.keymap:
......@@ -170,24 +178,38 @@ class CodeMirrorTextarea(forms.Textarea):
js += ["ui/js/codemirror-defaults.js"]
css = (
"%s/lib/codemirror.css" % CODEMIRROR_PATH,
) + \
tuple("%s/theme/%s.css" % (CODEMIRROR_PATH, theme_css_filename)
for theme_css_filename in self.theme_css) + \
tuple("%s/addon/%s.css" % (CODEMIRROR_PATH, css_file)
for css_file in self.addon_css) + \
(
"ui/css/codemirror-overrides.css",
("%s/lib/codemirror.css" % CODEMIRROR_PATH,)
+ tuple(
"%s/theme/%s.css" % (CODEMIRROR_PATH, theme_css_filename)
for theme_css_filename in self.theme_css
)
+ tuple(
"%s/addon/%s.css" % (CODEMIRROR_PATH, css_file)
for css_file in self.addon_css
)
+ (
"ui/css/codemirror-overrides.css",
"%s/addon/fold/foldgutter.css" % CODEMIRROR_PATH,
)
)
return FingerPrintedMedia(css={'all': css}, js=js)
return FingerPrintedMedia(css={"all": css}, js=js)
def __init__(
self, attrs=None, mode=None, theme=None, config=None, size=None,
dependencies=(), addon_js=(), addon_css=(),
custom_mode=None, custom_js=(), keymap=None, **kwargs):
self,
attrs=None,
mode=None,
theme=None,
config=None,
size=None,
dependencies=(),
addon_js=(),
addon_css=(),
custom_mode=None,
custom_js=(),
keymap=None,
**kwargs
):
u"""Constructor of CodeMirrorTextarea
Attribute:
......@@ -264,8 +286,8 @@ class CodeMirrorTextarea(forms.Textarea):
self.mode = mode or custom_mode or CODEMIRROR_MODE
if isstring(self.mode):
self.mode = { 'name': self.mode }
self.mode_name = self.mode['name']
self.mode = {"name": self.mode}
self.mode_name = self.mode["name"]
self.size = size or CODEMIRROR_SIZE
self.custom_mode = custom_mode
self.dependencies = dependencies
......@@ -274,47 +296,44 @@ class CodeMirrorTextarea(forms.Textarea):
self.custom_js = custom_js
self.keymap = keymap
self.addon_js = uniq(list(addon_js) + [
"mode/overlay",
"search/search",
"search/searchcursor",
"dialog/dialog",
])
self.addon_js = uniq(
list(addon_js)
+ ["mode/overlay", "search/search", "search/searchcursor", "dialog/dialog"]
)
self.addon_css = uniq(list(addon_css) + ["dialog/dialog"])
self.theme = theme or CODEMIRROR_THEME
theme_css_filename = THEME_CSS_FILENAME_RE.search(self.theme).group(0)
if theme_css_filename == 'default':
if theme_css_filename == "default":
self.theme_css = []
else:
self.theme_css = [theme_css_filename]
self.config = config or {}
def render(self, name, value, attrs=None):
def render(self, name, value, attrs=None, renderer=None):
"""Render CodeMirrorTextarea"""
if self.size is not None:
suffix = ' %s_editor.setSize%s;' % (name, tuple(self.size))
suffix = " %s_editor.setSize%s;" % (name, tuple(self.size))
else:
suffix = ''
suffix = ""
self.config.setdefault('foldGutter', True)
option_json = CodeMirrorJSONEncoder().encode(dict(chain(
self.config.items(),
[('mode', self.mode), ('theme', self.theme)])))
self.config.setdefault("foldGutter", True)
option_json = CodeMirrorJSONEncoder().encode(
dict(
chain(self.config.items(), [("mode", self.mode), ("theme", self.theme)])
)
)
output = [
super(CodeMirrorTextarea, self).render(name, value, attrs),
'<script type="text/javascript">var %(name)s_editor = CodeMirror.fromTextArea(document.getElementById("id_%(name)s"), %(options)s);%(suffix)s</script>' % \
dict(
name=name,
options=option_json,
suffix=suffix,
),
super().render(name, value, attrs, renderer),
'<script type="text/javascript">var %(name)s_editor = CodeMirror.fromTextArea(document.getElementById("id_%(name)s"), %(options)s);%(suffix)s</script>'
% dict(name=name, options=option_json, suffix=suffix,),
]
return mark_safe('\n'.join(output))
return mark_safe("\n".join(output)) # nosec
class CodeMirrorFileWidget(CodeMirrorTextarea):
"""Allows editing a file instead of a plain content"""
......@@ -322,11 +341,13 @@ class CodeMirrorFileWidget(CodeMirrorTextarea):
def __init__(self, *args, **kwargs):
super(CodeMirrorFileWidget, self).__init__(*args, **kwargs)
def render(self, name, value, attrs=None):
def render(self, name, value, attrs=None, renderer=None):
if isinstance(value, str):
contents = value
elif hasattr(value, 'read'):
elif hasattr(value, "read"):
contents = value.read()
if type(contents) == bytes:
contents = contents.decode("utf-8")
else:
contents = ''
return mark_safe(super(CodeMirrorFileWidget, self).render(name, contents, attrs))
contents = ""
return mark_safe(super().render(name, contents, attrs, renderer)) # nosec