products/CPSUid

changeset 18:cc4e1748df28

Use lines to store counter criteria to be able to edit them in the ZMI, must remove existing counters
author atchertchian
date Fri, 11 Aug 2006 09:34:16 +0000
parents b0ace3b82a57
children b619c4219090
files CHANGES tests/test_uidcounter.py tests/test_uidgenerator.py uidcounter.py
diffstat 4 files changed, 31 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/CHANGES
     1.2 +++ b/CHANGES
     1.3 @@ -1,6 +1,6 @@
     1.4  Requires:
     1.5  ~~~~~~~~~
     1.6 --
     1.7 +- Deleting existing counters.
     1.8  New features:
     1.9  ~~~~~~~~~~~~~
    1.10  -
    1.11 @@ -9,4 +9,4 @@
    1.12  -
    1.13  New internal features:
    1.14  ~~~~~~~~~~~~~~~~~~~~~~
    1.15 --
    1.16 +- Use lines to store counter criteria to be able to edit them in the ZMI.
     2.1 --- a/tests/test_uidcounter.py
     2.2 +++ b/tests/test_uidcounter.py
     2.3 @@ -38,6 +38,10 @@
     2.4              "source": "CPS",
     2.5              "doument_type": "Common type",
     2.6              }
     2.7 +        self.criteria_lines = (
     2.8 +            "source CPS",
     2.9 +            "doument_type Common type",
    2.10 +            )
    2.11          self.counter = UidCounter("counter", 1, self.criteria)
    2.12  
    2.13      # tests
    2.14 @@ -55,14 +59,14 @@
    2.15          self.assertEqual(counter.getId(), "counter")
    2.16          self.assertEqual(counter.counter_start, 1)
    2.17          self.assertEqual(counter.counter_current, 1)
    2.18 -        self.assertEqual(counter.criteria, criteria)
    2.19 +        self.assertEqual(counter.getCriteria(), criteria)
    2.20  
    2.21      def test_test_case_counter(self):
    2.22          self.assertEqual(self.counter.meta_type, "Uid Counter")
    2.23          self.assertEqual(self.counter.getId(), "counter")
    2.24          self.assertEqual(self.counter.counter_start, 1)
    2.25          self.assertEqual(self.counter.counter_current, 1)
    2.26 -        self.assertEqual(self.counter.criteria, self.criteria)
    2.27 +        self.assertEqual(self.counter.criteria, self.criteria_lines)
    2.28  
    2.29      def test_hit(self):
    2.30          self.assertEqual(self.counter.counter_current, 1)
     3.1 --- a/tests/test_uidgenerator.py
     3.2 +++ b/tests/test_uidgenerator.py
     3.3 @@ -105,11 +105,15 @@
     3.4          criteria = {
     3.5              'source': 'CPS',
     3.6              }
     3.7 +        criteria_lines = (
     3.8 +            'source CPS',
     3.9 +            )
    3.10          counter = self.generator._getCounter(**criteria)
    3.11          self.assertEqual(counter.getId(), 'source-cps')
    3.12          self.assertEqual(counter.counter_start, 0)
    3.13          self.assertEqual(counter.counter_current, 0)
    3.14 -        self.assertEqual(counter.criteria, criteria)
    3.15 +        self.assertEqual(counter.criteria, criteria_lines)
    3.16 +        self.assertEqual(counter.getCriteria(), criteria)
    3.17  
    3.18  
    3.19      def test___createCounter(self):
    3.20 @@ -120,7 +124,7 @@
    3.21          self.assertEqual(counter.getId(), 'source-cps')
    3.22          self.assertEqual(counter.counter_start, 0)
    3.23          self.assertEqual(counter.counter_current, 0)
    3.24 -        self.assertEqual(counter.criteria, criteria)
    3.25 +        self.assertEqual(counter.getCriteria(), criteria)
    3.26  
    3.27  
    3.28  def test_suite():
     4.1 --- a/uidcounter.py
     4.2 +++ b/uidcounter.py
     4.3 @@ -48,7 +48,11 @@
     4.4           'label': 'Counter start value'},
     4.5          {'id': 'counter_current', 'type': 'int', 'mode': 'w',
     4.6           'label': 'Counter current value'},
     4.7 -        {'id': 'criteria', 'type': 'text', 'mode': 'r',
     4.8 +        # one criteria per line, following the format "key value", for
     4.9 +        # instance:
    4.10 +        # portal_type Workspace
    4.11 +        # type CPS
    4.12 +        {'id': 'criteria', 'type': 'lines', 'mode': 'w',
    4.13           'label': 'Criteria mapping'},
    4.14          )
    4.15  
    4.16 @@ -56,13 +60,15 @@
    4.17      # API
    4.18      #
    4.19  
    4.20 -    def __init__(self, id, counter_start, criteria):
    4.21 +    def __init__(self, id, counter_start=0, criteria={}):
    4.22          """Initialization
    4.23          """
    4.24          self.id = id
    4.25          self._setPropValue('counter_start', counter_start)
    4.26          self._setPropValue('counter_current', counter_start)
    4.27 -        self._setPropValue('criteria', criteria)
    4.28 +        criteria_lines = list(['%s %s'%(key, value)
    4.29 +                               for key, value in criteria.items()])
    4.30 +        self._setPropValue('criteria', criteria_lines)
    4.31  
    4.32  
    4.33      security.declarePrivate('hit')
    4.34 @@ -85,8 +91,14 @@
    4.35      def getCriteria(self):
    4.36          """Get the counter criteria
    4.37          """
    4.38 -        return self.criteria
    4.39 -
    4.40 +        criteria_dict = {}
    4.41 +        for mapping in self.criteria:
    4.42 +            sep_index = mapping.find(' ')
    4.43 +            if sep_index != -1:
    4.44 +                key = mapping[:sep_index]
    4.45 +                value = mapping[sep_index+1:]
    4.46 +                criteria_dict[key] = value
    4.47 +        return criteria_dict
    4.48  
    4.49      # avoid conflicts on counter current value
    4.50      def _p_resolveConflict(self, oldState, savedState, newState):