Changeset 7908


Ignore:
Timestamp:
18 Mar 2012, 14:27:15 (13 years ago)
Author:
uli
Message:

Add first views/pages for site-wide CSV export of objects.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/browser
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r7868 r7908  
    3030    IAuthentication, IUnauthenticatedPrincipal, ILogout)
    3131from zope.catalog.interfaces import ICatalog
     32from zope.component import (
     33    getUtility, queryUtility, createObject, getAllUtilitiesRegisteredFor,
     34    getUtilitiesFor,
     35    )
     36#from zope.component.interfaces import Invalid
     37from zope.event import notify
    3238from zope.securitypolicy.interfaces import (
    3339    IPrincipalRoleManager, IPrincipalRoleMap)
    34 from zope.component import (
    35     getUtility, queryUtility, createObject, getAllUtilitiesRegisteredFor)
    36 #from zope.component.interfaces import Invalid
    37 from zope.event import notify
    3840from zope.session.interfaces import ISession
    3941from waeup.kofa.browser import (
     
    4446    IDepartment, IDepartmentAdd, ICourse, ICourseAdd, ICertificate,
    4547    ICertificateAdd, ICertificateCourse, ICertificateCourseAdd)
     48from waeup.kofa.browser.layout import jsaction, action, UtilityView
     49from waeup.kofa.browser.resources import warning, datepicker, tabs, datatable
    4650from waeup.kofa.interfaces import MessageFactory as _
    47 from waeup.kofa.browser.resources import warning, datepicker, tabs, datatable
    4851from waeup.kofa.interfaces import(
    4952    IKofaObject, IUsersContainer, IUserAccount, IDataCenter,
     
    5154    ILocalRolesAssignable, DuplicationError, IConfigurationContainer,
    5255    ISessionConfiguration, ISessionConfigurationAdd,
    53     IPasswordValidator, IContactForm, IKofaUtils)
     56    IPasswordValidator, IContactForm, IKofaUtils, ICSVExporter)
    5457from waeup.kofa.permissions import get_users_with_local_roles, get_all_roles
    5558from waeup.kofa.students.catalog import search as searchstudents
     
    6164from waeup.kofa.authentication import get_principal_role_manager
    6265from waeup.kofa.utils.helpers import get_user_account
    63 from waeup.kofa.browser.layout import jsaction, action, UtilityView
    6466
    6567grok.context(IKofaObject)
     
    12101212        return
    12111213
     1214class ExportCSVPage(KofaPage):
     1215    grok.context(IDataCenter)
     1216    grok.name('export')
     1217    grok.template('datacenterexportpage')
     1218    grok.require('waeup.manageUniversity')
     1219    label = _('Download portal data as CSV file.')
     1220    pnav = 0
     1221    export_button = _(u'Download')
     1222
     1223    def getExporters(self):
     1224        utils = getUtilitiesFor(ICSVExporter)
     1225        title_name_tuples = [
     1226            (util.title, name) for name, util in utils]
     1227        return sorted(title_name_tuples)
     1228
     1229    def update(self, export=None, exporter=None):
     1230        if None in (export, exporter):
     1231            return
     1232        self.redirect(
     1233            self.url(self.context, 'export.csv') + '?exporter=%s' % exporter)
     1234        return
     1235        exporter = getUtility(ICSVExporter, name=exporter)
     1236        csv_data = exporter.export_all(grok.getSite())
     1237        #csv_data.seek(0)
     1238        self.response.setHeader(
     1239            'Content-Type', 'text/csv; charset=UTF-8')
     1240        return csv_data
     1241
     1242class ExportCSVView(grok.View):
     1243    grok.context(IDataCenter)
     1244    grok.name('export.csv')
     1245    grok.require('waeup.manageUniversity')
     1246
     1247    def render(self, exporter=None):
     1248        if exporter is None:
     1249            return
     1250        exporter = getUtility(ICSVExporter, name=exporter)
     1251        csv_data = exporter.export_all(grok.getSite())
     1252        #csv_data.seek(0)
     1253        self.response.setHeader(
     1254            'Content-Type', 'text/csv; charset=UTF-8')
     1255        return csv_data
     1256
    12121257class ExportXMLPage(grok.View):
    12131258    """Deliver an XML representation of the context.
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py

    r7819 r7908  
    557557    text = _('Upload CSV file')
    558558
     559class ExportCSVButton(ActionButton):
     560    grok.context(IDataCenter)
     561    grok.view(DatacenterPage)
     562    grok.require('waeup.manageUniversity')
     563    grok.order(7)
     564    icon = 'go-down-16x16.png'
     565    target = '@@export'
     566    text = _('Export CSV file')
     567
    559568#
    560569# Primary navigation tabs (in upper left navigation bar)...
Note: See TracChangeset for help on using the changeset viewer.