Back to index

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

List of all members.

Public Member Functions

def __init__
def listExportableItems
def export
def import_

Public Attributes

 context

Static Public Attributes

 encoding = None

Private Member Functions

def _getNodeAttr
def _purgeContext
def _updateFromDOM
def _getExportInfo
def _mustPreserve

Static Private Attributes

string _FILENAME = 'criteria.xml'
string _ROOT_TAGNAME = 'criteria'

Detailed Description

Dump topic criteria to / from an XML file.

Definition at line 35 of file exportimport.py.


Constructor & Destructor Documentation

def CMFTopic.exportimport.TopicExportImport.__init__ (   self,
  context 
)

Definition at line 44 of file exportimport.py.

00044 
00045     def __init__(self, context):
00046         self.context = context


Member Function Documentation

Definition at line 117 of file exportimport.py.

00117 
00118     def _getExportInfo(self):
00119         context = self.context
00120         criterion_info = []
00121 
00122         for criterion_id, criterion in context.objectItems(
00123                                         context._criteria_metatype_ids()):
00124 
00125             # SortCriterion stashes the 'field' as 'index'.
00126             field = getattr(criterion, 'index', criterion.field)
00127 
00128             info = {'criterion_id': criterion_id,
00129                     'type': criterion.meta_type,
00130                     'field': field,
00131                     'attributes': []
00132                    }
00133 
00134             attributes = info['attributes']
00135             for attrname in criterion.editableAttributes():
00136                 value = getattr(criterion, attrname)
00137                 if type(value) in (tuple, list):
00138                     value = ','.join(value)
00139                 attributes.append((attrname, value))
00140 
00141             criterion_info.append(info)
00142 
00143         return {'criteria': criterion_info,
00144                }

Here is the caller graph for this function:

def CMFTopic.exportimport.TopicExportImport._getNodeAttr (   self,
  node,
  attrname,
  default = None 
) [private]

Definition at line 86 of file exportimport.py.

00086 
00087     def _getNodeAttr(self, node, attrname, default=None):
00088         attr = node.attributes.get(attrname)
00089         if attr is None:
00090             return default
00091         value = attr.value
00092         if isinstance(value, unicode) and self.encoding is not None:
00093             value = value.encode(self.encoding)
00094         return value

Here is the caller graph for this function:

Definition at line 145 of file exportimport.py.

00145 
00146     def _mustPreserve(self):
00147         context = self.context
00148         keepers = FolderishExporterImporter._mustPreserve(self)
00149         keepers.extend(context.objectItems(context._criteria_metatype_ids()))
00150         return keepers
00151 

Here is the caller graph for this function:

Definition at line 95 of file exportimport.py.

00095 
00096     def _purgeContext(self):
00097         context = self.context
00098         criterion_ids = context.objectIds(context._criteria_metatype_ids())
00099         for criterion_id in criterion_ids:
00100             self.context._delObject(criterion_id)

Here is the caller graph for this function:

def CMFTopic.exportimport.TopicExportImport._updateFromDOM (   self,
  root 
) [private]

Definition at line 101 of file exportimport.py.

00101 
00102     def _updateFromDOM(self, root):
00103         for criterion in root.getElementsByTagName('criterion'):
00104             c_type = self._getNodeAttr(criterion, 'type', None)
00105             field = self._getNodeAttr(criterion, 'field', None)
00106             attributes = {}
00107             for attribute in criterion.getElementsByTagName('attribute'):
00108                 name = self._getNodeAttr(attribute, 'name', None)
00109                 value = self._getNodeAttr(attribute, 'value', None)
00110                 if name == 'reversed':
00111                     value = value in ('True', 'true', '1')
00112                 attributes[name] = value
00113 
00114             self.context.addCriterion(field, c_type)
00115             added = self.context.getCriterion(field)
00116             added.edit(**attributes)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFTopic.exportimport.TopicExportImport.export (   self,
  export_context,
  subdir,
  root = False 
)
See IFilesystemExporter.

Definition at line 54 of file exportimport.py.

00054 
00055     def export(self, export_context, subdir, root=False):
00056         """ See IFilesystemExporter.
00057         """
00058         FolderishExporterImporter.export(self, export_context, subdir, root)
00059         template = PageTemplateResource('xml/%s' % self._FILENAME,
00060                                         globals()).__of__(self.context)
00061         export_context.writeDataFile('%s/criteria.xml' % self.context.getId(),
00062                                      template(info=self._getExportInfo()),
00063                                      'text/xml',
00064                                      subdir,
00065                                     )

Here is the call graph for this function:

def CMFTopic.exportimport.TopicExportImport.import_ (   self,
  import_context,
  subdir,
  root = False 
)
See IFilesystemImporter

Definition at line 66 of file exportimport.py.

00066 
00067     def import_(self, import_context, subdir, root=False):
00068         """ See IFilesystemImporter
00069         """
00070         FolderishExporterImporter.import_(self, import_context, subdir, root)
00071 
00072         self.encoding = import_context.getEncoding()
00073 
00074         if import_context.shouldPurge():
00075             self._purgeContext()
00076 
00077         data = import_context.readDataFile('%s/criteria.xml'
00078                                                 % self.context.getId(),
00079                                            subdir)
00080 
00081         if data is not None:
00082             dom = parseString(data)
00083             root = dom.firstChild
00084             assert root.tagName == self._ROOT_TAGNAME
00085             self._updateFromDOM(root)

Here is the call graph for this function:

See IFilesystemExporter.

Definition at line 47 of file exportimport.py.

00047 
00048     def listExportableItems(self):
00049         """ See IFilesystemExporter.
00050         """
00051         criteria_metatypes = self.context._criteria_metatype_ids()
00052         return [x for x in FolderishExporterImporter.listExportableItems(self)
00053                    if x[1].meta_type not in criteria_metatypes]

Here is the caller graph for this function:


Member Data Documentation

string CMFTopic.exportimport.TopicExportImport._FILENAME = 'criteria.xml' [static, private]

Definition at line 41 of file exportimport.py.

string CMFTopic.exportimport.TopicExportImport._ROOT_TAGNAME = 'criteria' [static, private]

Definition at line 42 of file exportimport.py.

Definition at line 45 of file exportimport.py.

Definition at line 40 of file exportimport.py.


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