Back to index

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

List of all members.

Public Member Functions

def __init__
def manage_editDiffFields
def manage_addDiffField
def setDiffField
def listDiffTypes
 Interface fulfillment ##.
def getDiffType
def setDiffForPortalType
def getDiffForPortalType
def computeDiff
def createChangeSet

Static Public Attributes

string id = 'portal_diff'
string meta_type = 'CMF Diff Tool'
tuple security = ClassSecurityInfo()
tuple manage_options
tuple manage_difftypes = PageTemplateFile('zpt/editCMFDiffTool', globals() )

Private Attributes

 _pt_diffs
 _p_changed

Static Private Attributes

tuple __implements__ = (IDiffToolZ2)
dictionary _difftypes = {}
 Internal attributes.

Detailed Description

Definition at line 21 of file CMFDiffTool.py.


Constructor & Destructor Documentation

Definition at line 40 of file CMFDiffTool.py.

00040 
00041     def __init__(self):
00042         self._pt_diffs = {}


Member Function Documentation

def CMFDiffTool.CMFDiffTool.CMFDiffTool.computeDiff (   self,
  ob1,
  ob2,
  id1 = None,
  id2 = None 
)
Compute the differences between two objects and return the
results as a list.  Each object in the list will implement the
IDifference interface

Definition at line 121 of file CMFDiffTool.py.

00121 
00122     def computeDiff(self, ob1, ob2, id1=None, id2=None):
00123         """Compute the differences between two objects and return the
00124         results as a list.  Each object in the list will implement the
00125         IDifference interface"""
00126 
00127         # Try to get the portal type from obj1 first.  If that fails, use obj2
00128         pt_name = ''
00129         try:
00130             pt_name = aq_base(ob1).portal_type
00131         except AttributeError:
00132             try:
00133                 pt_name = aq_base(ob2).portal_type
00134             except AttributeError:
00135                 pass
00136 
00137         diff_map = self._pt_diffs.get(pt_name, {})
00138 
00139         diffs = []
00140         for field, klass_name in diff_map.items():
00141             klass = self._difftypes[klass_name]
00142             f_diff = klass(ob1, ob2, field, id1=id1, id2=id2)
00143             # handle compound diff types
00144             if hasattr(f_diff, '__getitem__'):
00145                 diffs.extend(f_diff)
00146             else:
00147                 diffs.append(f_diff)
00148         return diffs

def CMFDiffTool.CMFDiffTool.CMFDiffTool.createChangeSet (   self,
  ob1,
  ob2,
  id1 = None,
  id2 = None 
)
Returns a ChangeSet object that represents the differences
between ob1 and ob2 (ie. ob2 - ob1) .

Definition at line 150 of file CMFDiffTool.py.

00150 
00151     def createChangeSet(self, ob1, ob2, id1=None, id2=None):
00152         """Returns a ChangeSet object that represents the differences
00153         between ob1 and ob2 (ie. ob2 - ob1) ."""
00154         # FIXME: Pick a better ID
00155         cs = BaseChangeSet('Changes').__of__(self)
00156         cs.computeDiff(ob1, ob2, id1=id1, id2=id2)
00157         return aq_base(cs)
00158 

Returns a dictionary where each key is an attribute or
method on the given portal type, and the value is the name of
a difference type.

Definition at line 113 of file CMFDiffTool.py.

00113 
00114     def getDiffForPortalType(self, pt_name):
00115         """Returns a dictionary where each key is an attribute or
00116         method on the given portal type, and the value is the name of
00117         a difference type."""
00118         # Return a copy so we don't have to worry about the user changing it
00119         return self._pt_diffs.get(pt_name, {}).copy()

Return a class corresponding to the specified diff type.
Instances of the class will implement the IDifference
interface

Definition at line 95 of file CMFDiffTool.py.

00095 
00096     def getDiffType(self, diff):
00097         """Return a class corresponding to the specified diff type.
00098         Instances of the class will implement the IDifference
00099         interface"""
00100         return self._difftypes.get(diff, None)

Interface fulfillment ##.

List the names of the registered difference types

Definition at line 90 of file CMFDiffTool.py.

00090 
00091     def listDiffTypes(self):
00092         """List the names of the registered difference types"""
00093         return self._difftypes.keys()

Here is the caller graph for this function:

def CMFDiffTool.CMFDiffTool.CMFDiffTool.manage_addDiffField (   self,
  pt_name,
  field,
  diff,
  REQUEST = None 
)
Add a new diff field from the ZMI

Definition at line 65 of file CMFDiffTool.py.

00065 
00066     def manage_addDiffField(self, pt_name, field, diff, REQUEST=None):
00067         """Add a new diff field from the ZMI"""
00068         self.setDiffField(pt_name, field, diff)
00069         if REQUEST:
00070             return self.manage_difftypes(manage_tabs_message="Field added")
00071         
        

Here is the call graph for this function:

def CMFDiffTool.CMFDiffTool.CMFDiffTool.manage_editDiffFields (   self,
  updates,
  REQUEST = None 
)
Edit the portal type fields

Definition at line 47 of file CMFDiffTool.py.

00047 
00048     def manage_editDiffFields(self, updates, REQUEST=None):
00049         """Edit the portal type fields"""
00050 
00051         # Clear the old values
00052         del self._pt_diffs
00053         self._pt_diffs = {}
00054         for r in updates:
00055             if r.get('delete', None):
00056                 continue
00057             self.setDiffField(r.pt_name, r.field, r.diff)
00058 
00059         self._p_changed = 1
00060         
00061         if REQUEST:
00062             return self.manage_difftypes(manage_tabs_message="Diff mappings updated")
00063 

Here is the call graph for this function:

def CMFDiffTool.CMFDiffTool.CMFDiffTool.setDiffField (   self,
  pt_name,
  field,
  diff 
)
Set the diff type for 'field' on the portal type 'pt_name' to 'diff'

Definition at line 72 of file CMFDiffTool.py.

00072 
00073     def setDiffField(self, pt_name, field, diff):
00074         """Set the diff type for 'field' on the portal type 'pt_name' to 'diff'"""
00075         if pt_name not in self.portal_types.listContentTypes():
00076             raise 'BadRequest', "Error: invalid portal type"
00077 
00078         elif not field:
00079             raise 'BadRequest', "Error: no field specified"
00080 
00081         elif diff not in self.listDiffTypes():
00082             raise 'BadRequest', "Error: invalid diff type"
00083 
00084         else:
00085             self._pt_diffs.setdefault(pt_name, {})[field] = diff
00086             self._p_changed = 1
00087 

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFDiffTool.CMFDiffTool.CMFDiffTool.setDiffForPortalType (   self,
  pt_name,
  mapping 
)
Set the difference type(self, s) for the specific portal type

mapping is a dictionary where each key is an attribute or
method on the given portal type, and the value is the name of
a difference type.

Definition at line 102 of file CMFDiffTool.py.

00102 
00103     def setDiffForPortalType(self, pt_name, mapping):
00104         """Set the difference type(self, s) for the specific portal type
00105 
00106         mapping is a dictionary where each key is an attribute or
00107         method on the given portal type, and the value is the name of
00108         a difference type."""
00109         # FIXME: Do some error checking
00110         self._pt_diffs[pt_name] = mapping.copy()
00111         self._p_changed = 1


Member Data Documentation

tuple CMFDiffTool.CMFDiffTool.CMFDiffTool.__implements__ = (IDiffToolZ2) [static, private]

Definition at line 34 of file CMFDiffTool.py.

dictionary CMFDiffTool.CMFDiffTool.CMFDiffTool._difftypes = {} [static, private]

Internal attributes.

Definition at line 38 of file CMFDiffTool.py.

Definition at line 58 of file CMFDiffTool.py.

Definition at line 41 of file CMFDiffTool.py.

string CMFDiffTool.CMFDiffTool.CMFDiffTool.id = 'portal_diff' [static]

Definition at line 24 of file CMFDiffTool.py.

tuple CMFDiffTool.CMFDiffTool.CMFDiffTool.manage_difftypes = PageTemplateFile('zpt/editCMFDiffTool', globals() ) [static]

Definition at line 44 of file CMFDiffTool.py.

Initial value:
(( {'label':'Configure', 'action':'manage_difftypes'},
                      {'label':'Overview', 'action':'manage_overview'},
                      ) + SimpleItem.manage_options
                    )

Definition at line 29 of file CMFDiffTool.py.

string CMFDiffTool.CMFDiffTool.CMFDiffTool.meta_type = 'CMF Diff Tool' [static]

Definition at line 25 of file CMFDiffTool.py.

tuple CMFDiffTool.CMFDiffTool.CMFDiffTool.security = ClassSecurityInfo() [static]

Definition at line 27 of file CMFDiffTool.py.


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