[Moin-devel] CVS: MoinMoin/action LikePages.py,1.14,1.15
J?rgen Hermann
jhermann at users.sourceforge.net
Thu Jun 20 14:17:06 EDT 2002
Update of /cvsroot/moin/MoinMoin/action
In directory usw-pr-cvs1:/tmp/cvs-serv16587/action
Modified Files:
LikePages.py
Log Message:
Refactored LikePages to functions
Index: LikePages.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/action/LikePages.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** LikePages.py 24 Apr 2002 19:36:54 -0000 1.14
--- LikePages.py 20 Jun 2002 21:16:54 -0000 1.15
***************
*** 19,41 ****
! def execute(pagename, request,
s_re=re.compile('([%s][%s]+)' % (config.upperletters, config.lowerletters)),
e_re=re.compile('([%s][%s]+)$' % (config.upperletters, config.lowerletters))):
-
# figure the start and end words
s_match = s_re.match(pagename)
e_match = e_re.search(pagename)
if not (s_match and e_match):
! Page(pagename).send_page(request,
! msg=_('<b>You cannot use LikePages on an extended pagename!</b>'))
! return
# extract the words
start = s_match.group(1)
- s_len = len(start)
end = e_match.group(1)
- e_len = len(end)
subpage = pagename + '/'
- sp_len = len(subpage)
# find any matching pages
--- 19,65 ----
! def execute(pagename, request):
! start, end, matches = findMatches(pagename, request)
!
! # error?
! if isinstance(matches, type('')):
! Page(pagename).send_page(request, msg=matches)
! return
!
! # no matches :(
! if not matches:
! Page(pagename).send_page(request,
! msg='<strong>' + _('No pages match "%s"!') % (pagename,) + '</strong>')
! return
!
! # one match - display it
! if len(matches) == 1:
! Page(matches.keys()[0]).send_page(request,
! msg='<strong>' + _('Exactly one matching page for "%s" found!') % (pagename,) + '</strong>')
! return
!
! # more than one match, list 'em
! webapi.http_headers(request)
! wikiutil.send_title(_('Multiple matches for "%s...%s"') % (start, end),
! pagename=pagename)
!
! showMatches(pagename, start, end, matches)
!
! wikiutil.send_footer(request, pagename)
!
!
! def findMatches(pagename, request,
s_re=re.compile('([%s][%s]+)' % (config.upperletters, config.lowerletters)),
e_re=re.compile('([%s][%s]+)$' % (config.upperletters, config.lowerletters))):
# figure the start and end words
s_match = s_re.match(pagename)
e_match = e_re.search(pagename)
if not (s_match and e_match):
! return None, None, _('<b>You cannot use LikePages on an extended pagename!</b>')
# extract the words
start = s_match.group(1)
end = e_match.group(1)
subpage = pagename + '/'
# find any matching pages
***************
*** 45,85 ****
if anypage == pagename:
continue
! p_len = len(anypage)
! if p_len > sp_len and anypage[:sp_len] == subpage:
matches[anypage] = 4
else:
! if p_len > s_len and anypage[:s_len] == start:
matches[anypage] = 1
! if p_len > e_len and anypage[-e_len:] == end:
matches[anypage] = matches.get(anypage, 0) + 2
! # no matches :(
! if not matches:
! Page(pagename).send_page(request,
! msg='<strong>' + _('No pages match "%s"!') % (pagename,) + '</strong>')
! return
!
! # one match - display it
! if len(matches) == 1:
! Page(matches.keys()[0]).send_page(request,
! msg='<strong>' + _('Exactly one matching page for "%s" found!') % (pagename,) + '</strong>')
! return
- # more than one match, list 'em
- webapi.http_headers(request)
- wikiutil.send_title(_('Multiple matches for "%s...%s"') % (start, end),
- pagename=pagename)
keys = matches.keys()
keys.sort()
! showMatches(matches, keys, 4, "%s/..." % pagename)
! showMatches(matches, keys, 3, "%s...%s" % (start, end))
! showMatches(matches, keys, 1, "%s..." % (start,))
! showMatches(matches, keys, 2, "...%s" % (end,))
!
! wikiutil.send_footer(request, pagename)
! def showMatches(matches, keys, match, title):
matchcount = matches.values().count(match)
--- 69,93 ----
if anypage == pagename:
continue
! if anypage.startswith(subpage):
matches[anypage] = 4
else:
! if anypage.startswith(start):
matches[anypage] = 1
! if anypage.endswith(end):
matches[anypage] = matches.get(anypage, 0) + 2
! return start, end, matches
+ def showMatches(pagename, start, end, matches):
keys = matches.keys()
keys.sort()
! _showMatchGroup(matches, keys, 4, "%s/..." % pagename)
! _showMatchGroup(matches, keys, 3, "%s...%s" % (start, end))
! _showMatchGroup(matches, keys, 1, "%s..." % (start,))
! _showMatchGroup(matches, keys, 2, "...%s" % (end,))
! def _showMatchGroup(matches, keys, match, title):
matchcount = matches.values().count(match)
More information about the Moin-devel
mailing list