Attachment 'LikePages.py.patch'

Download

   1 --- LikePages.py.orig	Mon Apr 17 04:37:42 2006
   2 +++ LikePages.py	Wed Jun 14 13:26:10 2006
   3 @@ -40,7 +40,7 @@
   4  
   5      # more than one match, list 'em
   6      request.http_headers()
   7 -
   8 +        
   9      # This action generate data using the user language
  10      request.setContentLanguage(request.lang)
  11  
  12 @@ -178,7 +178,7 @@
  13      @return: list of matching pages, sorted by rank
  14      """
  15      import difflib
  16 -    
  17 +
  18      # Match using case insensitive matching
  19      # Make mapping from lowerpages to pages - pages might have same name
  20      # with different case (although its stupid).
  21 @@ -205,16 +205,30 @@
  22  def showMatches(pagename, request, start, end, matches, show_count = True):
  23      keys = matches.keys()
  24      keys.sort()
  25 -    _showMatchGroup(request, matches, keys, 8, pagename, show_count)
  26 -    _showMatchGroup(request, matches, keys, 4, "%s/..." % pagename, show_count)
  27 -    _showMatchGroup(request, matches, keys, 3, "%s...%s" % (start, end), show_count)
  28 -    _showMatchGroup(request, matches, keys, 1, "%s..." % (start,), show_count)
  29 -    _showMatchGroup(request, matches, keys, 2, "...%s" % (end,), show_count)
  30 +
  31 +    (keys8, keys4, keys3, keys1, keys2) = ([] for i in range(5))
  32 +    for key in keys:
  33 +        if matches[key] == 8:
  34 +            keys8.append(key)
  35 +        elif matches[key] == 4:
  36 +            keys4.append(key)
  37 +        elif matches[key] == 3:
  38 +            keys3.append(key)
  39 +        elif matches[key] == 1:
  40 +            keys1.append(key)
  41 +        elif matches[key] == 2:
  42 +            keys2.append(key)
  43 +
  44 +    _showMatchGroup(request, matches, keys8, 8, pagename, show_count)
  45 +    _showMatchGroup(request, matches, keys4, 4, "%s/..." % pagename, show_count)
  46 +    _showMatchGroup(request, matches, keys3, 3, "%s...%s" % (start, end), show_count)
  47 +    _showMatchGroup(request, matches, keys1, 1, "%s..." % (start,), show_count)
  48 +    _showMatchGroup(request, matches, keys2, 2, "...%s" % (end,), show_count)
  49  
  50  
  51  def _showMatchGroup(request, matches, keys, match, title, show_count = True):
  52      _ = request.getText
  53 -    matchcount = matches.values().count(match)
  54 +    matchcount = len(keys)
  55  
  56      if matchcount:
  57          if show_count:
  58 @@ -229,14 +243,53 @@
  59              request.write(request.formatter.paragraph(0))
  60  
  61          # Render links
  62 -        request.write(request.formatter.bullet_list(1))
  63 -        for key in keys:
  64 -            if matches[key] == match:
  65 -                request.write(request.formatter.listitem(1))
  66 -                request.write(request.formatter.pagelink(1, key))
  67 -                request.write(request.formatter.text(key))
  68 -                request.write(request.formatter.pagelink(0, key))
  69 -                request.write(request.formatter.listitem(0))
  70 -        request.write(request.formatter.bullet_list(0))
  71 -
  72 -
  73 +        if matchcount <= 5:
  74 +            _showMatchItems(request, matches, keys, match)
  75 +        else:
  76 +            request.write(_jsp_func())
  77 +            _showMatchItems(request, matches, keys[:5], match)
  78 +            request.write(_hs_btn(match))
  79 +            request.write(_hs_start(match))
  80 +            _showMatchItems(request, matches, keys[5:], match)
  81 +            request.write(_hs_end())
  82 +
  83 +def _showMatchItems(request,matches, keys, match):
  84 +    request.write(request.formatter.bullet_list(1))
  85 +    for key in keys:
  86 +        request.write(request.formatter.listitem(1))
  87 +        request.write(request.formatter.pagelink(1, key))
  88 +        request.write(request.formatter.text(key))
  89 +        request.write(request.formatter.pagelink(0, key))
  90 +        request.write(request.formatter.listitem(0))
  91 +    request.write(request.formatter.bullet_list(0))
  92 +
  93 +def _jsp_func():
  94 +    func = '''
  95 +    <script language="JavaScript" type="text/javascript">
  96 +    <!--
  97 +    function hideshow(e){
  98 +    e.style.display=(e.style.display=="none")?"":"none";
  99 +    }
 100 +    //-->
 101 +    </script>
 102 +    '''
 103 +    return func
 104 +
 105 +
 106 +def _hs_btn(idx):
 107 +    html = '''
 108 +    <div id="hs_btn"> <a href="#" onClick="hideshow(hs_content_%s)">More...</a> </div>
 109 +    ''' % idx
 110 +    return html
 111 +
 112 +def _hs_start(idx):
 113 +    html = '''
 114 +    <div id="hs_content_%s" style="display:none">
 115 +    ''' % idx
 116 +    return html
 117 +
 118 +def _hs_end():
 119 +    html = '''
 120 +    </div>
 121 +    '''
 122 +    return html
 123 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-06-14 06:16:09, 4.2 KB) [[attachment:LikePages.py.patch]]
  • [get | view] (2006-06-14 11:29:39, 5.2 KB) [[attachment:screenshot.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.