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

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

Let's edit application histories too.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: browser.py 9122 2012-08-29 11:53:22Z 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
36def replaceApplicantMessages(old, new):
37    applicants = grok.getSite()['applicants']
38    for container in applicants.values():
39        for applicant in container.values():
40            history = IObjectHistory(applicant)
41            history.modifyMessages(old, new)
42    return
43
44class ReindexPage(UtilityView, grok.View):
45    """ Reindex view.
46
47    Reindexes a catalog. For managers only.
48    """
49    grok.context(IUniversity)
50    grok.name('reindex')
51    grok.require('waeup.managePortal')
52
53    def update(self,ctlg=None):
54        if ctlg is None:
55            self.flash('No catalog name provided.')
56            return
57        cat = queryUtility(ICatalog, name='%s_catalog' % ctlg)
58        if cat is None:
59            self.flash('%s_catalog does not exist' % ctlg)
60            return
61        self.context.logger.info(
62            'Catalog `%s_catalog` re-indexing started.' % ctlg)
63        cat.updateIndexes()
64        no_of_entries = cat.values()[0].documentCount()
65        self.flash('%d %s re-indexed.' % (no_of_entries,ctlg))
66        self.context.logger.info(
67            'Re-indexing of %d objects finished.' % no_of_entries)
68        return
69
70    def render(self):
71        self.redirect(self.url(self.context, '@@index'))
72        return
73
74class ModifyAllStudentHistory(UtilityView, grok.View):
75    """ View to modify all student histories.
76
77    """
78    grok.context(IUniversity)
79    grok.name('modify_student_history')
80    grok.require('waeup.managePortal')
81
82    def update(self,old=None, new=None):
83        if None in (old, new):
84            self.flash('Syntax: /modify_student_history?old=[old string]&new=[new string]')
85            return
86        replaceStudentMessages(old, new)
87        self.context.logger.info(
88            "'%s' replaced by '%s' in all student histories." % (old, new))
89        self.flash('Finished')
90        return
91
92    def render(self):
93        self.redirect(self.url(self.context, '@@index'))
94        return
95
96class ModifyAllApplicantHistory(UtilityView, grok.View):
97    """ View to modify all student histories.
98
99    """
100    grok.context(IUniversity)
101    grok.name('modify_applicant_history')
102    grok.require('waeup.managePortal')
103
104    def update(self,old=None, new=None):
105        if None in (old, new):
106            self.flash('Syntax: /modify_applicant_history?old=[old string]&new=[new string]')
107            return
108        replaceApplicantMessages(old, new)
109        self.context.logger.info(
110            "'%s' replaced by '%s' in all applicant histories." % (old, new))
111        self.flash('Finished')
112        return
113
114    def render(self):
115        self.redirect(self.url(self.context, '@@index'))
116        return
Note: See TracBrowser for help on using the repository browser.