Ignore:
Timestamp:
03/24/05 19:10:29 (8 years ago)
Author:
hauma
Message:
  • If a TOC page contains a call to TracNav with itself as argument, use the currently edited version of TOC in the preview of the navigation bar. Disable the edit button in preview mode.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trac/trunk/wiki-macros/TracNav.py

    r2935 r2936  
    7777listRule = re.compile(r"""^(?P<indent> *)\* +(?:(?P<wikilink>\[wiki:(?P<link>(&#34;([^&#34;]*)&#34;|'([^']*)')|([^ \]]+)) +(?P<label>[^\]]*)\])|(?P<text>.*))""", re.M) 
    7878 
    79 def getToc(env, db, name): 
    80     cursor = db.cursor() 
    81     cursor.execute('SELECT text FROM wiki WHERE name=%s ORDER BY version DESC LIMIT 1', name) 
    82     row = cursor.fetchone() 
    83     if not row: 
    84         return None 
    85  
    86     tocText = row[0] 
     79def getToc(hdf, env, db, curpage, name): 
     80    preview = hdf.getValue('args.preview', "") 
     81 
     82    tocText = "* Table of contents" 
     83    if preview and (name == curpage): 
     84        tocText = hdf.getValue('wiki.page_source', tocText); 
     85    else: 
     86        cursor = db.cursor() 
     87        cursor.execute('SELECT text FROM wiki WHERE name=%s ORDER BY version DESC LIMIT 1', name) 
     88        row = cursor.fetchone() 
     89        if row: 
     90            tocText = row[0] 
    8791 
    8892    # env.log.debug(tocText) 
    89  
     93    return tocText 
     94 
     95 
     96def parseToc(tocText): 
    9097    stack = [] 
    9198    nextPos = 0 
     
    141148 
    142149def execute(hdf, args, env): 
    143     curpage =  '%s' % hdf.getValue('args.page', '') 
     150    preview = hdf.getValue('args.preview', "") 
     151    curpage = hdf.getValue('args.page', "") 
    144152    name = args 
    145153    if not name: 
     
    147155 
    148156    db = env.get_db_cnx() 
    149     toc = getToc(env, db, name) 
     157    toc = parseToc(getToc(hdf, env, db, curpage, name)) 
    150158    if not toc: 
    151159        msg = '' 
    152160        msg += '<div class="system-message"><strong>Error: Table of contents does not exist.' 
    153         if (hdf.getValue('trac.acl.WIKI_MODIFY', '')): 
     161        if (not preview) and (hdf.getValue('trac.acl.WIKI_MODIFY', '')): 
    154162            msg += ' Click here to <a href="%s?edit=yes">edit</a>.' % env.href.wiki(name) 
    155163        msg += '</strong></div>\n' 
     
    189197 
    190198def displayAll(hdf, env, name, curpage, toc, col): 
     199    preview = hdf.getValue('args.preview', "") 
    191200    html = '' 
    192201    html += '%s<div class="wiki-toc trac-nav">\n' % indentation(col) 
    193202    col += 1 
    194     if hdf.getValue('trac.acl.WIKI_MODIFY', ''): 
     203    if (not preview) and hdf.getValue('trac.acl.WIKI_MODIFY', ''): 
    195204        html += '%s<div class="edit"><a href="%s?edit=yes">edit</a></div>\n' % (indentation(col), env.href.wiki(name)) 
    196205    html += '%s<ul>\n' % indentation(col) 
Note: See TracChangeset for help on using the changeset viewer.