1. Atsushi Odagiri
  2. python-bpmappers-dev

Commits

Shinya Okano  committed 5783dc8

NonKeyListDelegateFieldでafter_filterを使えるように修正

  • Participants
  • Parent commits a8d75c6
  • Branches default

Comments (0)

Files changed (2)

File bpmappers/fields.py

View file
 
 
 class NonKeyListDelegateField(NonKeyDelegateField):
-    def __init__(self, mapper_class, callback=None, filter=None, *args, **kwargs):
+    def __init__(self, mapper_class, callback=None, filter=None, after_filter=None, *args, **kwargs):
         super(NonKeyListDelegateField, self).__init__(mapper_class, callback, *args, **kwargs)
         self._filter = filter
+        self._after_filter = after_filter
 
     def filter(self, value=None):
         if self._filter:
             return self._filter(value)
         return value
 
+    def after_filter(self, value):
+        if self._after_filter:
+            return self._after_filter(value)
+        return value
+
     def as_value(self, mapper, value=[]):
         parsed = []
         # filterは割り込み用
         value = self.filter(value)
         for v in value:
-            parsed.append(super(NonKeyListDelegateField, self).as_value(mapper, self.callback_value(v)))
+            parsed.append(self.after_filter(super(NonKeyListDelegateField, self).as_value(mapper, self.callback_value(v))))
         return parsed

File tests/field_tests.py

View file
         value = self.field.get_value(DummyMapper(None), [{"Spam": "Egg"}])
         self.assertEqual(value, self.filter.returns)
         self.assertTrue(self.filter.called)
+
+
+class NonKeyListDelegateFieldAfterFilterTest(TestCase):
+    "NonKeyListDelegateField.after_filter"
+    def setUp(self):
+        self.after_filter = DummyCallback("Spam")
+        self.field = fields.NonKeyListDelegateField(
+            DummyMapper,
+            after_filter=self.after_filter)
+
+    def test_get_value(self):
+        value = self.field.get_value(
+            DummyMapper(None), [1, 2, 3])
+        self.assertEqual(value, ["Spam", "Spam", "Spam"])
+        self.assertTrue(self.after_filter.called)