[Erp5-report] r35660 rafael - in /erp5/trunk/products/ZSQLCatalog: ./ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed May 26 22:12:31 CEST 2010


Author: rafael
Date: Wed May 26 22:12:29 2010
New Revision: 35660

URL: http://svn.erp5.org?rev=35660&view=rev
Log:
Added 2 utility methods.

 - getFilterDict return the filter dictionary as a dict (Instead a PersistentMapping), this allow devoloper manipulate it using Python Scripts at ZODB.

 - setFilterExpression allows set tales to a single filter, instead use edit to edit all. 

Modified:
    erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
    erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=35660&r1=35659&r2=35660&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py [utf8] Wed May 26 22:12:29 2010
@@ -2456,6 +2456,20 @@
         return None
     return None
 
+  def setFilterExpression(self, method_name, expression):
+    """ Set the Expression for a certain method name. This allow set 
+        expressions by scripts.
+    """
+    if withCMF:
+      if getattr(aq_base(self), 'filter_dict', None) is None:
+        self.filter_dict = PersistentMapping()
+        return None
+      self.filter_dict[method_name]['expression'] = expression
+      if expression:
+        self.filter_dict[method_name]['expression_instance'] = Expression(expression)
+      else:
+        self.filter_dict[method_name]['expression_instance'] = None
+
   def isPortalTypeSelected(self, method_name, portal_type):
     """ Returns true if the portal type is selected for this method.
       XXX deprecated
@@ -2484,6 +2498,25 @@
       except KeyError:
         return []
     return []
+
+  def getFilterDict(self):
+    """
+      Utility Method.
+      Filter Dict is a dictionary and used at Python Scripts, 
+      This method returns a filter dict as a dictionary.
+    """
+    if withCMF:
+      if getattr(aq_base(self), 'filter_dict', None) is None:
+        self.filter_dict = PersistentMapping()
+        return None
+      filter_dict = {}
+      for key in self.filter_dict:
+        # Filter is also a Persistence dict.
+        filter_dict[key] = {}
+        for sub_key in self.filter_dict[key]:
+           filter_dict[key][sub_key] = self.filter_dict[key][sub_key]
+      return filter_dict
+    return None
 
   def getFilterableMethodList(self):
     """

Modified: erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py?rev=35660&r1=35659&r2=35660&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py [utf8] Wed May 26 22:12:29 2010
@@ -72,6 +72,30 @@
     self.assertEquals('python: 1', self._catalog.getExpression('z_dummy_method'))
     self.assertEquals('', self._catalog.getExpression('not_exists'))
 
+  def test_setFilterExpression(self):
+    request = dict(z_dummy_method_box=1, z_dummy_method_expression='python: 1')
+    self._catalog.manage_editFilter(REQUEST=request)
+    expression = self._catalog.getExpressionInstance('z_dummy_method')
+    self._catalog.setFilterExpression('z_dummy_method', 'python: 2')
+    self.assertEquals('python: 2', self._catalog.getExpression('z_dummy_method'))
+    self.assertNotEquals(expression, 
+                         self._catalog.getExpressionInstance('z_dummy_method'))
+    self._catalog.setFilterExpression('z_dummy_method', 'python: 1')
+    self.assertEquals('python: 1', self._catalog.getExpression('z_dummy_method'))
+    self.assertRaises(KeyError, self._catalog.setFilterExpression, 
+                                'not_exists', "python:1")
+    self.assertEquals('', self._catalog.getExpression('not_exists'))
+
+  def test_getFilterDict(self):
+    request = dict(z_dummy_method_box=1, z_dummy_method_expression='python: 1')
+    self._catalog.manage_editFilter(REQUEST=request)
+    filter_dict = self._catalog.getFilterDict()
+    self.assertEquals(self._catalog.filter_dict.keys(), filter_dict.keys())
+    self.assertTrue(isinstance(filter_dict, type({})))
+    self.assertTrue(isinstance(filter_dict['z_dummy_method'], type({})))
+    self.assertEquals(self._catalog.getExpression('z_dummy_method'), 
+                      filter_dict['z_dummy_method']['expression'])
+
   def test_getFilterExpressionInstance(self):
     request = dict(z_dummy_method_box=1, z_dummy_method_expression='python: 1')
     self._catalog.manage_editFilter(REQUEST=request)




More information about the Erp5-report mailing list