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.3'
Browse files Browse the repository at this point in the history
* release/1.3:
  update CHANGES
  add migrations of demo application
  fixes tox config
  fixes wrong PermissionDenied import
  fixes template check permissio issue
  • Loading branch information
saxix committed Aug 23, 2016
2 parents d08c1b8 + 18c4268 commit 4b4f4c2
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 22 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ language: python
sudo: false

env:
- TESTENV=py27-d17
- TESTENV=py27-d18
- TESTENV=py27-d19
- TESTENV=py27-d110

- TESTENV=py33-d17
- TESTENV=py33-d18

- TESTENV=py34-d17
- TESTENV=py34-d18
- TESTENV=py34-d19
- TESTENV=py34-d110

# - TESTENV=py35-d16
# - TESTENV=py35-d17
# - TESTENV=py35-d18
# - TESTENV=py35-d19
- TESTENV=py35-d18
- TESTENV=py35-d19
- TESTENV=py35-d110

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

script:
- tox -e $TESTENV -- py.test tests --cov=admin_extra_urls --cov-report=xml --cov-config=tests/.coveragerc
- tox -e $TESTENV

after_success:
- coverage combine
Expand Down
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Release 1.3
-----------
* fixes template check permissio issue

Release 1.2
-----------
* check permission before run action/link
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, 2, 0, 'final', 0)
VERSION = __version__ = (1, 3, 0, 'final', 0)
__author__ = 'sax'


Expand Down
14 changes: 14 additions & 0 deletions src/admin_extra_urls/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def labelize(label):
class ExtraUrlConfigException(RuntimeError):
pass


IS_GRAPPELLI_INSTALLED = 'grappelli' in settings.INSTALLED_APPS

opts = namedtuple('UrlOptions', 'path,label,icon,perm,order,css_class,visible')
Expand All @@ -40,6 +41,9 @@ def link(path=None, label=None, icon='', permission=None,
:param required permission to run the action
"""
if callable(permission):
permission = encapsulate(permission)


def link_decorator(func):
def _inner(self, *args, **kwargs):
Expand Down Expand Up @@ -83,6 +87,9 @@ def action(path=None, label=None, icon='', permission=None,
"""

if callable(permission):
permission = encapsulate(permission)

def action_decorator(func):
def _inner(self, request, pk):
obj = self.model.objects.get(pk=pk)
Expand Down Expand Up @@ -117,6 +124,13 @@ def _inner(self, request, pk):
return action_decorator


def encapsulate(func):
def wrapper():
return func

return wrapper


class ExtraUrlMixin(object):
"""
Allow to add new 'url' to the standard ModelAdmin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% 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 %}
{% has_permission urlattrs as authorized %}
{% if authorized and urlattrs.visible %}
{% spaceless %}<li>
<a id="btn-{{method_name}}" href="{% url cl.opts|admin_urlname:method_name %}{% if is_popup %}?_popup=1{% endif %}"
Expand Down
10 changes: 9 additions & 1 deletion src/admin_extra_urls/templatetags/extra_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django import template
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
from django.template import Node, TemplateSyntaxError

Expand All @@ -14,7 +15,14 @@ def has_permission(context, perm_name):
if not perm_name:
return True
request = context['request']
return request.user.has_perm(perm_name)
user = request.user
if callable(perm_name):
try:
return perm_name(request, context.get('original', None))
except PermissionDenied:
return False
else:
return user.has_perm(perm_name)


class NewlinelessNode(template.Node):
Expand Down
37 changes: 37 additions & 0 deletions tests/demoapp/demo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-22 09:47
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='DemoModel1',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='DemoModel2',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='DemoModel3',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
]
Empty file.
5 changes: 4 additions & 1 deletion tests/demoapp/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': ['django.contrib.messages.context_processors.messages']
'context_processors': ['django.contrib.messages.context_processors.messages',
'django.contrib.auth.context_processors.auth',
"django.template.context_processors.request",
]
},
},
]
3 changes: 3 additions & 0 deletions tests/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import sys

if __name__ == '__main__':
here = os.path.dirname(__file__)

sys.path.append(os.path.join(here, 'demoapp'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings')

from django.core.management import execute_from_command_line
Expand Down
23 changes: 13 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[tox]
envlist = {py27}-{d17,d18,d19,dtrunk}
{py33}-{d17,d18}
{py34,py35}-{d18,d19,dtrunk}
envlist = {py27}-{d18,d19,d110,dtrunk}
{py33}-{d18}
{py34}-{d18,d19,d110}
{py35}-{d18,d19,d110,dtrunk}

[pytest]
python_paths=./tests/demoapp/
Expand Down Expand Up @@ -34,7 +35,8 @@ deps=
d17: django>=1.7,<1.8
d18: django>=1.8,<1.9
d19: django>=1.9,<1.10
dtrunk: django>=1.10.dev,<1.11
d110: django>=1.10,<1.11
dtrunk: django>=1.11.dev,<1.12
coverage: django

commands =
Expand All @@ -53,20 +55,21 @@ ignore_outcome = True

[testenv:py35-d18]
commands =
{posargs: py.test tests --cov=admin_extra_urls --cov-report=xml \
--cov-config=tests/.coveragerc --create-db --assert=plain}
{posargs: py.test tests --cov=admin_extra_urls --cov-report=xml --cov-config=tests/.coveragerc --create-db --assert=plain}

[testenv:py35-d19]
commands =
{posargs: py.test tests --cov=admin_extra_urls --cov-report=xml \
--cov-config=tests/.coveragerc --create-db --assert=plain}
{posargs: py.test tests/ --cov=admin_extra_urls --cov-report=xml --cov-config=tests/.coveragerc --create-db --assert=plain}

[testenv:py35-d110]
commands =
{posargs: py.test tests --cov=admin_extra_urls --cov-report=xml --cov-config=tests/.coveragerc --create-db --assert=plain}


[testenv:py35-dtrunk]
pip_pre = True
ignore_outcome = True
commands =
{posargs: py.test tests --cov=admin_extra_urls --cov-report=xml \
--cov-config=tests/.coveragerc --create-db --assert=plain}
{posargs: py.test tests --cov=admin_extra_urls --cov-report=xml --cov-config=tests/.coveragerc --create-db --assert=plain}


0 comments on commit 4b4f4c2

Please sign in to comment.