~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/events/wikidictsrescan.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - wikidicts notification plugin for event system
 
4
 
 
5
    When a Group or Dict page changes, we rescan them and recreate the cache.
 
6
 
 
7
    @copyright: 2007 by MoinMoin:ThomasWaldmann
 
8
    @license: GNU GPL, see COPYING for details.
 
9
"""
 
10
 
 
11
from MoinMoin import log
 
12
logging = log.getLogger(__name__)
 
13
 
 
14
from MoinMoin import events as ev
 
15
from MoinMoin import wikidicts
 
16
 
 
17
def handle(event):
 
18
    # "changed" includes creation, deletion, renamed and copied
 
19
    if (isinstance(event, ev.PageChangedEvent) or isinstance(event, ev.PageRenamedEvent) or
 
20
        isinstance(event, ev.PageCopiedEvent) or isinstance(event, ev.TrivialPageChangedEvent)):
 
21
        cfg = event.request.cfg
 
22
        pagename = event.page.page_name
 
23
        if cfg.cache.page_dict_regexact.search(pagename) or \
 
24
           cfg.cache.page_group_regexact.search(pagename):
 
25
            return handle_groupsdicts_changed(event)
 
26
 
 
27
 
 
28
def handle_groupsdicts_changed(event):
 
29
    """ Handles events related to groups and dicts page changes:
 
30
        Scans all pages matching the dict / group regex and pickles the
 
31
        data to disk.
 
32
    """
 
33
    request = event.request
 
34
    page = event.page
 
35
 
 
36
    logging.debug("groupsdicts changed: %r, scan_dicts started", page.page_name)
 
37
    del request.dicts
 
38
    gd = wikidicts.GroupDict(request)
 
39
    gd.scan_dicts()
 
40
    logging.debug("groupsdicts changed: scan_dicts finished")
 
41