# HG changeset patch # User Sylvain Thénault # Date 1320686213 -3600 # Node ID 8a933961938e798d4304a9de0f7ebc0bff4c6b3a # Parent 6d8eb873256df4383eb1f1188aec89d372ef91ac [tableview] deepcopy of colrenderer was actually broken with py < 2.7 diff -r 6d8eb873256d -r 8a933961938e web/views/tableview.py --- a/web/views/tableview.py Mon Nov 07 18:09:13 2011 +0100 +++ b/web/views/tableview.py Mon Nov 07 18:16:53 2011 +0100 @@ -64,6 +64,8 @@ _ = unicode from warnings import warn +from copy import copy +from types import MethodType from logilab.mtconverter import xml_escape from logilab.common.decorators import cachedproperty @@ -366,6 +368,10 @@ self._cw = view._cw self.colid = colid + def copy(self): + assert self.view is None + return copy(self) + def default_header(self): """Return header for this column if one has not been specified.""" return self._cw._(self.colid) @@ -698,6 +704,23 @@ self.renderfunc = renderfunc self.sortfunc = sortfunc + def copy(self): + assert self.view is None + # copy of attribute referencing a method doesn't work with python < 2.7 + renderfunc = self.__dict__.pop('renderfunc') + sortfunc = self.__dict__.pop('sortfunc') + try: + acopy = copy(self) + for aname, member in[('renderfunc', renderfunc), + ('sortfunc', sortfunc)]: + if isinstance(member, MethodType): + member = MethodType(member.im_func, acopy, acopy.__class__) + setattr(acopy, aname, member) + return acopy + finally: + self.renderfunc = renderfunc + self.sortfunc = sortfunc + def render_cell(self, w, rownum): entity = self.entity(rownum) if entity is None: