Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
* release/0.4:
  bump 0.4
  add css_class attribute. useful to customise button layout
  add css_class attribute. useful to customise button layout
  open 0.4
  • Loading branch information
saxix committed Feb 5, 2015
2 parents d93b227 + 5b12f96 commit 2ff52fd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
7 changes: 5 additions & 2 deletions CHANGES
@@ -1,11 +1,15 @@
Release 0.4
-----------
* add css_class attribute


Release 0.3
-----------
* add ability to order buttons


Release 0.2
-----------

* python 3.3, 3.4 compatibility
* add ability to customize the upload template
* disable button after click to prevent double click
Expand All @@ -15,5 +19,4 @@ Release 0.2

Release 0.1
-----------

* Initial release
8 changes: 8 additions & 0 deletions README.rst
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion admin_extra_urls/__init__.py
Expand Up @@ -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'


Expand Down
20 changes: 11 additions & 9 deletions admin_extra_urls/extras.py
Expand Up @@ -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.
Expand All @@ -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):
Expand All @@ -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.
Expand All @@ -72,7 +73,8 @@ def _inner(self, request, pk):
label or labelize(func.__name__),
icon,
permission,
order)
order,
css_class)

return _inner

Expand Down Expand Up @@ -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<pk>.*)/$' % 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)),
Expand Down
8 changes: 4 additions & 4 deletions admin_extra_urls/templates/admin_extra_urls/change_form.html
Expand Up @@ -4,13 +4,13 @@
<div class="object-tools">
{% 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%}
<a href="{% url opts|admin_urlname:method_name original.pk %}{% if is_popup %}?_popup=1{% endif %}"
class="btn btn-success">
{% if icon %}<i class="{{ icon }} icon-white"></i>&nbsp;{% endif %}
<a id="btn-{{method_name}}" href="{% url opts|admin_urlname:method_name original.pk %}{% if is_popup %}?_popup=1{% endif %}"
class="extra-link {{css_class}} {{method_name}}">
{% if icon %}<i class="{{ icon }}"></i>&nbsp;{% endif %}
{{ label }}</a>
{% endnlless %}
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions admin_extra_urls/templates/admin_extra_urls/change_list.html
Expand Up @@ -11,12 +11,12 @@
</a>
{% 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 %}
<a href="{% url cl.opts|admin_urlname:method_name %}{% if is_popup %}?_popup=1{% endif %}"
class="btn btn-success">{% if icon %}<i class="{{ icon }} icon-white"></i>&nbsp;{% endif %}{{ label }}
<a id="btn-{{method_name}}" href="{% url cl.opts|admin_urlname:method_name %}{% if is_popup %}?_popup=1{% endif %}"
class="extra-link {{css_class}} {{method_name}}">{% if icon %}<i class="{{ icon }} icon-white"></i>&nbsp;{% endif %}{{ label }}
</a>
{% endspaceless %}
{% endif %}
Expand Down

0 comments on commit 2ff52fd

Please sign in to comment.