Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
PortalTransforms.Transform.Transform Class Reference
Inheritance diagram for PortalTransforms.Transform.Transform:
Inheritance graph
[legend]
Collaboration diagram for PortalTransforms.Transform.Transform:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __setstate__
def manage_beforeDelete
def get_documentation
def convert
def name
def get_parameters
def get_parameter_value
def get_parameter_infos
def set_parameters
def reload
def preprocess_param

Public Attributes

 id
 module
 inputs
 output
 output_encoding
 title

Static Public Attributes

string meta_type = 'Transform'
tuple meta_types = all_meta_types()
tuple manage_options
tuple manage_main = PageTemplateFile('configureTransform', _www)
tuple manage_reloadTransform = PageTemplateFile('reloadTransform', _www)
tuple tr_widgets = PageTemplateFile('tr_widgets', _www)
tuple security = ClassSecurityInfo()

Private Member Functions

def _tr_init
def _load_transform

Private Attributes

 _config
 _config_metadata
 _v_transform

Static Private Attributes

 __implements__ = itransform
int __allow_access_to_unprotected_subobjects__ = 1

Detailed Description

A transform is an external method with
additional configuration information

Definition at line 65 of file Transform.py.


Constructor & Destructor Documentation

def PortalTransforms.Transform.Transform.__init__ (   self,
  id,
  module,
  transform = None 
)

Definition at line 91 of file Transform.py.

00091 
00092     def __init__(self, id, module, transform=None):
00093         self.id = id
00094         self.module = module
00095         # DM 2004-09-09: 'Transform' instances are stored as
00096         #  part of a module level configuration structure
00097         #  Therefore, they must not contain persistent objects
00098         self._config = UserDict()
00099         self._config.__allow_access_to_unprotected_subobjects__ = 1
00100         self._config_metadata = UserDict()
00101         self._tr_init(1, transform)


Member Function Documentation

__setstate__ is called whenever the instance is loaded
    from the ZODB, like when Zope is restarted.

    We should reload the wrapped transform at this time

Definition at line 102 of file Transform.py.

00102 
00103     def __setstate__(self, state):
00104         """ __setstate__ is called whenever the instance is loaded
00105             from the ZODB, like when Zope is restarted.
00106 
00107             We should reload the wrapped transform at this time
00108         """
00109         Transform.inheritedAttribute('__setstate__')(self, state)
00110         self._tr_init()

Here is the call graph for this function:

Definition at line 146 of file Transform.py.

00146 
00147     def _load_transform(self):
00148         try:
00149             m = import_from_name(self.module)
00150         except ImportError, err:
00151             transform = BrokenTransform(self.id, self.module, err)
00152             msg = "Cannot register transform %s (ImportError), using BrokenTransform: Error\n %s" % (self.id, err)
00153             self.title = 'BROKEN'
00154             log(msg, severity=ERROR)
00155             return transform
00156         if not hasattr(m, 'register'):
00157             msg = 'Invalid transform module %s: no register function defined' % self.module
00158             raise TransformException(msg)
00159         try:
00160             transform = m.register()
00161         except Exception, err:
00162             transform = BrokenTransform(self.id, self.module, err)
00163             msg = "Cannot register transform %s, using BrokenTransform: Error\n %s" % (self.id, err)
00164             self.title = 'BROKEN'
00165             log(msg, severity=ERROR)
00166         else:
00167             self.title = ''
00168         self._v_transform = transform
00169         return transform

Here is the call graph for this function:

Here is the caller graph for this function:

def PortalTransforms.Transform.Transform._tr_init (   self,
  set_conf = 0,
  transform = None 
) [private]
initialize the zope transform by loading the wrapped transform 

Definition at line 111 of file Transform.py.

00111 
00112     def _tr_init(self, set_conf=0, transform=None):
00113         """ initialize the zope transform by loading the wrapped transform """
00114         __traceback_info__ = (self.module, )
00115         if transform is None:
00116             transform = self._load_transform()
00117         else:
00118             self._v_transform = transform
00119         # check this is a valid transform
00120         if not hasattr(transform, '__class__'):
00121             raise TransformException('Invalid transform : transform is not a class')
00122         if not itransform.isImplementedBy(transform):
00123             raise TransformException('Invalid transform : itransform is not implemented by %s' % transform.__class__)
00124         if not hasattr(transform, 'inputs'):
00125             raise TransformException('Invalid transform : missing required "inputs" attribute')
00126         if not hasattr(transform, 'output'):
00127             raise TransformException('Invalid transform : missing required "output" attribute')
00128         # manage configuration
00129         if set_conf and hasattr(transform, 'config'):
00130             conf = dict(transform.config)
00131             self._config.update(conf)
00132             make_config_persistent(self._config)
00133             if hasattr(transform, 'config_metadata'):
00134                 conf = dict(transform.config_metadata)
00135                 self._config_metadata.update(conf)
00136                 make_config_persistent(self._config_metadata)
00137         transform.config = dict(self._config)
00138         make_config_nonpersistent(transform.config)
00139         transform.config_metadata = dict(self._config_metadata)
00140         make_config_nonpersistent(transform.config_metadata)
00141 
00142         self.inputs = transform.inputs
00143         self.output = transform.output
00144         self.output_encoding = getattr(transform, 'output_encoding', None)
00145         return transform

Here is the call graph for this function:

Here is the caller graph for this function:

def PortalTransforms.Transform.Transform.convert (   self,
  args,
  kwargs 
)
return apply the transform and return the result 

Definition at line 186 of file Transform.py.

00186 
00187     def convert(self, *args, **kwargs):
00188         """ return apply the transform and return the result """
00189         if not hasattr(self, '_v_transform'):
00190             self._load_transform()
00191         return self._v_transform.convert(*args, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

return transform documentation 

Definition at line 179 of file Transform.py.

00179 
00180     def get_documentation(self):
00181         """ return transform documentation """
00182         if not hasattr(self, '_v_transform'):
00183             self._load_transform()
00184         return self._v_transform.__doc__

Here is the call graph for this function:

get informations about a parameter

return a tuple (type, label, description [, type specific data])
where type in (string, int, list, dict)
      label and description are two string describing the field
there may be some additional elements specific to the type :
     (key label, value label) for the dict type

Definition at line 222 of file Transform.py.

00222 
00223     def get_parameter_infos(self, key):
00224         """ get informations about a parameter
00225 
00226         return a tuple (type, label, description [, type specific data])
00227         where type in (string, int, list, dict)
00228               label and description are two string describing the field
00229         there may be some additional elements specific to the type :
00230              (key label, value label) for the dict type
00231         """
00232         try:
00233             return tuple(self._config_metadata[key])
00234         except KeyError:
00235             return 'string', '', ''

Here is the caller graph for this function:

get value of a transform's parameter 

Definition at line 207 of file Transform.py.

00207 
00208     def get_parameter_value(self, key):
00209         """ get value of a transform's parameter """
00210         value = self._config[key]
00211         type = self.get_parameter_infos(key)[0]
00212         if type == 'dict':
00213             result = {}
00214             for key, val in value.items():
00215                 result[key] = val
00216         elif type == 'list':
00217             result = list(value)
00218         else:
00219             result = value
00220         return result

Here is the call graph for this function:

Here is the caller graph for this function:

get transform's parameters names 

Definition at line 198 of file Transform.py.

00198 
00199     def get_parameters(self):
00200         """ get transform's parameters names """
00201         if not hasattr(self, '_v_transform'):
00202             self._load_transform()
00203         keys = self._v_transform.config.keys()
00204         keys.sort()
00205         return keys

Here is the call graph for this function:

Here is the caller graph for this function:

def PortalTransforms.Transform.Transform.manage_beforeDelete (   self,
  item,
  container 
)

Definition at line 171 of file Transform.py.

00171 
00172     def manage_beforeDelete(self, item, container):
00173         SimpleItem.manage_beforeDelete(self, item, container)
00174         if self is item:
00175             # unregister self from catalog on deletion
00176             tr_tool = getToolByName(self, 'portal_transforms')
00177             tr_tool._unmapTransform(self)

Here is the call graph for this function:

return the name of the transform instance

Definition at line 193 of file Transform.py.

00193 
00194     def name(self):
00195         """return the name of the transform instance"""
00196         return self.id

Here is the caller graph for this function:

preprocess param fetched from an http post to handle optional dictionary

Definition at line 275 of file Transform.py.

00275 
00276     def preprocess_param(self, kwargs):
00277         """ preprocess param fetched from an http post to handle optional dictionary
00278         """
00279         for param in self.get_parameters():
00280             if self.get_parameter_infos(param)[0] == 'dict':
00281                 try:
00282                     keys = kwargs[param + '_key']
00283                     del kwargs[param + '_key']
00284                 except:
00285                     keys = ()
00286                 try:
00287                     values = kwargs[param + '_value']
00288                     del kwargs[param + '_value']
00289                 except:
00290                     values = ()
00291                 kwargs[param] = dict = {}
00292                 for key, value in zip(keys, values):
00293                     key = key.strip()
00294                     if key:
00295                         value = value.strip()
00296                         if value:
00297                             dict[key] = value
00298 
00299 InitializeClass(Transform)
00300 

Here is the call graph for this function:

Here is the caller graph for this function:

reload the module where the transformation class is defined 

Definition at line 268 of file Transform.py.

00268 
00269     def reload(self):
00270         """ reload the module where the transformation class is defined """
00271         log('Reloading transform %s' % self.module)
00272         m = import_from_name(self.module)
00273         reload(m)
00274         self._tr_init()

Here is the call graph for this function:

Here is the caller graph for this function:

def PortalTransforms.Transform.Transform.set_parameters (   self,
  REQUEST = None,
  kwargs 
)
set transform's parameters 

Definition at line 237 of file Transform.py.

00237 
00238     def set_parameters(self, REQUEST=None, **kwargs):
00239         """ set transform's parameters """
00240         if not kwargs:
00241             kwargs = REQUEST.form
00242         self.preprocess_param(kwargs)
00243         for param, value in kwargs.items():
00244             try:
00245                 self.get_parameter_value(param)
00246             except KeyError:
00247                 log('Warning: ignored parameter %r' % param)
00248                 continue
00249             meta = self.get_parameter_infos(param)
00250             self._config[param] = VALIDATORS[meta[0]](value)
00251 
00252         tr_tool = getToolByName(self, 'portal_transforms')
00253         # need to remap transform if necessary (i.e. configurable inputs / output)
00254         if kwargs.has_key('inputs') or kwargs.has_key('output'):
00255             tr_tool._unmapTransform(self)
00256             if not hasattr(self, '_v_transform'):
00257                 self._load_transform()
00258             self.inputs = kwargs.get('inputs', self._v_transform.inputs)
00259             self.output = kwargs.get('output', self._v_transform.output)
00260             tr_tool._mapTransform(self)
00261         # track output encoding
00262         if kwargs.has_key('output_encoding'):
00263             self.output_encoding = kwargs['output_encoding']
00264         if REQUEST is not None:
00265             REQUEST['RESPONSE'].redirect(tr_tool.absolute_url()+'/manage_main')
00266 

Here is the call graph for this function:


Member Data Documentation

Definition at line 89 of file Transform.py.

Definition at line 70 of file Transform.py.

Definition at line 97 of file Transform.py.

Definition at line 99 of file Transform.py.

Definition at line 117 of file Transform.py.

Definition at line 92 of file Transform.py.

Definition at line 141 of file Transform.py.

tuple PortalTransforms.Transform.Transform.manage_main = PageTemplateFile('configureTransform', _www) [static]

Definition at line 84 of file Transform.py.

Initial value:
(
                      ({'label':'Configure',
                       'action':'manage_main'},
                       {'label':'Reload',
                       'action':'manage_reloadTransform'},) +
                      SimpleItem.manage_options
                      )

Definition at line 76 of file Transform.py.

tuple PortalTransforms.Transform.Transform.manage_reloadTransform = PageTemplateFile('reloadTransform', _www) [static]

Definition at line 85 of file Transform.py.

Definition at line 72 of file Transform.py.

tuple PortalTransforms.Transform.Transform.meta_types = all_meta_types() [static]

Definition at line 74 of file Transform.py.

Definition at line 93 of file Transform.py.

Definition at line 142 of file Transform.py.

Definition at line 143 of file Transform.py.

tuple PortalTransforms.Transform.Transform.security = ClassSecurityInfo() [static]

Definition at line 88 of file Transform.py.

Definition at line 152 of file Transform.py.

tuple PortalTransforms.Transform.Transform.tr_widgets = PageTemplateFile('tr_widgets', _www) [static]

Definition at line 86 of file Transform.py.


The documentation for this class was generated from the following file: