Skip to content

Commit

Permalink
Merge branch 'release/1.5.5'
Browse files Browse the repository at this point in the history
* release/1.5.5:
  bump version
  updates
  • Loading branch information
saxix committed Oct 19, 2022
2 parents 3cb7200 + 95d65dd commit 33eee4d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[bumpversion]
current_version = 1.5.4
current_version = 1.5.5
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize = {major}.{minor}.{patch}
commit = True
commit = False
tag = False
allow_dirty = True

Expand Down
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.5.5
-----
* minor refactoring of get_urls()


1.5.4
-----
* allow overwrite visible inside handler
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def read(*parts):
'wheel',
]
dev_require = ['autopep8',
'bump2version',
'check-manifest',
'django',
'pip-tools',
Expand Down
2 changes: 1 addition & 1 deletion src/admin_extra_buttons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NAME = 'django-admin-extra-buttons'
VERSION = __version__ = '1.5.4'
VERSION = __version__ = '1.5.5'
__author__ = 'sax'
8 changes: 6 additions & 2 deletions src/admin_extra_buttons/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def enabled(self):
def model_admin(self):
return self.handler.model_admin

@property
def admin_site(self):
return self.handler.model_admin.admin_site

@property
def visible(self):
if not self.context: # pragma: no cover
Expand Down Expand Up @@ -132,9 +136,9 @@ def get_url(self, context):
detail = len(self.handler.sig.parameters) > self.default_change_form_arguments
try:
if self.change_form and self.original and detail:
url_ = reverse(f'admin:{self.handler.url_name}', args=[self.original.pk])
url_ = reverse(f'{self.admin_site.name}:{self.handler.url_name}', args=[self.original.pk])
elif self.change_list:
url_ = reverse(f'admin:{self.handler.url_name}')
url_ = reverse(f'{self.admin_site.name}:{self.handler.url_name}')
else:
return None
filters = get_preserved_filters(self.request)
Expand Down
10 changes: 7 additions & 3 deletions src/admin_extra_buttons/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ def get_common_context(self, request, pk=None, **kwargs):
context['original'] = self.object
return context

def get_urls(self):
def get_extra_urls(self) -> list:
self.extra_button_handlers = {}
handlers = {}
extra_urls = []
opts = self.model._meta
original = super().get_urls()
for cls in inspect.getmro(self.__class__):
for method_name, method in cls.__dict__.items():
if callable(method) and isinstance(method, BaseExtraHandler):
Expand All @@ -145,7 +144,12 @@ def get_urls(self):
name=handler.url_name))
if hasattr(handler, 'button_class'):
self.extra_button_handlers[handler.func.__name__] = handler
return extra_urls + original
return extra_urls

def get_urls(self):
urls = self.get_extra_urls()
urls.extend(super().get_urls())
return urls

def get_changeform_buttons(self, context):
return [h for h in self.extra_button_handlers.values() if h.change_form in [True, None]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
{% for button in buttons %}
{% if button.can_render and button.change_form %}
{{ button }}
{# {% include "admin_extra_buttons/includes/button.html" with button=button %}#}
{% endif %}
{% endfor %}

0 comments on commit 33eee4d

Please sign in to comment.