Skip to content

Commit 6d0a617

Browse files
committed
Python 2/3 changes.
1 parent 1307704 commit 6d0a617

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

polymorphic_tree/admin/parentadmin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from future.builtins import str, int
12
from django.conf import settings
23
from django.core.urlresolvers import reverse
34
from django.db import transaction
@@ -168,10 +169,10 @@ def api_node_moved_view(self, request):
168169
Update the position of a node, from a API request.
169170
"""
170171
try:
171-
moved_id = long(request.POST['moved_id'])
172-
target_id = long(request.POST['target_id'])
172+
moved_id = int(request.POST['moved_id'])
173+
target_id = int(request.POST['target_id'])
173174
position = request.POST['position']
174-
previous_parent_id = long(request.POST['previous_parent_id']) or None
175+
previous_parent_id = int(request.POST['previous_parent_id']) or None
175176

176177
# Not using .non_polymorphic() so all models are downcasted to the derived model.
177178
# This causes the signal below to be emitted from the proper class as well.

polymorphic_tree/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"""
44
from django.core.exceptions import ValidationError
55
from django.utils.translation import ugettext_lazy as _
6+
from django.utils.six import integer_types
67
from mptt.models import MPTTModel, MPTTModelBase, TreeForeignKey
78
from polymorphic import PolymorphicModel
89
from polymorphic.base import PolymorphicModelBase
910
from polymorphic_tree.managers import PolymorphicMPTTModelManager
10-
11+
from future.utils import with_metaclass
1112

1213
def _get_base_polymorphic_model(ChildModel):
1314
"""
@@ -45,7 +46,7 @@ def clean(self, value, model_instance):
4546
def _validate_parent(self, parent, model_instance):
4647
if not parent:
4748
return
48-
elif isinstance(parent, (int, long)):
49+
elif isinstance(parent, integer_types):
4950
# TODO: Improve this code, it's a bit of a hack now because the base model is not known in the NodeTypePool.
5051
base_model = _get_base_polymorphic_model(model_instance.__class__)
5152

@@ -61,11 +62,10 @@ def _validate_parent(self, parent, model_instance):
6162

6263

6364

64-
class PolymorphicMPTTModel(MPTTModel, PolymorphicModel):
65+
class PolymorphicMPTTModel(with_metaclass(PolymorphicMPTTModelBase, MPTTModel, PolymorphicModel)):
6566
"""
6667
The base class for all nodes; a mapping of an URL to content (e.g. a HTML page, text file, blog, etc..)
6768
"""
68-
__metaclass__ = PolymorphicMPTTModelBase
6969

7070
#: Whether the node type allows to have children.
7171
can_have_children = True

polymorphic_tree/templatetags/polymorphic_tree_admin_tags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from future.builtins import next
12
from django.contrib.admin.views.main import ChangeList
23
from django.contrib.contenttypes.models import ContentType
34
from django.template import Library, Node, TemplateSyntaxError, Variable
@@ -53,7 +54,7 @@ def _render_node(self, context, cl, node):
5354
bits.append(self._render_node(context, cl, child))
5455

5556
columns = self._get_column_repr(cl, node) # list(tuple(name, html), ..)
56-
first_real_column = (col for col in columns if col[0] != 'action_checkbox').next()
57+
first_real_column = next(col for col in columns if col[0] != 'action_checkbox')
5758

5859
context['columns'] = columns
5960
context['other_columns'] = [col for col in columns if col[0] not in ('action_checkbox', first_real_column[0])]

polymorphic_tree/templatetags/stylable_admin_list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
This feature can be activated by simply extending the template stylable/admin/change_list.html
1313
"""
14+
from future.builtins import zip, str
1415
from django.conf import settings
1516
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
1617
from django.core.exceptions import ObjectDoesNotExist
@@ -83,7 +84,7 @@ def stylable_result_headers(cl):
8384
else:
8485
header['class_attrib'] = mark_safe(' class="col-%s"' % field_name)
8586

86-
if header.has_key('url_primary') and not header.has_key('url'):
87+
if 'url_primary' in header and 'url' not in header:
8788
header['url'] = header['url_primary'] # Django 1.3 template compatibility.
8889

8990
yield header

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ def find_version(*parts):
3939
'django-polymorphic>=0.4.2',
4040
'django-mptt>=0.5.1',
4141
'django-tag-parser>=1.0.0',
42+
'future>=0.12.2',
4243
],
4344
requires=[
44-
'Django (>=1.3)', # Using staticfiles
45+
'Django (>=1.4)', # Using staticfiles
4546
],
4647
description="A polymorphic mptt structure to display content in a tree.",
4748
long_description=read('README.rst'),
@@ -66,6 +67,7 @@ def find_version(*parts):
6667
'Programming Language :: Python',
6768
'Programming Language :: Python :: 2.6',
6869
'Programming Language :: Python :: 2.7',
70+
'Programming Language :: Python :: 3.3',
6971
'Topic :: Internet :: WWW/HTTP',
7072
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
7173
'Topic :: Software Development :: Libraries :: Python Modules',

0 commit comments

Comments
 (0)