Ignore:
Timestamp:
5 Jan 2010, 11:04:30 (15 years ago)
Author:
uli
Message:

Add import csv page for datacenters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/pages.py

    r4674 r4677  
    77from waeup.browser import WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage
    88from waeup.catalog import search, search_context
     9from waeup.datacenter import Import
    910from waeup.interfaces import (IUniversity, IWAeUPObject, IUserContainer,
    1011                              IUserAccount, IFacultyContainer, IDataCenter)
     
    240241    pnav = 0
    241242
     243class DataCenterImportCSVPage(WAeUPPage):
     244    """A view for importing things.
     245
     246    """
     247    grok.require('waeup.manageUniversity')
     248    grok.name('importcsv')
     249    grok.template('datacenterimportcsvpage')
     250    grok.context(IDataCenter)
     251    title = u'Import CSV'
     252    pnav = 0
     253
     254    def getImports(self):
     255        result = []
     256        imports = self.context.getPossibleImports()
     257        result = [Import(x, y) for x, y in imports]
     258        return result
     259
     260    def update(self, csvfile=None, clear=None, overwrite=None,
     261               receiverid=None, CANCEL=None, SUBMIT=None):
     262        if CANCEL is not None:
     263            self.redirect(self.url(self.context))
     264            return
     265        if not csvfile:
     266            return
     267        if not SUBMIT:
     268            return
     269        try:
     270            self.context.doImport(csvfile, receiverid, clear=clear)
     271        except ValueError:
     272            self.flash('Could not import: %s' % os.path.basename(csvfile))
     273            return
     274        except:
     275            self.flash('Import failed: %s %s' % (sys.exc_info()[0],
     276                                                 sys.exc_info()[1]))
     277            return
     278        self.flash('Successfully imported: %s' % os.path.basename(csvfile))
     279        self.redirect(self.url(self.context))
     280        return
     281
    242282
    243283#
Note: See TracChangeset for help on using the changeset viewer.