Commit 34b1bfc7 authored by Julien Muchembled's avatar Julien Muchembled

Simplify code of some decorators

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40071 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ea31cff4
......@@ -88,14 +88,11 @@ from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
PICKLE_CLEANERS = {}
class cleaner_for(object):
def __init__(self, classdef):
self.classdef = classdef
def __call__(self, callable):
PICKLE_CLEANERS[self.classdef] = callable
return callable
def cleaner_for(classdef):
def wrapper(func):
PICKLE_CLEANERS[classdef] = func
return func
return wrapper
# BBB: Remove this cleaner when we drop support for Zope 2.8
@cleaner_for(ZopePageTemplate)
......
......@@ -41,6 +41,7 @@ from Products.MailHost.MailHost import MailHost
from email import message_from_string
import backportUnittest
from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.Utils import simple_decorator
from Products.ZSQLCatalog.SQLCatalog import Catalog
class FileUpload(file):
......@@ -316,23 +317,18 @@ def createZServer(log=os.devnull):
hs.close()
# decorators
class reindex(object):
@simple_decorator
def reindex(func):
"""Decorator to commit transaction and flush activities after the method is
called.
"""
def __init__(self, func):
self._func = func
def __get__(self, instance, cls=None):
self._instance = instance
return self
def __call__(self, *args, **kw):
ret = self._func(self._instance, *args, **kw)
def wrapper(self, *args, **kw):
ret = func(self, *args, **kw)
if kw.get('reindex', 1):
transaction.commit()
self._instance.tic()
self.tic()
return ret
return wrapper
# Use this as a method or class decorator to tag it as TODO.
# The test will be skipped:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment