@@ -60,7 +60,8 @@ def _get_tree_table(mapper):
6060
6161
6262def mptt_before_insert (mapper , connection , instance ):
63- """ Based on this example https://bitbucket.org/zzzeek/sqlalchemy/src/73095b353124/examples/nested_sets/nested_sets.py?at=master
63+ """ Based on example
64+ https://bitbucket.org/zzzeek/sqlalchemy/src/73095b353124/examples/nested_sets/nested_sets.py?at=master
6465 """
6566 table = _get_tree_table (mapper )
6667 db_pk = instance .get_db_pk ()
@@ -70,7 +71,8 @@ def mptt_before_insert(mapper, connection, instance):
7071 instance .left = 1
7172 instance .right = 2
7273 instance .level = 1
73- tree_id = connection .scalar (select ([func .max (table .c .tree_id ) + 1 ])) or 1
74+ tree_id = connection .scalar (
75+ select ([func .max (table .c .tree_id ) + 1 ])) or 1
7476 instance .tree_id = tree_id
7577 else :
7678 (parent_pos_left ,
@@ -188,7 +190,8 @@ def mptt_before_update(mapper, connection, instance):
188190 left_sibling_parent ,
189191 left_sibling_tree_id ) = current_lvl_nodes [- 1 ]
190192 instance .parent_id = left_sibling_parent
191- left_sibling = {'lft' : left_sibling_left , 'rgt' : left_sibling_right ,
193+ left_sibling = {'lft' : left_sibling_left ,
194+ 'rgt' : left_sibling_right ,
192195 'is_parent' : False }
193196 # if move_before to top level
194197 elif not right_sibling_parent :
@@ -238,7 +241,9 @@ def mptt_before_update(mapper, connection, instance):
238241 ).fetchone ()
239242
240243 # if instance just update w/o move
241- if not left_sibling and str (node_parent_id ) == str (instance .parent_id ) and not mptt_move_inside :
244+ if not left_sibling \
245+ and str (node_parent_id ) == str (instance .parent_id )\
246+ and not mptt_move_inside :
242247 if left_sibling_tree_id is None :
243248 return
244249
@@ -299,7 +304,8 @@ def mptt_before_update(mapper, connection, instance):
299304 )
300305 # if just insert
301306 else :
302- tree_id = connection .scalar (select ([func .max (table .c .tree_id ) + 1 ]))
307+ tree_id = connection .scalar (
308+ select ([func .max (table .c .tree_id ) + 1 ]))
303309
304310 connection .execute (
305311 table .update (table_pk .in_ (subtree ))
0 commit comments