Skip to content

Commit 50a6bf0

Browse files
committed
Merge branch 'release/1.4.2'
the commit.
2 parents 4d9aef9 + 45840cf commit 50a6bf0

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.3.0
2+
current_version = 1.4.0
33
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
44
serialize = {major}.{minor}.{patch}
55
commit = True

CHANGES

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
1.4.2
2+
-----
3+
* catch OSError when checking decorator
4+
5+
6+
1.4
7+
-----
8+
* add support for @decorators
9+
10+
111
1.3.1
212
-----
313
* uses __str__ instead of __repr__ (DjangoDebugToolbar issue)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ from admin_extra_buttons.api import ExtraButtonsMixin, button, confirm_action, l
4444
from admin_extra_buttons.utils import HttpResponseRedirectToReferrer
4545
from django.http import HttpResponse, JsonResponse
4646
from django.contrib import admin
47+
from django.views.decorators.clickjacking import xframe_options_sameorigin
48+
from django.views.decorators.csrf import csrf_exempt
4749

4850
class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
4951

@@ -79,6 +81,13 @@ class MyModelModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
7981
def api4(self, request):
8082
return HttpResponse("Basic Authentication allowed")
8183

84+
@view(decorators=[csrf_exempt, xframe_options_sameorigin])
85+
def preview(self, request):
86+
if request.method == "POST":
87+
return HttpResponse("POST")
88+
return HttpResponse("GET")
89+
90+
8291
```
8392

8493
#### Project Links
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
default_app_config = 'admin_extra_buttons.apps.Config'
22

33
NAME = 'django-admin-extra-buttons'
4-
VERSION = __version__ = '1.3.0'
4+
VERSION = __version__ = '1.4.2'
55
__author__ = 'sax'

src/admin_extra_buttons/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, func, **kwargs):
1414
self.func._handler = self
1515
self.config = kwargs
1616
self.model_admin = kwargs.get('model_admin', None)
17-
17+
self.decorators = kwargs.get('decorators', [])
1818
self.login_required = kwargs.get('login_required', True)
1919
self._pattern = kwargs.get('pattern', None)
2020
self.permission = kwargs.get('permission')

src/admin_extra_buttons/mixins.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.template.response import TemplateResponse
1212
from django.urls import path, reverse
1313

14-
from .handlers import BaseExtraHandler
14+
from .handlers import BaseExtraHandler, ViewHandler
1515

1616
logger = logging.getLogger(__name__)
1717

@@ -90,7 +90,7 @@ def check(cls, **kwargs):
9090
try:
9191
from admin_extra_buttons.utils import check_decorator_errors
9292
errors.extend(check_decorator_errors(cls))
93-
except (OperationalError, ProgrammingError): # pragma: no cover
93+
except (OSError, OperationalError, ProgrammingError): # pragma: no cover
9494
pass
9595
return errors
9696

@@ -133,11 +133,15 @@ def get_urls(self):
133133
if callable(method) and isinstance(method, BaseExtraHandler):
134134
handlers[method_name] = method.get_instance(self)
135135

136+
handler: ViewHandler
136137
for handler in handlers.values():
137138
handler.url_name = f'{opts.app_label}_{opts.model_name}_{handler.func.__name__}'
138139
if handler.url_pattern:
140+
f = partial(getattr(self, handler.func.__name__), self)
141+
for deco in handler.decorators[::-1]:
142+
f = deco(f)
139143
extra_urls.append(path(handler.url_pattern,
140-
partial(getattr(self, handler.func.__name__), self),
144+
f,
141145
name=handler.url_name))
142146
if hasattr(handler, 'button_class'):
143147
self.extra_button_handlers[handler.func.__name__] = handler
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends "admin/change_list.html" %}{% load extra_buttons %}
22
{% block object-tools-items %}
3-
{% for n in cl.model_admin.names %}<div>{{ n }}</div>{% endfor %}
3+
{# {% for n in cl.model_admin.names %}<div>{{ n }}</div>{% endfor %}#}
44
{{ block.super }}
55
{% include "admin_extra_buttons/includes/change_list_buttons.html" %}
66
{% endblock %}

src/admin_extra_buttons/templates/admin_extra_buttons/includes/change_form_buttons.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{% load extra_buttons i18n static admin_list admin_urls %}
2-
{{ extra_buttons }}
32
{% get_changeform_buttons adminform.model_admin as buttons %}
43
{% for button in buttons %}
54
{% if button.can_render and button.change_form %}

0 commit comments

Comments
 (0)