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/1.7'
Browse files Browse the repository at this point in the history
* release/1.7:
  bump version 1.7
  open 1.7
  fixes django 2.0 support
  update README
  • Loading branch information
saxix committed Jan 17, 2018
2 parents bf36eea + 11ddf25 commit 22188e2
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 82 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
- DJANGO=1.9
- DJANGO=1.10
- DJANGO=1.11
- DJANGO=2.0


matrix:
Expand All @@ -27,17 +28,18 @@ matrix:
env: DJANGO=1.9
- python: 3.6
env: DJANGO=1.10
- python: 3.6
env: DJANGO=1.11

sudo: false

install:
- pip install tox-travis
- pip install "coverage<=4.0" "coveralls>=0.5" codecov
- pip install "coverage<=4.0" codecov

script:
- tox -e "py${TRAVIS_PYTHON_VERSION//.}-d${DJANGO//.}"

after_success:
- coverage combine
- coveralls
- codecov
7 changes: 6 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
Release 1.7
-----------
* removed deprecated `has_permission`
* add support django 2.0


Release 1.6
-----------
* dropped support for django 1.8
* `action()` default behaviour do not display button if in `add` mode
* all `**kwargs` passed to action() will be passed to decorated method
* deprecated `has_permission` templatetag
* deprecated `has_permission` templatetag


Release 1.5
Expand Down
59 changes: 23 additions & 36 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,42 +51,29 @@ How to use it
You don't need to return a HttpResponse. The default behavior is:

- with `link()` browser will be redirected to ``changelist_view``

- with `action()` browser will be redirected to ``change_view``


`link()` / action() options
---------------------------

`path=None`

path url path for the action. will be the url where the button will point to.

label=`None`

label for the button. by default the "labelized" function name

`icon=''`

icon for the button

`permission=None`

permission required to use the button. can be a callable qith the current object as argument.

`css_class="btn btn-success"`

extra css classes to use for the button

`order=999`

in case of multiple button the order to use


`visible=lambda o: o and o.pk`

callable or bool. By default do not display the button if in `add` mode
- with `link()` button is displayed in the 'list' view and the browser will be redirected to ``changelist_view``

- with `action()` button is displayed in the 'update' view and the browser will be redirected to ``change_view``


link() / action() options
-------------------------

+------------+----------------------+----------------------------------------------------------------------------------------+
| path | None | path url path for the action. will be the url where the button will point to. |
+------------+----------------------+----------------------------------------------------------------------------------------+
| label | None | label for the button. by default the "labelized" function name |
+------------+----------------------+----------------------------------------------------------------------------------------+
| icon | '' | icon for the button |
+------------+----------------------+----------------------------------------------------------------------------------------+
| permission | None | permission required to use the button. can be a callable (current object as argument). |
+------------+----------------------+----------------------------------------------------------------------------------------+
| css_class | "btn btn-success" | extra css classes to use for the button |
+------------+----------------------+----------------------------------------------------------------------------------------+
| order | 999 | in case of multiple button the order to use |
+------------+----------------------+----------------------------------------------------------------------------------------+
| visible | lambda o: o and o.pk | callable or bool. By default do not display the button if in `add` mode |
+-----------------------------------+----------------------------------------------------------------------------------------+


*Note*
Expand Down
2 changes: 1 addition & 1 deletion src/admin_extra_urls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

NAME = 'admin-extra-urls'
VERSION = __version__ = (1, 6, 0, 'final', 0)
VERSION = __version__ = (1, 7, 0, 'final', 0)
__author__ = 'sax'


Expand Down
7 changes: 6 additions & 1 deletion src/admin_extra_urls/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
from django.conf.urls import url
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse

from django.http import HttpResponse, HttpResponseRedirect

try:
from django.urls import reverse # django 2.0
except ImportError:
from django.core.urlresolvers import reverse


def labelize(label):
return label.replace('_', ' ').strip().title()
Expand Down
2 changes: 1 addition & 1 deletion src/admin_extra_urls/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from django.contrib import messages

from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse
from .extras import reverse

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load extra_urls i18n admin_static admin_list admin_urls %}

{% for method_name,urlattrs in adminform.model_admin.extra_detail_buttons %}
{% has_permission options.perm as authorized %}
{% if authorized and options.visible%}
{% nlless %}
<li>{% if original.pk %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{% load extra_urls i18n admin_static admin_list admin_urls %}

{% for method_name,urlattrs in cl.model_admin.extra_buttons %}
{% has_permission options.perm as authorized %}
{% if authorized and options.visible %}
{% if options.authorized and options.visible %}
{% spaceless %}
<li><a id="btn-{{method_name}}" href="{% url cl.opts|admin_urlname:method_name %}{% if is_popup %}?_popup=1{% endif %}"
class="extra-link {{options.css_class}} {{method_name}}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load extra_urls i18n admin_static admin_list admin_urls %}

{% for method_name, urlattrs in adminform.model_admin.extra_detail_buttons %}
{% has_permission options.perm as authorized %}
{% eval_extra_options method_name urlattrs as options %}
{% if options.visible and options.authorized %}
{% nlless %}<li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load extra_urls i18n admin_static admin_list admin_urls %}

{% for method_name,urlattrs in cl.model_admin.extra_buttons %}
{% has_permission urlattrs.perm as authorized %}
{% eval_extra_options method_name urlattrs as options %}
{% if options.visible and options.authorized %}
{% spaceless %}<li>
Expand Down
20 changes: 9 additions & 11 deletions src/admin_extra_urls/templatetags/extra_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@

register = template.Library()


@register.assignment_tag(takes_context=True)
def has_permission(context, perm_name):
warnings.warn(
"`has_permission` has been deprecated in admin-extra-urls 1.6"
" and will be removed. See `eval_extra_options` ",
DeprecationWarning
)
return False


#
# @register.assignment_tag(takes_context=True)
# def has_permission(context, perm_name):
# warnings.warn(
# "`has_permission` has been deprecated in admin-extra-urls 1.6"
# " and will be removed. See `eval_extra_options` ",
# DeprecationWarning
# )
# return False
# if not perm_name:
# return True
# request = context['request']
Expand Down
3 changes: 1 addition & 2 deletions src/admin_extra_urls/upload.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from django.contrib import messages
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.template.response import TemplateResponse

from .extras import ExtraUrlMixin, link
from .extras import ExtraUrlMixin, link, reverse


class UploadMixin(ExtraUrlMixin):
Expand Down
3 changes: 1 addition & 2 deletions tests/demoapp/demo/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.contrib import admin
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from admin_extra_urls.extras import ExtraUrlMixin, link, action
from admin_extra_urls.extras import ExtraUrlMixin, link, action, reverse
from admin_extra_urls.mixins import _confirm_action
from admin_extra_urls.upload import UploadMixin
from .models import DemoModel1, DemoModel2, DemoModel3, DemoModel4
Expand Down
27 changes: 19 additions & 8 deletions tests/demoapp/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,26 @@
'django.contrib.admin',
'admin_extra_urls',
'demo']
import django

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
if django.VERSION[0] == 2 :
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
else:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

xLOGGING = {
'version': 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/demoapp/demo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
admin.autodiscover()

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', admin.site.urls),
] + staticfiles_urlpatterns()
6 changes: 3 additions & 3 deletions tests/test_confirm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import logging
from django.core.urlresolvers import reverse
from admin_extra_urls.extras import reverse

logger = logging.getLogger(__name__)


def test_confirm(app, admin_user):
def test_confirm(django_app, admin_user):
url = reverse('admin:demo_demomodel1_changelist')
res = app.get(url, user=admin_user)
res = django_app.get(url, user=admin_user)
res = res.click('Confirm')
assert str(res.content).find("Confirm action")
res = res.form.submit().follow()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_extra_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@

import pytest
from django.contrib.auth.models import Permission
from django.core.urlresolvers import reverse
from admin_extra_urls.extras import reverse

logger = logging.getLogger(__name__)


def test_link(app, staff_user):
def test_link(django_app, staff_user):
perms = Permission.objects.filter(codename__in=['add_demomodel1', 'change_demomodel1'])
staff_user.user_permissions.add(*perms)
url = reverse('admin:demo_demomodel1_changelist')
res = app.get(url, user=staff_user)
res = django_app.get(url, user=staff_user)
res = res.click('Refresh').follow()
assert str(res.context['messages']._loaded_messages[0].message) == 'refresh called'


def test_link_reverse(app, staff_user):
def test_link_reverse(django_app, staff_user):
perms = Permission.objects.filter(codename__in=['add_demomodel1', 'change_demomodel1'])
staff_user.user_permissions.add(*perms)
url = reverse('admin:demo_demomodel1_refresh')
res = app.get(url, user=staff_user).follow()
res = django_app.get(url, user=staff_user).follow()
assert str(res.context['messages']._loaded_messages[0].message) == 'refresh called'


def test_link_custom_path_reverse(app, admin_user):
def test_link_custom_path_reverse(django_app, admin_user):
url = reverse('admin:demo_demomodel1_custom_path')
assert url == '/admin/demo/demomodel1/a/b/'

Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
# as per https://docs.djangoproject.com/en/1.11/faq/install/#what-python-version-can-i-use-with-django
envlist = d{19,110}-py{27,34,35,py}
d{111}-py{27,34,35,36,py}
envlist = d{19,110,111}-py{27,34,35,py}
d{20}-py{34,35,36}

[pytest]
python_paths=./tests/demoapp/
Expand Down

0 comments on commit 22188e2

Please sign in to comment.