source: main/waeup.kofa/trunk/src/waeup/kofa/utils/browser.py @ 9012

Last change on this file since 9012 was 9012, checked in by Henrik Bettermann, 12 years ago

ObjectHistory? method, helper function and view to modify (manipulate) student history messages.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1## $Id: browser.py 9012 2012-07-18 06:47:21Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""UI components for utilities and helpers.
19"""
20
21import grok
22from zope.catalog.interfaces import ICatalog
23from zope.component import queryUtility, getUtility, createObject
24from waeup.kofa.browser.layout import UtilityView
25from waeup.kofa.interfaces import IObjectHistory
26
27from waeup.kofa.interfaces import IUniversity
28
29def replaceStudentMessages(old, new):
30    students = grok.getSite()['students']
31    for student in students.values():
32        history = IObjectHistory(student)
33        history.modifyMessages(old, new)
34    return
35
36class ReindexPage(UtilityView, grok.View):
37    """ Reindex view.
38
39    Reindexes a catalog. For managers only.
40    """
41    grok.context(IUniversity)
42    grok.name('reindex')
43    grok.require('waeup.managePortal')
44
45    def update(self,ctlg=None):
46        if ctlg is None:
47            self.flash('No catalog name provided.')
48            return
49        cat = queryUtility(ICatalog, name='%s_catalog' % ctlg)
50        if cat is None:
51            self.flash('%s_catalog does not exist' % ctlg)
52            return
53        self.context.logger.info(
54            'Catalog `%s_catalog` re-indexing started.' % ctlg)
55        cat.updateIndexes()
56        no_of_entries = cat.values()[0].documentCount()
57        self.flash('%d %s re-indexed.' % (no_of_entries,ctlg))
58        self.context.logger.info(
59            'Re-indexing of %d objects finished.' % no_of_entries)
60        return
61
62    def render(self):
63        self.redirect(self.url(self.context, '@@index'))
64        return
65
66class ModifyAllStudentHistory(UtilityView, grok.View):
67    """ View to modify all student histories.
68
69    """
70    grok.context(IUniversity)
71    grok.name('modify_student_history')
72    grok.require('waeup.managePortal')
73
74    def update(self,old=None, new=None):
75        if None in (old, new):
76            self.flash('Syntax: /modify_student_history?old=[old string]&new=[new string]')
77            return
78        replaceStudentMessages(old, new)
79        self.context.logger.info(
80            "'%s' replaced by '%s' in all student histories." % (old, new))
81        self.flash('Finished')
82        return
83
84    def render(self):
85        self.redirect(self.url(self.context, '@@index'))
86        return
Note: See TracBrowser for help on using the repository browser.