diff --git a/CHANGES b/CHANGES index b517019..f1269fe 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +Release 0.4 +----------- +* add css_class attribute + + Release 0.3 ----------- * add ability to order buttons @@ -5,7 +10,6 @@ Release 0.3 Release 0.2 ----------- - * python 3.3, 3.4 compatibility * add ability to customize the upload template * disable button after click to prevent double click @@ -15,5 +19,4 @@ Release 0.2 Release 0.1 ----------- - * Initial release diff --git a/README.rst b/README.rst index 5c98af3..60246e9 100644 --- a/README.rst +++ b/README.rst @@ -36,6 +36,14 @@ Example:: - with `@action()` browser will be redirected to `change view ` +More options:: + + + @link(label='Update', icon="icon-refresh icon-white", permission='model_change", order=-1) + def update_all(self, request): + .... + + *Note* The package contains a ``UploadMixin`` to manage custom file uploads diff --git a/admin_extra_urls/__init__.py b/admin_extra_urls/__init__.py index 2f26b5b..f0cf8a5 100644 --- a/admin_extra_urls/__init__.py +++ b/admin_extra_urls/__init__.py @@ -3,7 +3,7 @@ import os NAME = 'admin-extra-urls' -VERSION = __version__ = (0, 3, 0, 'final', 0) +VERSION = __version__ = (0, 4, 0, 'final', 0) __author__ = 'sax' diff --git a/admin_extra_urls/extras.py b/admin_extra_urls/extras.py index cdbd731..e989def 100644 --- a/admin_extra_urls/extras.py +++ b/admin_extra_urls/extras.py @@ -12,7 +12,7 @@ def labelize(label): return label.replace('_', ' ').strip().title() -def link(path=None, label=None, icon='', permission=None, order=999): +def link(path=None, label=None, icon='', permission=None, css_class="btn btn-success", order=999): """ decorator to mark ModelAdmin method as 'url' links. @@ -26,7 +26,7 @@ def link(path=None, label=None, icon='', permission=None, order=999): """ - def action_decorator(func): + def link_decorator(func): def _inner(self, *args, **kwargs): ret = func(self, *args, **kwargs) if not isinstance(ret, HttpResponse): @@ -38,14 +38,15 @@ def _inner(self, *args, **kwargs): label or labelize(func.__name__), icon, permission, - order) + order, + css_class) return _inner - return action_decorator + return link_decorator -def action(path=None, label=None, icon='', permission=None, order=999): +def action(path=None, label=None, icon='', permission=None, css_class="btn btn-success", order=999): """ decorator to mark ModelAdmin method as 'url' action. @@ -72,7 +73,8 @@ def _inner(self, request, pk): label or labelize(func.__name__), icon, permission, - order) + order, + css_class) return _inner @@ -116,16 +118,16 @@ def wrapper(*args, **kwargs): extras = [] for __, entry in extra_urls.items(): - isdetail, method_name, (path, label, icon, perm_name, order) = entry + isdetail, method_name, (path, label, icon, perm_name, order, css_class) = entry info[2] = method_name if isdetail: self.extra_detail_buttons.append([method_name, label, - icon, perm_name, order]) + icon, perm_name, css_class, order]) uri = r'^%s/(?P.*)/$' % path else: uri = r'^%s/$' % path self.extra_buttons.append([method_name, label, - icon, perm_name, order]) + icon, perm_name, css_class, order]) extras.append(url(uri, wrap(getattr(self, method_name)), diff --git a/admin_extra_urls/templates/admin_extra_urls/change_form.html b/admin_extra_urls/templates/admin_extra_urls/change_form.html index 9ea0204..8e2d7ac 100644 --- a/admin_extra_urls/templates/admin_extra_urls/change_form.html +++ b/admin_extra_urls/templates/admin_extra_urls/change_form.html @@ -4,13 +4,13 @@
{% block object-tools-items %} {{block.super}} - {% for method_name, label, icon, perm in adminform.model_admin.extra_detail_buttons %} + {% for method_name, label, icon, perm, css_class in adminform.model_admin.extra_detail_buttons %} {% has_permission perm as authorized %} {% if authorized %} {%nlless%} - - {% if icon %} {% endif %} + + {% if icon %} {% endif %} {{ label }} {% endnlless %} {% endif %} diff --git a/admin_extra_urls/templates/admin_extra_urls/change_list.html b/admin_extra_urls/templates/admin_extra_urls/change_list.html index e8430b7..a93394c 100644 --- a/admin_extra_urls/templates/admin_extra_urls/change_list.html +++ b/admin_extra_urls/templates/admin_extra_urls/change_list.html @@ -11,12 +11,12 @@ {% endif %} - {% for method_name, label, icon, perm in cl.model_admin.extra_buttons %} + {% for method_name, label, icon, perm, css_class in cl.model_admin.extra_buttons %} {% has_permission perm as authorized %} {% if authorized %} {% spaceless %} - {% if icon %} {% endif %}{{ label }} + {% if icon %} {% endif %}{{ label }} {% endspaceless %} {% endif %}