1 | ## $Id: browser.py 11954 2014-11-13 16:54:17Z 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 | |
---|
21 | import grok |
---|
22 | from zope.catalog.interfaces import ICatalog |
---|
23 | from zope.component import queryUtility, getUtility, createObject |
---|
24 | from waeup.ikoba.browser.layout import UtilityView |
---|
25 | from waeup.ikoba.interfaces import IObjectHistory |
---|
26 | |
---|
27 | from waeup.ikoba.interfaces import ICompany |
---|
28 | |
---|
29 | class ReindexPage(UtilityView, grok.View): |
---|
30 | """ Reindex view. |
---|
31 | |
---|
32 | Reindexes a catalog. For managers only. |
---|
33 | """ |
---|
34 | grok.context(ICompany) |
---|
35 | grok.name('reindex') |
---|
36 | grok.require('waeup.managePortal') |
---|
37 | |
---|
38 | def update(self,ctlg=None): |
---|
39 | if ctlg is None: |
---|
40 | self.flash('No catalog name provided.') |
---|
41 | return |
---|
42 | cat = queryUtility(ICatalog, name='%s_catalog' % ctlg) |
---|
43 | if cat is None: |
---|
44 | self.flash('%s_catalog does not exist' % ctlg) |
---|
45 | return |
---|
46 | self.context.logger.info( |
---|
47 | 'Catalog `%s_catalog` re-indexing started.' % ctlg) |
---|
48 | cat.updateIndexes() |
---|
49 | no_of_entries = cat.values()[0].documentCount() |
---|
50 | self.flash('%d %s re-indexed.' % (no_of_entries,ctlg)) |
---|
51 | self.context.logger.info( |
---|
52 | 'Re-indexing of %d objects finished.' % no_of_entries) |
---|
53 | return |
---|
54 | |
---|
55 | def render(self): |
---|
56 | self.redirect(self.url(self.context, '@@index')) |
---|
57 | return |
---|