Changeset 4166 for waeup


Ignore:
Timestamp:
25 May 2009, 09:56:39 (15 years ago)
Author:
uli
Message:

Update datacenter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/datacenter.py

    r4152 r4166  
    88import grok
    99from datetime import datetime
     10from zope.component import getUtility
    1011from zope.interface import Interface
    11 from waeup.interfaces import IWAeUPObject
    12 from waeup.viewlets import Index, MainArea, LeftSidebar
     12from waeup.interfaces import IWAeUPObject, IWAeUPCSVImporter, ICSVDataReceivers
     13from waeup.viewlets import Index, ImportCSV, MainArea, LeftSidebar
    1314
    1415class DataCenter(grok.Container):
     
    1617    """
    1718    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
    1845   
    1946    def getFiles(self):
     
    3865        self.storage = path
    3966
     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       
    4085class IDataCenterFile(Interface):
    4186    """A data center file.
     
    4792    """A description of a file stored in data center.
    4893    """
    49 
     94    grok.implements(IDataCenterFile)
     95   
    5096    def __init__(self, context):
    5197        self.context = context
     
    141187    def render(self):
    142188        return u'<div class="portlet"><a href="@@settings">Settings</a></div>'
    143 
     189   
     190class 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.