Changeset 4166 for waeup/branches
- Timestamp:
- 25 May 2009, 09:56:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/datacenter.py
r4152 r4166 8 8 import grok 9 9 from datetime import datetime 10 from zope.component import getUtility 10 11 from zope.interface import Interface 11 from waeup.interfaces import IWAeUPObject 12 from waeup.viewlets import Index, MainArea, LeftSidebar12 from waeup.interfaces import IWAeUPObject, IWAeUPCSVImporter, ICSVDataReceivers 13 from waeup.viewlets import Index, ImportCSV, MainArea, LeftSidebar 13 14 14 15 class DataCenter(grok.Container): … … 16 17 """ 17 18 storage = os.path.join(os.path.dirname(__file__), 'files') 19 20 def getImporters(self): 21 """Get a list of all importers available. 22 23 The search for available importers is done in two steps: 24 25 1) Look for a utility providing ICSVDataReceiver, 26 27 2) For every item of that utility: try to get an adapter 28 providing IWAeUPCSVImporter. 29 """ 30 result = [] 31 receivers = [] 32 curr_obj = getattr(self, '__parent__', None) 33 while curr_obj is not None: 34 if ICSVDataReceivers.providedBy(curr_obj): 35 receivers = self.getCSVDataReceivers(curr_obj) 36 break 37 curr_obj = getattr(curr_obj, '__parent__', None) 38 for receiver in receivers: 39 try: 40 importer = IWAeUPCSVImporter(receiver) 41 result.append(importer) 42 except: 43 pass 44 return result 18 45 19 46 def getFiles(self): … … 38 65 self.storage = path 39 66 67 68 def getCSVDataReceivers(self, obj): 69 """Get a list of attributes, that can receive CSV data. 70 """ 71 result = [] 72 for attr_name in dir(obj): 73 if attr_name.startswith('_'): 74 continue 75 try: 76 attr = getattr(obj, attr_name) 77 # This might fail... 78 IWAeUPCSVImporter(attr) 79 result.append(attr) 80 except: 81 pass 82 return result 83 84 40 85 class IDataCenterFile(Interface): 41 86 """A data center file. … … 47 92 """A description of a file stored in data center. 48 93 """ 49 94 grok.implements(IDataCenterFile) 95 50 96 def __init__(self, context): 51 97 self.context = context … … 141 187 def render(self): 142 188 return u'<div class="portlet"><a href="@@settings">Settings</a></div>' 143 189 190 class ImportCSVMain(grok.Viewlet): 191 grok.viewletmanager(MainArea) 192 grok.context(DataCenter) 193 grok.view(ImportCSV) 194 grok.require('waeup.manageUniversity') 195 196 def update(self, *args, **kw): 197 print "ARGS: ", args, kw 198 return super(ImportCSVMain, self).update(*args, **kw) 199
Note: See TracChangeset for help on using the changeset viewer.