Ignore:
Timestamp:
27 May 2009, 09:58:01 (16 years ago)
Author:
uli
Message:

Move import functionality from viewlet to datacenter.

File:
1 edited

Legend:

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

    r4184 r4186  
    157157        return 'z%s' % struct.unpack('>Q', oid)[0]
    158158
     159    def doImport(self, csvfile, receiverid, clear=None):
     160        receivers = self.getReceiverIds()
     161        if receiverid not in receivers.keys():
     162            raise ValueError('The requested data receiver cannot be found.')
     163        receiver = receivers[receiverid]
     164        importer = IWAeUPCSVImporter(receiver)
     165        if clear is not None:
     166            importer.doImport(csvfile, clear_old_data=clear)
     167        else:
     168            importer.doImport(csvfile)
     169        return
     170
    159171       
    160172class IDataCenterFile(Interface):
     
    269281    grok.require('waeup.manageUniversity')
    270282    grok.template('master')
     283    grok.context(DataCenter)
    271284
    272285    def update(self, csvfile=None, clear=None, overwrite=None,
     
    279292        if not SUBMIT:
    280293            return
    281         receivers = self.context.getReceiverIds()
    282         if receiverid not in receivers.keys():
    283             return
    284         receiver = receivers[receiverid]
    285         importer = IWAeUPCSVImporter(receiver)
    286         importer.doImport(csvfile)
     294        try:
     295            self.context.doImport(csvfile, receiverid, clear=clear)
     296        except ValueError:
     297            self.flash('Could not import: %s' % os.path.basename(csvfile))
     298            return
     299        except:
     300            self.flash('Import failed: %s' % sys.exc_info()[1])
     301            return
     302        self.flash('Successfully imported: %s' % os.path.basename(csvfile))
     303        self.redirect(self.url(self.context))
    287304        return
    288305
    289306class Import(object):
     307    """Helper class to aggregate imports and their data.
     308    """
    290309    def __init__(self, filedescr, importers):
    291310        self.file = filedescr
Note: See TracChangeset for help on using the changeset viewer.