Skip to content

Commit

Permalink
refactor: remove noparent and just leave noop
Browse files Browse the repository at this point in the history
  • Loading branch information
ergo committed Nov 23, 2016
1 parent 1ddb3dd commit 574ad96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion ziggurat_foundations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __nonzero__(self):


noop = NOOP()
noparent = NOOP()


def make_passwordmanager():
Expand Down
4 changes: 2 additions & 2 deletions ziggurat_foundations/models/services/resource_tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import unicode_literals

from ziggurat_foundations import noparent
from ziggurat_foundations import noop

__all__ = ['ResourceTreeService']

Expand Down Expand Up @@ -77,7 +77,7 @@ def path_upper(self, object_id, limit_depth=1000000, db_session=None, *args,
object_id=object_id, limit_depth=limit_depth, db_session=db_session,
*args, **kwargs)

def move_to_position(self, resource_id, to_position, new_parent_id=noparent,
def move_to_position(self, resource_id, to_position, new_parent_id=noop,
db_session=None, *args, **kwargs):
"""
Moves node to new location in the tree
Expand Down
14 changes: 7 additions & 7 deletions ziggurat_foundations/models/services/resource_tree_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict

import sqlalchemy as sa
from ziggurat_foundations import noparent
from ziggurat_foundations import noop
from ziggurat_foundations.exc import (
ZigguratResourceTreeMissingException,
ZigguratResourceTreePathException,
Expand Down Expand Up @@ -171,7 +171,7 @@ def path_upper(cls, object_id, limit_depth=1000000, db_session=None, *args,

@classmethod
def move_to_position(cls, resource_id, to_position,
new_parent_id=noparent, db_session=None, *args,
new_parent_id=noop, db_session=None, *args,
**kwargs):
"""
Moves node to new location in the tree
Expand All @@ -194,15 +194,15 @@ def move_to_position(cls, resource_id, to_position,

# reset if parent is same as old
if new_parent_id == resource.parent_id:
new_parent_id = noparent
new_parent_id = noop

if new_parent_id is not noparent:
if new_parent_id is not noop:
cls.check_node_parent(resource_id, new_parent_id,
db_session=db_session)
else:
same_branch = True

if new_parent_id is noparent:
if new_parent_id is noop:
# it is not guaranteed that parent exists
parent_id = resource.parent_id if resource else None
else:
Expand All @@ -212,7 +212,7 @@ def move_to_position(cls, resource_id, to_position,
parent_id, to_position, on_same_branch=same_branch,
db_session=db_session)
# move on same branch
if new_parent_id is noparent:
if new_parent_id is noop:
order_range = list(sorted((resource.ordering, to_position)))
move_down = resource.ordering > to_position

Expand Down Expand Up @@ -361,7 +361,7 @@ def check_node_position(
:return:
"""
db_session = get_db_session(db_session)
if position < 1:
if not position or position < 1:
raise ZigguratResourceOutOfBoundaryException(
'Position is lower than {}', value=1)
item_count = cls.count_children(parent_id, db_session=db_session)
Expand Down

0 comments on commit 574ad96

Please sign in to comment.