[Mpuls-commits] r996 - in wasko/branches/2.0: . waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 28 19:27:17 CET 2010


Author: bh
Date: 2010-01-28 19:27:15 +0100 (Thu, 28 Jan 2010)
New Revision: 996

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/waskaweb/lib/navigation.py
Log:
* waskaweb/lib/navigation.py: Fix formatting


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-01-28 18:17:47 UTC (rev 995)
+++ wasko/branches/2.0/ChangeLog	2010-01-28 18:27:15 UTC (rev 996)
@@ -1,5 +1,9 @@
 2010-01-28  Bernhard Herzog  <bh at intevation.de>
 
+	* waskaweb/lib/navigation.py: Fix formatting
+
+2010-01-28  Bernhard Herzog  <bh at intevation.de>
+
 	* waskaweb/lib/config.py (get_path): No need to treat an absolute
 	filename specially.  os.path.join already does the right thing.
 

Modified: wasko/branches/2.0/waskaweb/lib/navigation.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/navigation.py	2010-01-28 18:17:47 UTC (rev 995)
+++ wasko/branches/2.0/waskaweb/lib/navigation.py	2010-01-28 18:27:15 UTC (rev 996)
@@ -1,27 +1,27 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS - 
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
 # Web-Anwendungs-Server fuer Kompetenzagenturen).
-# 
+#
 # mpuls WASKA is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the
 # Free Software Foundation, either version 3 of the License, or (at your
 # option) any later version.
-# 
+#
 # mpuls WASKA is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 # License for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public
 # License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-# 
-# mpuls WASKA has been developed on behalf of the 
+#
+# mpuls WASKA has been developed on behalf of the
 # Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
 # within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
 # European Social Fund resources.
 #
 # Authors:
@@ -31,35 +31,36 @@
 import logging
 from cgi import escape
 
-from paste.httpexceptions  import HTTPNotFound
-#from pylons import app_globals as g
+from paste.httpexceptions import HTTPNotFound
 from pylons import session, g
 from pylons.i18n import _
 
 from formed.meta.nodecomponents import Node
-from formed.instance.tree import InstanceNode, RepeatInstanceContainerNode, RepeatInstanceNode
-from formed.meta.data           import PageNode
+from formed.meta.data import PageNode
+from formed.instance.tree import InstanceNode, RepeatInstanceContainerNode, \
+     RepeatInstanceNode
+from formed.instance.backends.postgres import DBFactory as InstanceFactory
 
 from waskaweb.lib.db import PostgresDBInterface
 from waskaweb.lib.filecache import FileCache
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
 
-SELECT_ITEM   = u"/formularpage/select/%s"
+SELECT_ITEM = u"/formularpage/select/%s"
 SELECT_BRANCH = u"/navigation/select_branch/%s"
-CLOSE_BRANCH  = u"/navigation/close_branch/%s"
-OPEN_BRANCH   = u"/navigation/open_branch/%s"
+CLOSE_BRANCH = u"/navigation/close_branch/%s"
+OPEN_BRANCH = u"/navigation/open_branch/%s"
 
 CHECK_MODIFICATION = u'onclick="return checkModification();"'
 
+
 log = logging.getLogger(__name__)
 
+
 def get_navigation(id, openfolders=None):
     print "n1"
     factory = InstanceFactory(g.formedTree, PostgresDBInterface())
     print "n2"
-    instance_tree = factory.loadInstanceTreeByIdentifier(
-        id,
-        session.get('uncommited_fields'))
+    instance_tree = factory.loadInstanceTreeByIdentifier(id,
+                                              session.get('uncommited_fields'))
     navigation = NavigationTree(instance_tree, openfolders)
     print "n3"
     return navigation
@@ -70,7 +71,7 @@
     return tree.render(tree.root, FileCache(), error_pages)
 
 def mark_folderopen(ti):
-    if ti.key not in session.get('navigation.openfolders'): 
+    if ti.key not in session.get('navigation.openfolders'):
         session['navigation.openfolders'].append(ti.key)
         ti.unfold()
     session.save()
@@ -80,7 +81,8 @@
         session['navigation.openfolders'].remove(ti.key)
         session.save()
     except:
-        log.error('Tried to remove %s from %s' % (ti.key, session['navigation.openfolders']))
+        log.error('Tried to remove %s from %s',
+                  ti.key, session['navigation.openfolders'])
 
 def get_pagename(page_id):
     '''Returns the name of the page identified by page_id'''
@@ -91,27 +93,30 @@
     except:
         log.error('Can not find name for page %s' % page_id)
 
+
 class TreeItem:
 
-    def __init__(self, name, description, children = None, parent = None):
-        self.is_open     = False
-        self.name        = name
+    def __init__(self, name, description, children=None, parent=None):
+        self.is_open = False
+        self.name = name
         self.description = description
-        self.parent      = parent
-        self.children    = children
-        self.key         = None
-        self.next        = None
-        self.repeat      = False
+        self.parent = parent
+        self.children = children
+        self.key = None
+        self.next = None
+        self.repeat = False
 
     def is_child(self):
         return self.children is None
 
     def deepest_item(self):
         cur = self
-        if cur.repeat: return cur 
+        if cur.repeat:
+            return cur
         while cur.children:
             cur = cur.children[0]
-            if cur.repeat: break 
+            if cur.repeat:
+                break
         return cur
 
     def get_depth(self):
@@ -125,7 +130,8 @@
     def find_page(self):
         cur = self
         while cur:
-            if cur.next: return cur
+            if cur.next:
+                return cur
             cur = cur.parent
         return None
 
@@ -139,7 +145,6 @@
         return opened
 
     def render(self, page, out, get_image, error_lookup):
-
         out.append(u'<tr>')
         selected = page == self.key
         has_error = self in error_lookup
@@ -148,35 +153,41 @@
         entry = []
         if self.is_child():
             select_link = SELECT_ITEM % self.key
-            icon.append(u'<a href="%s" %s>' % ( select_link, CHECK_MODIFICATION))
+            icon.append(u'<a href="%s" %s>'
+                        % (select_link, CHECK_MODIFICATION))
             icon.append(get_image("/images/icons/navigation/entry.png",
-                u' border="0"'
-                u' alt="%s"'
-                u' title="%s"' % (_('entry'), _('Open page'))))
+                                  u' border="0"'
+                                  u' alt="%s"'
+                                  u' title="%s"'
+                                  % (_('entry'), _('Open page'))))
         else:
             deepest = self.deepest_item()
             select_link = SELECT_BRANCH %  deepest.key
             if self.is_open:
                 action = CLOSE_BRANCH % self.key
-                icon.append(u'<a href="%s" %s>' % ( action, CHECK_MODIFICATION))
+                icon.append(u'<a href="%s" %s>' % (action, CHECK_MODIFICATION))
                 icon.append(get_image("/images/icons/navigation/folder_open.png",
-                    u' border="0"'
-                    u' alt="%s"'
-                    u' title="%s"' % (_('entry'), _('Open page'))))
+                                      u' border="0"'
+                                      u' alt="%s"'
+                                      u' title="%s"'
+                                      % (_('entry'), _('Open page'))))
             else:
                 action = OPEN_BRANCH % self.key
-                icon.append(u'<a href="%s" %s>' % ( action, CHECK_MODIFICATION))
+                icon.append(u'<a href="%s" %s>' % (action, CHECK_MODIFICATION))
                 icon.append(get_image("/images/icons/navigation/folder_closed.png",
-                    u' border="0"'
-                    u' alt="%s"'
-                    u' title="%s"' % (_('entry'), _('Open page'))))
+                                      u' border="0"'
+                                      u' alt="%s"'
+                                      u' title="%s"'
+                                      % (_('entry'), _('Open page'))))
         icon.append('</a>')
         entry.append(u'<a href="%s" %s>%s</a>' % (
                 select_link, CHECK_MODIFICATION, escape(self.description)))
 
-        selected = str(self.key)== str(session.get('navigation.selectedpage')) and "selected" or ""
+        selected = (str(self.key) == str(session.get('navigation.selectedpage'))
+                    and "selected" or "")
         out.append(u'<td class="%s">' % selected)
-        out.append('<span style="white-space:nowrap;">%s %s</span>' % ("&nbsp;"*(self.get_depth()-1), "".join(icon)))
+        out.append('<span style="white-space:nowrap;">%s %s</span>'
+                   % ("&nbsp;" * (self.get_depth() - 1), "".join(icon)))
         out.append(u'</td>')
         out.append(u'<td class="%s">' % selected)
         out.append('%s' % ("".join(entry)))
@@ -199,7 +210,6 @@
             for child in self.children:
                 child.render(page, out, get_image, error_lookup)
 
-
     def set_open(self, flag):
         self.is_open = flag
 
@@ -242,7 +252,8 @@
 
     def nextKey(self):
         page = self.find_page()
-        if not page: return None
+        if not page:
+            return None
         return page.next
 
 def get_page(nc):
@@ -256,44 +267,43 @@
 class NavigationTreeBuilder(object):
 
     def __init__(self, root, openfolders):
-        self.key   = root.getIdentifier()
-        self.prev  = None
+        self.key = root.getIdentifier()
+        self.prev = None
         self.first = None
         self.openfolders = openfolders or []
-        self.root  = self.build(root, None)
+        self.root = self.build(root, None)
 
     def build(self, nc, parent):
         if isinstance(nc, RepeatInstanceNode):
-            nc = nc.getChildren()[0] # Ignore RepeatInstanceNodes. Not needed while rendering
+            # Ignore RepeatInstanceNodes. Not needed while rendering
+            nc = nc.getChildren()[0]
         meta = nc.getMeta()
         if isinstance(meta, PageNode):
             if meta.isInvisible():
                 return None
-            ti = TreeItem(meta.getName(), meta.getDescription(), parent = parent)
+            ti = TreeItem(meta.getName(), meta.getDescription(), parent=parent)
             if not self.first:
                 self.first = ti
             if self.prev:
                 self.prev.next = ti
             self.prev = ti
-            ti.key = nc.getIdentifier() 
+            ti.key = nc.getIdentifier()
             return ti
 
         if isinstance(nc, InstanceNode):
             children = []
-            n = TreeItem(
-                get_page(nc),
-                meta.getDescription(),
-                children,
-                parent)
+            n = TreeItem(get_page(nc), meta.getDescription(), children, parent)
+
             # Mark rg-containers for rendering overview pages later
             if isinstance(nc, RepeatInstanceContainerNode):
-                log.debug('Found repeatgroup container: %s' % nc.getIdentifier()) 
+                log.debug('Found repeatgroup container: %s', nc.getIdentifier())
                 n.repeat = True
 
             for child in nc.getChildren():
                 print child.getMeta().getName()
                 c = self.build(child, n)
-                if c: children.append(c)
+                if c:
+                    children.append(c)
             n.key = nc.getIdentifier()
             # Try to reopen already opened folders.
             log.debug('key: %s, open: %s' % (n.key, self.openfolders))
@@ -302,14 +312,14 @@
             return n
 
         ti = TreeItem("xxx", "Unknown Item", parent = parent)
-        ti.key = nc.getIdentifier() 
+        ti.key = nc.getIdentifier()
         return ti
 
 class NavigationTree:
 
     def __init__(self, instance, openfolders=None):
         builder = NavigationTreeBuilder(instance.getRootNode(), openfolders)
-        self.root       = builder.root
+        self.root = builder.root
         self.first_page = builder.first
 
     def getAllItems(self):
@@ -341,7 +351,7 @@
                     stack.append(c.getChildren())
         return None
 
-    def render(self, page, file_cache, error_pages = set()):
+    def render(self, page, file_cache, error_pages=set()):
         error_lookup = set()
         self.root.build_error_lookup(error_lookup, error_pages)
         out = [u'<table class="navigation">']



More information about the Mpuls-commits mailing list