Permalink
Browse files

add an _autoname_reset flag, which will cause the folder to add a nex…

…t name of autoname_start+1 regardless of any existing maxKey value
  • Loading branch information...
mcdonc committed Mar 28, 2013
1 parent 42a11ec commit 2e1d5c5e741d714090a6f8a6ad738c9434b1cafc
Showing with 21 additions and 3 deletions.
  1. +8 −3 substanced/folder/__init__.py
  2. +13 −0 substanced/folder/tests.py
@@ -754,6 +754,7 @@ class SequentialAutoNamingFolder(Folder, _AutoNamingFolder):
_autoname_length = 7
_autoname_start = -1
+ _autoname_reset = False
def __init__(
self,
@@ -789,10 +790,14 @@ def next_name(self, subobject):
will be the value of this folder's ``autoname_start`` constructor
value.
"""
- try:
- maxkey = self.data.maxKey()
- except ValueError: # empty tree
+ if self._autoname_reset:
maxkey = self._autoname_start
+ self._autoname_reset = False
+ else:
+ try:
+ maxkey = self.data.maxKey()
+ except ValueError: # empty tree
+ maxkey = self._autoname_start
name = self._zfill(int(maxkey) + 1)
return name
View
@@ -938,6 +938,19 @@ def test_next_name_alternate_autoname_start(self):
inst = self._makeOne(autoname_start=0)
self.assertEqual(inst.next_name(None), '1'.zfill(7))
+ def test_next_name_empty_autoname_reset(self):
+ inst = self._makeOne()
+ inst._autoname_reset = True
+ self.assertEqual(inst.next_name(None), '0'.zfill(7))
+ self.assertFalse(inst._autoname_reset)
+
+ def test_next_name_nonempty_autoname_reset(self):
+ ob = DummyModel()
+ inst = self._makeOne({'0000005':ob})
+ inst._autoname_reset = True
+ self.assertEqual(inst.next_name(None), '0'.zfill(7))
+ self.assertFalse(inst._autoname_reset)
+
def test_add_not_intifiable(self):
ob = DummyModel()
inst = self._makeOne()

0 comments on commit 2e1d5c5

Please sign in to comment.