Changeset 4058 for waeup/branches/ulif-rewrite/src/waeup/viewlets.py
- Timestamp:
- 3 Apr 2009, 10:45:17 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/viewlets.py
r4055 r4058 3 3 import zope.interface 4 4 from zope.component import getMultiAdapter 5 from interfaces import IUniversity, IWAeUPObject, IWAeUPXMLExporter 5 from zope.location.interfaces import ISite 6 from waeup.interfaces import (IUniversity, IWAeUPObject, IWAeUPXMLExporter, 7 IWAeUPXMLImporter) 6 8 7 9 grok.context(zope.interface.Interface) … … 35 37 'Content-Type', 'text/xml; charset=UTF-8') 36 38 return xml 39 40 class ImportXML(grok.View): 41 """Replace the context object by an object created from an XML 42 representation. 43 44 XXX: This does not work for ISite objects, i.e. for instance 45 for complete University objects. 46 """ 47 grok.require('waeup.manageUniversity') 48 grok.template('master') 49 50 def update(self, xmlfile=None, CANCEL=None, SUBMIT=None): 51 if CANCEL is not None: 52 self.redirect(self.url(self.context)) 53 return 54 if not xmlfile: 55 return 56 importer = IWAeUPXMLImporter(self.context) 57 obj = importer.doImport(xmlfile) 58 if type(obj) != type(self.context): 59 return 60 parent = self.context.__parent__ 61 name = self.context.__name__ 62 self.context = obj 63 if hasattr(parent, name): 64 setattr(parent, name, obj) 65 else: 66 del parent[name] 67 parent[name] = obj 68 pass 69 return 70 71 37 72 38 73 class Head(grok.ViewletManager): … … 97 132 return '<div class="portlet"><a href="export.xml">%s</a></div>' % ( 98 133 'Export as XML',) 134 135 class ImportLink(grok.Viewlet): 136 grok.viewletmanager(LeftSidebar) 137 grok.view(Index) 138 grok.order(99) 139 grok.require('waeup.manageUniversity') 140 141 def render(self): 142 if ISite.providedBy(self.context): 143 # We cannot simply replace local sites. 144 return '' 145 return '<div class="portlet"><a href="importxml">%s</a></div>' % ( 146 'Import from XML',) 99 147 100 148 class MainArea(grok.ViewletManager): 101 149 grok.name('main') 102 150 151 class ImportXMLViewlet(grok.Viewlet): 152 grok.viewletmanager(MainArea) 153 grok.view(ImportXML) 154 103 155 104 156 class Footer(grok.ViewletManager):
Note: See TracChangeset for help on using the changeset viewer.