incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1360279 - in /incubator/bloodhound/trunk/bloodhound_dashboard: bhdashboard/admin.py bhdashboard/macros.py setup.py
Date Wed, 11 Jul 2012 16:30:52 GMT
Author: gjm
Date: Wed Jul 11 16:30:51 2012
New Revision: 1360279

URL: http://svn.apache.org/viewvc?rev=1360279&view=rev
Log:
dashboard: adding an alternative guide TOC macro and renaming of links - towards #85

Added:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/macros.py   (with props)
Modified:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py
    incubator/bloodhound/trunk/bloodhound_dashboard/setup.py

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py?rev=1360279&r1=1360278&r2=1360279&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/admin.py Wed Jul 11 16:30:51
2012
@@ -31,11 +31,13 @@ from trac.util.translation import _
 from trac.wiki.admin import WikiAdmin
 from trac.wiki.model import WikiPage
 
+GUIDE_NAME = 'Guide'
+
 class BloodhoundAdmin(Component):
     """Bloodhound administration commands.
     """
 
-    RENAME_MAP = {'TracGuide': 'Guide'}
+    RENAME_MAP = {'TracGuide': GUIDE_NAME + '/Index',}
 
     implements(IAdminCommandProvider)
 
@@ -44,11 +46,12 @@ class BloodhoundAdmin(Component):
         """List available commands.
         """
         yield ('wiki bh-upgrade', '',
-                'Move Trac* wiki pages to Guide/',
+                'Move Trac* wiki pages to %s/*' % GUIDE_NAME,
                 None, self._do_wiki_upgrade)
 
     def _do_wiki_upgrade(self):
-        """Move all wiki pages starting with Trac prefix to Guide/
+        """Move all wiki pages starting with Trac prefix to unbranded user
+        guide pages.
         """
         get_new_name = self.RENAME_MAP.get
 
@@ -56,7 +59,8 @@ class BloodhoundAdmin(Component):
         pages = wiki_admin.get_wiki_list()
         for old_name in pages:
             if old_name.startswith('Trac'):
-                new_name = get_new_name(old_name, 'Guide/' + old_name[4:])
+                new_name = get_new_name(old_name,
+                                        GUIDE_NAME + '/' + old_name[4:])
                 if not new_name:
                     continue
                 if new_name in pages:
@@ -70,9 +74,25 @@ class BloodhoundAdmin(Component):
                     printout(_('Error moving %(page)s : %(message)s',
                             page=old_name, message=unicode(exc)))
                 else:
-                    # On success , insert redirection page
+                    # On success, rename links in other pages
+                    self._do_wiki_rename_links(old_name, new_name)
+                    # On success, insert redirection page
                     redirection = WikiPage(self.env, old_name)
                     redirection.text = _('See [wiki:"%(name)s"].', name=new_name)
                     comment = 'Bloodhound guide update'
                     redirection.save('bloodhound', comment, '0.0.0.0')
+        self._do_wiki_rename_links('TracGuideToc', 'UserGuideToc')
 
+    def _do_wiki_rename_links(self, old_name, new_name):
+        import re
+        with self.env.db_transaction as db:
+            pages = db("""SELECT name, text FROM wiki
+                          WHERE text %s
+                          """ % db.like(),
+                              ('%' + db.like_escape(old_name) + '%',))
+            for name, text in pages:
+                res = db("""UPDATE wiki
+                            SET text=%s
+                            WHERE name=%s
+                            """, 
+                         (re.sub(r'\b%s\b' % old_name, new_name, text), name))

Added: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/macros.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/macros.py?rev=1360279&view=auto
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/macros.py (added)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/macros.py Wed Jul 11 16:30:51
2012
@@ -0,0 +1,61 @@
+from genshi.builder import tag
+from trac.util.translation import _, cleandoc_
+from trac.wiki.api import WikiSystem
+from trac.wiki.macros import WikiMacroBase
+
+from bhdashboard.admin import GUIDE_NAME
+
+class UserGuideTocMacro(WikiMacroBase):
+    _description = cleandoc_("""Display a Guide table of contents
+    
+    This macro provides the table-of-contents specific to the user Guide
+    """
+    )
+    TOC = [('%(guide)s/Index',                    'Index'),
+           ('%(guide)s/Install',                  'Installation'),
+           ('%(guide)s/InterfaceCustomization',   'Customization'),
+           ('%(guide)s/Plugins',                  'Plugins'),
+           ('%(guide)s/Upgrade',                  'Upgrading'),
+           ('%(guide)s/Ini',                      'Configuration'),
+           ('%(guide)s/Admin',                    'Administration'),
+           ('%(guide)s/Backup',                   'Backup'),
+           ('%(guide)s/Logging',                  'Logging'),
+           ('%(guide)s/Permissions' ,             'Permissions'),
+           ('%(guide)s/Wiki',                     'The Wiki'),
+           ('WikiFormatting',               'Wiki Formatting'),
+           ('%(guide)s/Timeline',                 'Timeline'),
+           ('%(guide)s/Browser',                  'Repository Browser'),
+           ('%(guide)s/RevisionLog',              'Revision Log'),
+           ('%(guide)s/Changeset',                'Changesets'),
+           ('%(guide)s/Tickets',                  'Tickets'),
+           ('%(guide)s/Workflow',                 'Workflow'),
+           ('%(guide)s/Roadmap',                  'Roadmap'),
+           ('%(guide)s/Query',                    'Ticket Queries'),
+           ('%(guide)s/BatchModify',              'Batch Modify'),
+           ('%(guide)s/Reports',                  'Reports'),
+           ('%(guide)s/Rss',                      'RSS Support'),
+           ('%(guide)s/Notification',             'Notification'),
+          ]
+
+    def expand_macro(self, formatter, name, args):
+        curpage = formatter.resource.id
+
+        # scoped TOC (e.g. TranslateRu/Guide or 0.X/Guide ...)
+        prefix = ''
+        guideprefix =  GUIDE_NAME + '/'
+        data = {'guide': GUIDE_NAME,}
+        idx = curpage.find('/')
+        if idx > 0:
+            prefix = curpage[:idx+1]
+        if prefix.endswith(guideprefix):
+            prefix = prefix[:len(prefix)-len(guideprefix)]
+        ws = WikiSystem(self.env)
+        return tag.div(
+            tag.h4(_('Table of Contents')),
+            tag.ul([tag.li(tag.a(title,
+                                 href=formatter.href.wiki(prefix+ref % data),
+                                 class_=(not ws.has_page(prefix+ref % data) and
+                                         'missing')),
+                           class_=(prefix+ref % data== curpage and 'active'))
+                    for ref, title in self.TOC]),
+            class_='wiki-toc')

Propchange: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/macros.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/setup.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/setup.py?rev=1360279&r1=1360278&r2=1360279&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/setup.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/setup.py Wed Jul 11 16:30:51 2012
@@ -114,6 +114,7 @@ ENTRY_POINTS = r"""
                [trac.plugins]
                bhdashboard.admin = bhdashboard.admin
                bhdashboard.api = bhdashboard.api
+               bhdashboard.macros = bhdashboard.macros
                bhdashboard.layouts.bootstrap = bhdashboard.layouts.bootstrap
                bhdashboard.widgets.containers = bhdashboard.widgets.containers
                bhdashboard.widgets.query = bhdashboard.widgets.query



Mime
View raw message