Skip to content

Commit 8464354

Browse files
authored
Merge pull request #19 from openpolis/master
WIP: django-2 compatibility
2 parents d521ede + f86d33e commit 8464354

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ docs/_build/
5757
target/
5858

5959
# IDE/Editor stuff
60-
.idea/*
60+
.idea/*
61+
62+
.DS_Store

django_admin_row_actions/admin.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from django import VERSION
2+
from django import forms
23
from django.conf.urls import url
4+
from django.utils.safestring import mark_safe
35
from django.utils.translation import ugettext_lazy as _
46

57
from six import string_types
@@ -28,9 +30,17 @@ class AdminRowActionsMixin(object):
2830

2931
@property
3032
def media(self):
31-
media = super(AdminRowActionsMixin, self).media
32-
media.add_js(['js/jquery.dropdown.min.js'])
33-
media.add_css({'all': ['css/jquery.dropdown.min.css']})
33+
css = super(AdminRowActionsMixin, self).media._css
34+
css['all'] = css.get('all', [])
35+
css['all'].extend(["css/jquery.dropdown.min.css"])
36+
37+
js = super(AdminRowActionsMixin, self).media._js
38+
js.extend(["js/jquery.dropdown.min.js",])
39+
40+
media = forms.Media(
41+
css=css, js=js
42+
)
43+
3444
return media
3545

3646
def get_list_display(self, request):
@@ -64,7 +74,7 @@ def to_dict(tool_name):
6474

6575
elif isinstance(tool, dict): # A parameter dict
6676
tool['enabled'] = tool.get('enabled', True)
67-
if 'action' in tool: # If 'action' is specified then use our generic url in preference to 'url' value
77+
if 'action' in tool: # If 'action' is specified then use our generic url in preference to 'url' value
6878
if isinstance(tool['action'], tuple):
6979
self._named_row_actions[tool['action'][0]] = tool['action'][1]
7080
tool['url'] = '{}rowactions/{}/'.format(url_prefix, tool['action'][0])
@@ -83,11 +93,15 @@ def _row_actions(self, obj):
8393
items=items,
8494
request=getattr(self, '_request')
8595
).render()
86-
87-
return html
96+
if VERSION < (1, 9):
97+
return html
98+
else:
99+
return mark_safe(html)
88100
return ''
89101
_row_actions.short_description = ''
90-
_row_actions.allow_tags = True
102+
103+
if VERSION < (1, 9):
104+
_row_actions.allow_tags = True
91105

92106
def get_tool_urls(self):
93107

django_admin_row_actions/static/js/jquery.dropdown.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
.data('jq-dropdown-trigger', trigger)
6060
.show();
6161

62-
// Position it
63-
position();
62+
// Position it (TODO: bug)
63+
// position();
6464

6565
// Trigger the show callback
6666
jqDropdown
@@ -131,7 +131,8 @@
131131

132132
$(document).on('click.jq-dropdown', '[data-jq-dropdown]', show);
133133
$(document).on('click.jq-dropdown', hide);
134-
$(window).on('resize', position);
134+
// TODO: bug
135+
// $(window).on('resize', position);
135136

136137
})(jQuery);
137138
})(django.jQuery);

django_admin_row_actions/static/js/jquery.dropdown.min.js

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)