Skip to content

Commit

Permalink
Merge d55e466 into 99adc29
Browse files Browse the repository at this point in the history
  • Loading branch information
stop5 committed Nov 10, 2017
2 parents 99adc29 + d55e466 commit 5b709af
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python:
- 2.7

env:
- DJANGO="Django>=2.0a1,<2.1"
- DJANGO="Django>=1.11,<1.12"
- DJANGO="Django>=1.10,<1.11"
- DJANGO="Django>=1.9,<1.10"
Expand All @@ -28,12 +29,17 @@ matrix:
- python: 3.5
env: DJANGO="Django>=1.7,<1.8"

- python: 3.3
env: DJANGO="Django>=2.0a1,<2.1"
- python: 3.3
env: DJANGO="Django>=1.11,<1.12"
- python: 3.3
env: DJANGO="Django>=1.10,<1.11"
- python: 3.3
env: DJANGO="Django>=1.9,<1.10"

- python: 2.7
env: DJANGO="Django>=2.0a1,<2.1"

after_success:
coveralls
5 changes: 4 additions & 1 deletion sitetree/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.conf import settings as django_settings
from django import VERSION as django_version
from django.core.urlresolvers import get_urlconf, get_resolver
try:
from django.urls import get_urlconf, get_resolver
except ImportError:
from django.core.urlresolvers import get_urlconf, get_resolver
from django.utils.translation import ugettext_lazy as _
from django.utils import six
from django.http import HttpResponseRedirect
Expand Down
5 changes: 4 additions & 1 deletion sitetree/management/commands/sitetree_resync_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def handle(self, *apps, **options):
item.save(using=using)
# Copy permissions to M2M field once `item`
# has been saved
item.access_permissions = item.permissions
if hasattr(item.access_permissions, "set"):
item.access_permissions.set(item.permissions)
else:
item.access_permissions = item.permissions

Cache.reset()
4 changes: 2 additions & 2 deletions sitetree/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Migration(migrations.Migration):
('access_perm_type', models.IntegerField(default=1, help_text='<b>Any</b> &mdash; user should have any of chosen permissions. <b>All</b> &mdash; user should have all chosen permissions.', verbose_name='Permissions interpretation', choices=[(1, 'Any'), (2, 'All')])),
('sort_order', models.IntegerField(default=0, help_text='Item position among other site tree items under the same parent.', verbose_name='Sort order', db_index=True)),
('access_permissions', models.ManyToManyField(to='auth.Permission', verbose_name='Permissions granting access', blank=True)),
('parent', models.ForeignKey(related_name='treeitem_parent', blank=True, to='sitetree.TreeItem', help_text='Parent site tree item.', null=True, verbose_name='Parent')),
('tree', models.ForeignKey(related_name='treeitem_tree', verbose_name='Site Tree', to='sitetree.Tree', help_text='Site tree this item belongs to.')),
('parent', models.ForeignKey(related_name='treeitem_parent', on_delete=models.CASCADE, blank=True, to='sitetree.TreeItem', help_text='Parent site tree item.', null=True, verbose_name='Parent')),
('tree', models.ForeignKey(related_name='treeitem_tree', on_delete=models.CASCADE, verbose_name='Site Tree', to='sitetree.Tree', help_text='Site tree this item belongs to.')),
],
options={
'abstract': False,
Expand Down
4 changes: 2 additions & 2 deletions sitetree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TreeItemBase(models.Model):
'<b>Note:</b> Refer to Django "URL dispatcher" documentation (e.g. "Naming URL patterns" part).'),
db_index=True, default=False)
tree = models.ForeignKey(
MODEL_TREE, related_name='%(class)s_tree', verbose_name=_('Site Tree'),
MODEL_TREE, related_name='%(class)s_tree', on_delete=models.CASCADE, verbose_name=_('Site Tree'),
help_text=_('Site tree this item belongs to.'), db_index=True)
hidden = models.BooleanField(
_('Hidden'), help_text=_('Whether to show this item in navigation.'), db_index=True, default=False)
Expand Down Expand Up @@ -118,7 +118,7 @@ class TreeItemBase(models.Model):
# These two are for 'adjacency list' model.
# This is the current approach of tree representation for sitetree.
parent = models.ForeignKey(
'self', related_name='%(class)s_parent', verbose_name=_('Parent'),
'self', related_name='%(class)s_parent', on_delete=models.CASCADE, verbose_name=_('Parent'),
help_text=_('Parent site tree item.'), db_index=True, null=True, blank=True)
sort_order = models.IntegerField(
_('Sort order'),
Expand Down
13 changes: 11 additions & 2 deletions sitetree/sitetreeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,13 @@ def get_tree_current_item(self, tree_alias):
return None

# urlquote is an attempt to support non-ascii in url.
current_url = urlquote(self.current_request.path)
path = self.current_request.path
if type(path) == str:
current_url = urlquote(path.encode("UTF-8"))
elif type(path) in (bytes, bytearray):
current_url = urlquote(path)
else:
current_url = path

for url_item, url in self._items_urls.items():
# Iterate each as this dict may contains "current" items for various trees.
Expand Down Expand Up @@ -851,7 +857,10 @@ def check_access(self, item, context):
:param Context context:
:rtype: bool
"""
authenticated = self.current_request.user.is_authenticated()
if hasattr(self.current_request.user.is_authenticated, "__call__"):
authenticated = self.current_request.user.is_authenticated()
else:
authenticated = self.current_request.user.is_authenticated

if item.access_loggedin and not authenticated:
return False
Expand Down
6 changes: 5 additions & 1 deletion sitetree/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def pytest_configure():

if not pytest.config.pluginmanager.hasplugin('django'):
raise Exception('`pytest-django` package is required to run `%s` tests.' % app_name)
if hasattr(global_settings, "MIDDLEWARE"):
middleware = global_settings.MIDDLEWARE
else:
middleware = global_settings.MIDDLEWARE_CLASSES

configure_kwargs = dict(
INSTALLED_APPS=(
Expand All @@ -28,7 +32,7 @@ def pytest_configure():
'%s.tests' % app_name
),
DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}},
MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES, # Prevents Django 1.7 warning.
MIDDLEWARE_CLASSES=middleware, # Prevents Django 1.7 warning.
ROOT_URLCONF='%s.tests.urls' % app_name,
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skip_missing_interpreters = True

envlist =
py{27,32,33,34}-django{17,18,19,110,111}
py{35,36}-django{18,19,110,111}
py{35,36}-django{18,19,110,111,20}


[testenv]
Expand All @@ -18,3 +18,4 @@ deps =
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
django20: Django>=2.0a1,<2.1

0 comments on commit 5b709af

Please sign in to comment.