Skip to content

Commit

Permalink
fixes codemirror
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Feb 27, 2025
1 parent 2520f77 commit 2754d70
Show file tree
Hide file tree
Showing 9 changed files with 10,225 additions and 486 deletions.
31 changes: 15 additions & 16 deletions src/dbtemplates/admin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import logging
import posixpath

from django import forms
from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponse
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext

from admin_extra_buttons.decorators import button, view

# Check if django-reversion is installed and use reversions' VersionAdmin
# as the base admin class if yes
from admin_sync.mixin import PublishMixin, SyncMixin
from adminfilters.mixin import AdminFiltersMixin
from adminfilters.value import ValueFilter
from django import forms
from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpResponse
from django.shortcuts import render
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext

from dbtemplates.conf import settings
from dbtemplates.models import Template, add_template_to_cache, remove_cached_template
Expand All @@ -40,23 +40,21 @@ def render(self, name, value, attrs=None, renderer=None):
result = []
result.append(super().render(name, value, attrs))
result.append(
"""
<script type="text/javascript">
var editor = CodeMirror.fromTextArea('id_%(name)s', {
path: "%(media_prefix)sjs/",
f"""<script type="text/javascript">
var editor = CodeMirror.fromTextArea(document.getElementById('id_{name}'), {{
path: "{settings.DBTEMPLATES_MEDIA_PREFIX}js/",
parserfile: "parsedjango.js",
stylesheet: "%(media_prefix)scss/django.css",
stylesheet: "{settings.DBTEMPLATES_MEDIA_PREFIX}css/django.css",
continuousScanning: 500,
height: "40.2em",
tabMode: "shift",
indentUnit: 4,
lineNumbers: true
});
}});
</script>
"""
% {"media_prefix": settings.DBTEMPLATES_MEDIA_PREFIX, "name": name}
)
return "".join(result)
return mark_safe("".join(result)) # noqa: S308

Check warning

Code scanning / Bandit

Potential XSS on mark_safe function. Warning

Potential XSS on mark_safe function.

Check warning

Code scanning / Bandit

Use of mark_safe() may expose cross-site scripting vulnerabilities and should be reviewed. Warning

Use of mark_safe() may expose cross-site scripting vulnerabilities and should be reviewed.


if settings.DBTEMPLATES_USE_CODEMIRROR:
Expand Down Expand Up @@ -142,6 +140,7 @@ class TemplateAdmin(SyncMixin, AdminFiltersMixin, PublishMixin, TemplateModelAdm
save_as = True
search_fields = ("name", "content")
actions = ["invalidate_cache", "repopulate_cache", "check_syntax"]
change_form_template = "admin/dbtemplates/template/change_form.html"

def invalidate_cache(self, request, queryset):
for template in queryset:
Expand Down
3 changes: 1 addition & 2 deletions src/dbtemplates/conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import posixpath

from appconf import AppConf
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from appconf import AppConf


class DbTemplatesConf(AppConf):
USE_CODEMIRROR = False
Expand Down
1 change: 0 additions & 1 deletion src/dbtemplates/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.template import TemplateDoesNotExist
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _

from natural_keys import NaturalKeyModel, NaturalKeyModelManager

from dbtemplates.conf import settings
Expand Down
Loading

0 comments on commit 2754d70

Please sign in to comment.