## $Id: browser.py 9122 2012-08-29 11:53:22Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """UI components for utilities and helpers. """ import grok from zope.catalog.interfaces import ICatalog from zope.component import queryUtility, getUtility, createObject from waeup.kofa.browser.layout import UtilityView from waeup.kofa.interfaces import IObjectHistory from waeup.kofa.interfaces import IUniversity def replaceStudentMessages(old, new): students = grok.getSite()['students'] for student in students.values(): history = IObjectHistory(student) history.modifyMessages(old, new) return def replaceApplicantMessages(old, new): applicants = grok.getSite()['applicants'] for container in applicants.values(): for applicant in container.values(): history = IObjectHistory(applicant) history.modifyMessages(old, new) return class ReindexPage(UtilityView, grok.View): """ Reindex view. Reindexes a catalog. For managers only. """ grok.context(IUniversity) grok.name('reindex') grok.require('waeup.managePortal') def update(self,ctlg=None): if ctlg is None: self.flash('No catalog name provided.') return cat = queryUtility(ICatalog, name='%s_catalog' % ctlg) if cat is None: self.flash('%s_catalog does not exist' % ctlg) return self.context.logger.info( 'Catalog `%s_catalog` re-indexing started.' % ctlg) cat.updateIndexes() no_of_entries = cat.values()[0].documentCount() self.flash('%d %s re-indexed.' % (no_of_entries,ctlg)) self.context.logger.info( 'Re-indexing of %d objects finished.' % no_of_entries) return def render(self): self.redirect(self.url(self.context, '@@index')) return class ModifyAllStudentHistory(UtilityView, grok.View): """ View to modify all student histories. """ grok.context(IUniversity) grok.name('modify_student_history') grok.require('waeup.managePortal') def update(self,old=None, new=None): if None in (old, new): self.flash('Syntax: /modify_student_history?old=[old string]&new=[new string]') return replaceStudentMessages(old, new) self.context.logger.info( "'%s' replaced by '%s' in all student histories." % (old, new)) self.flash('Finished') return def render(self): self.redirect(self.url(self.context, '@@index')) return class ModifyAllApplicantHistory(UtilityView, grok.View): """ View to modify all student histories. """ grok.context(IUniversity) grok.name('modify_applicant_history') grok.require('waeup.managePortal') def update(self,old=None, new=None): if None in (old, new): self.flash('Syntax: /modify_applicant_history?old=[old string]&new=[new string]') return replaceApplicantMessages(old, new) self.context.logger.info( "'%s' replaced by '%s' in all applicant histories." % (old, new)) self.flash('Finished') return def render(self): self.redirect(self.url(self.context, '@@index')) return