1. Lee McFadden
  2. WebHelpers


pjenvey  committed 2d65c9f

[svn] noop instead of raising a KeyError when there's no cycle or counter to reset

  • Participants
  • Parent commits a02524c
  • Branches trunk

Comments (0)

Files changed (1)

File webhelpers/rails/text.py

View file
  • Ignore whitespace
     Resets the cycle so that it starts from the first element in the array
     the next time it is used.
-    del request_config().environ['railshelpers.cycles'][name]
+    try:
+        del request_config().environ['railshelpers.cycles'][name]
+    except KeyError:
+        pass
 def counter(name='default', start=1, step=1):
     """Return the next cardinal in a sequence.
     Resets the counter so that it starts from the ``start`` cardinal in
     the sequence next time it is used.
-    del request_config().environ['railshelpers.counters'][name]
+    try:
+        del request_config().environ['railshelpers.counters'][name]
+    except KeyError:
+        pass
 def truncate(text, length=30, truncate_string='...'):