Skip to content

Commit b8de43c

Browse files
committed
Merge branch 'feature/admin-link-updates'
2 parents db67ae5 + 6c92a65 commit b8de43c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

easyaudit/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.core.urlresolvers import reverse
77

88
from django.utils.safestring import mark_safe
9+
from django.utils.html import escape
910
from . import settings
1011
from .models import CRUDEvent, LoginEvent, RequestEvent
1112
from .admin_helpers import prettify_json, EasyAuditModelAdmin
@@ -29,13 +30,14 @@ def object_repr_link(self, obj):
2930
html = obj.object_repr
3031
else:
3132
try:
33+
escaped_obj_repr = escape(obj.object_repr)
3234
url = reverse("admin:%s_%s_change" % (
3335
obj.content_type.app_label,
3436
obj.content_type.model,
3537
), args=(obj.object_id,))
36-
html = '<a href="%s">%s</a>' % (url, obj.object_repr)
38+
html = '<a href="%s">%s</a>' % (url, escaped_obj_repr)
3739
except:
38-
html = obj.object_repr
40+
html = escape(obj.object_repr)
3941
return mark_safe(html)
4042

4143
object_repr_link.short_description = 'object repr'

easyaudit/admin_helpers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@
1313
from django.contrib import messages
1414
from django.conf.urls import url
1515
from django.utils.safestring import mark_safe
16+
from django.utils.html import escape
1617
from . import settings
1718

1819
import json
1920

20-
2121
def prettify_json(json_string):
2222
"""Given a JSON string, it returns it as a
2323
safe formatted HTML"""
24+
escaped = escape(json_string)
2425
try:
25-
data = json.loads(json_string)
26-
html = '<pre>' + json.dumps(data, sort_keys=True, indent=4) + '</pre>'
26+
data = json.loads(escaped)
27+
# html = '<pre>' + json.dumps(data, sort_keys=True, indent=4) + '</pre>'
28+
html = json.dumps(data, sort_keys=True, indent=4)
2729
except:
28-
html = json_string
29-
return mark_safe(html)
30+
html = escaped
31+
return html
3032

3133

3234
class EasyAuditModelAdmin(admin.ModelAdmin):
@@ -38,13 +40,14 @@ def user_link(self, obj):
3840
return '-'
3941
try:
4042
user_model = get_user_model()
43+
escaped = escape(str(user))
4144
url = reverse("admin:%s_%s_change" % (
4245
user_model._meta.app_label,
4346
user_model._meta.model_name,
4447
), args=(user.id,))
45-
html = '<a href="%s">%s</a>' % (url, str(user))
48+
html = '<a href="%s">%s</a>' % (url, escaped)
4649
except:
47-
html = str(user)
50+
html = escape(str(user))
4851
return mark_safe(html)
4952
user_link.short_description = 'user'
5053

0 commit comments

Comments
 (0)