[Mpuls-commits] r1236 - in wasko/branches/2.0: . mpulsweb/lib waskaweb/controllers waskaweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Feb 4 12:09:33 CET 2010
Author: torsten
Date: 2010-02-04 12:09:28 +0100 (Thu, 04 Feb 2010)
New Revision: 1236
Added:
wasko/branches/2.0/mpulsweb/lib/navigation.py
Removed:
wasko/branches/2.0/waskaweb/lib/navigation.py
Modified:
wasko/branches/2.0/ChangeLog
wasko/branches/2.0/waskaweb/controllers/case.py
wasko/branches/2.0/waskaweb/controllers/formularpage.py
wasko/branches/2.0/waskaweb/controllers/navigation.py
wasko/branches/2.0/waskaweb/controllers/repeatgroup.py
wasko/branches/2.0/waskaweb/lib/helpers.py
Log:
Moved lib/navigation to base
* waskaweb/lib/navigation.py,
mpulsweb/lib/navigation.py: Moved file
* waskaweb/controllers/repeatgroup.py,
waskaweb/controllers/navigation.py,
waskaweb/controllers/case.py,
waskaweb/controllers/formularpage.py,
waskaweb/lib/helpers.py: Changed imports
Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/ChangeLog 2010-02-04 11:09:28 UTC (rev 1236)
@@ -1,5 +1,22 @@
2010-02-04 Torsten Irländer <torsten.irlaender at intevation.de>
+
+ * waskaweb/lib/navigation.py: (FileCache): Moved from lib/filecache as
+ it is only used here.
+ * waskaweb/lib/filecace.py: Deleted. Not imported anywhere anymore.
+
+ Moved lib/navigation to base
+
+ * waskaweb/lib/navigation.py,
+ mpulsweb/lib/navigation.py: Moved file
+ * waskaweb/controllers/repeatgroup.py,
+ waskaweb/controllers/navigation.py,
+ waskaweb/controllers/case.py,
+ waskaweb/controllers/formularpage.py,
+ waskaweb/lib/helpers.py: Changed imports
+
+2010-02-04 Torsten Irländer <torsten.irlaender at intevation.de>
+
Moved lib/app_globals into base
* waskaweb/lib/app_globals.py,
Copied: wasko/branches/2.0/mpulsweb/lib/navigation.py (from rev 1235, wasko/branches/2.0/waskaweb/lib/navigation.py)
Property changes on: wasko/branches/2.0/mpulsweb/lib/navigation.py
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: wasko/branches/2.0/waskaweb/controllers/case.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/case.py 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/waskaweb/controllers/case.py 2010-02-04 11:09:28 UTC (rev 1236)
@@ -44,7 +44,7 @@
from mpulsweb.lib.db import db
from waskaweb.lib.search import INCONSISTENCY_CHECK_AFTER
-from waskaweb.lib.navigation import get_navigation
+from mpulsweb.lib.navigation import get_navigation
from mpulsweb.lib.security import checkRole
#from waskaweb.lib.xmlimport import importFromXML
from waskaweb.lib.validators import NewCaseForm, SetStandinForm, \
Modified: wasko/branches/2.0/waskaweb/controllers/formularpage.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/formularpage.py 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/waskaweb/controllers/formularpage.py 2010-02-04 11:09:28 UTC (rev 1236)
@@ -12,7 +12,7 @@
from waskaweb.lib.base import BaseController, render
from mpulsweb.lib.db import PostgresDBInterface
-from waskaweb.lib.navigation import mark_folderopen
+from mpulsweb.lib.navigation import mark_folderopen
from waskaweb.lib.renderer import ViewRenderer, RepeatGroupRenderer, ErrorRenderer
from formed.instance.backends.postgres import DBFactory as InstanceFactory
Modified: wasko/branches/2.0/waskaweb/controllers/navigation.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/navigation.py 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/waskaweb/controllers/navigation.py 2010-02-04 11:09:28 UTC (rev 1236)
@@ -36,7 +36,7 @@
from waskaweb.controllers.case import CaseController
from mpulsweb.lib.security import checkRole
from waskaweb.lib.base import *
-from waskaweb.lib.navigation import mark_folderopen, mark_folderclose
+from mpulsweb.lib.navigation import mark_folderopen, mark_folderclose
from waskaweb.controllers.formularpage import FormularpageController
log = logging.getLogger(__name__)
Modified: wasko/branches/2.0/waskaweb/controllers/repeatgroup.py
===================================================================
--- wasko/branches/2.0/waskaweb/controllers/repeatgroup.py 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/waskaweb/controllers/repeatgroup.py 2010-02-04 11:09:28 UTC (rev 1236)
@@ -11,7 +11,7 @@
from waskaweb.lib.base import BaseController, render
from mpulsweb.lib.db import PostgresDBInterface
-from waskaweb.lib.navigation import get_navigation
+from mpulsweb.lib.navigation import get_navigation
from waskaweb.controllers.formularpage import FormularpageController
from formed.instance.backends.postgres import DBFactory as InstanceFactory
Modified: wasko/branches/2.0/waskaweb/lib/helpers.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/helpers.py 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/waskaweb/lib/helpers.py 2010-02-04 11:09:28 UTC (rev 1236)
@@ -46,7 +46,7 @@
from mpulsweb.lib.security import hasRole, getKAName
-from waskaweb.lib.navigation import get_pagename, render_navigation
+from mpulsweb.lib.navigation import get_pagename, render_navigation
from waskaweb.lib.filters import shorten, nl_to_br
Deleted: wasko/branches/2.0/waskaweb/lib/navigation.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/navigation.py 2010-02-04 11:05:45 UTC (rev 1235)
+++ wasko/branches/2.0/waskaweb/lib/navigation.py 2010-02-04 11:09:28 UTC (rev 1236)
@@ -1,372 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-#
-# 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
-# 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
-# European Social Fund resources.
-#
-# Authors:
-# Sascha L. Teichmann <teichmann at intevation.de>
-#
-
-import logging
-from cgi import escape
-
-from pylons import session, g
-from pylons.i18n import _
-
-from formed.meta.data import PageNode
-from formed.instance.tree import InstanceNode, RepeatInstanceContainerNode, \
- RepeatInstanceNode
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
-
-from mpulsweb.lib.db import PostgresDBInterface
-
-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"
-
-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'))
- navigation = NavigationTree(instance_tree, openfolders)
- print "n3"
- return navigation
-
-def render_navigation(mode="r"):
- tree = session['navigation.tree']
- error_pages = set()
- return tree.render(tree.root, FileCache(), error_pages)
-
-def mark_folderopen(ti):
- if ti.key not in session.get('navigation.openfolders'):
- session['navigation.openfolders'].append(ti.key)
- ti.unfold()
- session.save()
-
-def mark_folderclose(ti):
- try:
- session['navigation.openfolders'].remove(ti.key)
- session.save()
- except:
- 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'''
- navigation = session.get('navigation.tree')
- try:
- ti = navigation.getTreeItem(page_id)
- return "Akte: %s" % ti.description
- except:
- log.error('Can not find name for page %s' % page_id)
-
-class FileCache(object):
-
- def __init__(self, base=None):
- self.base = base
- self.cache = {}
-
- def get_image(self, name, attributes = ""):
- return '<img src="%s" %s>' % (name, attributes)
-
- def get_base(self):
- return self.base
-
-class TreeItem:
-
- 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
-
- def is_child(self):
- return self.children is None
-
- def deepest_item(self):
- cur = self
- if cur.repeat:
- return cur
- while cur.children:
- cur = cur.children[0]
- if cur.repeat:
- break
- return cur
-
- def get_depth(self):
- depth = 0
- current = self
- while current.parent:
- current = current.parent
- depth += 1
- return depth
-
- def find_page(self):
- cur = self
- while cur:
- if cur.next:
- return cur
- cur = cur.parent
- return None
-
- def unfold(self):
- opened = []
- cur = self
- while cur:
- cur.is_open = True
- opened.append(cur)
- cur = cur.parent
- 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
-
- icon = []
- entry = []
- if self.is_child():
- select_link = SELECT_ITEM % self.key
- 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'))))
- 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(get_image("/images/icons/navigation/folder_open.png",
- 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(get_image("/images/icons/navigation/folder_closed.png",
- 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 "")
- out.append(u'<td class="%s">' % selected)
- out.append('<span style="white-space:nowrap;">%s %s</span>'
- % (" " * (self.get_depth() - 1), "".join(icon)))
- out.append(u'</td>')
- out.append(u'<td class="%s">' % selected)
- out.append('%s' % ("".join(entry)))
- out.append(u'</td>')
-
- # Free slots for markings
- #out.append(u'<td class="%s">' % selected)
- #out.append(u'</td>')
- #out.append(u'<td class="%s">' % selected)
- #out.append(u'</td>')
-
- # Error marking
- out.append(u'<td class="%s">' % selected)
- if has_error:
- out.append('<span class="error">E</span>')
- out.append(u'</td>')
-
- out.append(u'</tr>')
- if self.is_open and self.children:
- for child in self.children:
- child.render(page, out, get_image, error_lookup)
-
- def set_open(self, flag):
- self.is_open = flag
-
- def build_error_lookup(self, lookup, error_pages):
- mark = self.name in error_pages
- if self.children:
- for child in self.children:
- if child.build_error_lookup(lookup, error_pages):
- mark = True
- if mark:
- lookup.add(self)
- return mark
-
- #def get_description_chain(self, form_data):
- # cur = self
- # descriptions = []
- # while cur:
- # if cur.description:
- # descriptions.insert(0, u"%s%s" % (
- # escape(cur.description), form_data.getHelp(cur.name)))
- # cur = cur.parent
- # return descriptions
-
- #def pureHeaders(self):
- # if self.parent:
- # for h in self.parent.pureHeaders():
- # yield h
- # if self.description:
- # yield self.description
-
- #def renderHeader(self, form_data):
- # descriptions = self.get_description_chain(form_data)
- # if not descriptions: return u""
- # out = [u'<div id="content_ueberschrift"><ul>']
- # for depth, desc in enumerate(descriptions):
- # depth = min(depth + 1, 4)
- # out.append(u'<li><h%d>%s</h%d></li>' % (depth, desc, depth))
- # out.append(u'</ul></div>')
- # return u"".join(out)
-
- def nextKey(self):
- page = self.find_page()
- if not page:
- return None
- return page.next
-
-def get_page(nc):
- meta = nc.getMeta()
- while nc:
- if isinstance(meta, PageNode):
- return meta.getName()
- nc = nc.parent
- return ""
-
-class NavigationTreeBuilder(object):
-
- def __init__(self, root, openfolders):
- self.key = root.getIdentifier()
- self.prev = None
- self.first = None
- self.openfolders = openfolders or []
- self.root = self.build(root, None)
-
- def build(self, nc, parent):
- if isinstance(nc, RepeatInstanceNode):
- # 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)
- if not self.first:
- self.first = ti
- if self.prev:
- self.prev.next = ti
- self.prev = ti
- ti.key = nc.getIdentifier()
- return ti
-
- if isinstance(nc, InstanceNode):
- children = []
- 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())
- n.repeat = True
-
- for child in nc.getChildren():
- print child.getMeta().getName()
- c = self.build(child, n)
- 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))
- if n.key in self.openfolders:
- n.set_open(True)
- return n
-
- ti = TreeItem("xxx", "Unknown Item", parent = parent)
- ti.key = nc.getIdentifier()
- return ti
-
-class NavigationTree:
-
- def __init__(self, instance, openfolders=None):
- builder = NavigationTreeBuilder(instance.getRootNode(), openfolders)
- self.root = builder.root
- self.first_page = builder.first
-
- def getAllItems(self):
- page = self.first_page
- while page:
- yield page
- page = page.next
-
- def getTreeItem(self, key):
- stack = [self.root.children]
- while stack:
- children = stack.pop()
- for c in children:
- if c.key == key:
- return c
- if c.children:
- stack.append(c.children)
- return None
-
- def findTreeItemByPageName(self, name):
- stack = [self.root.getChildren()]
- item = None
- while stack:
- children = stack.pop()
- for c in children:
- if c.name == name:
- return c
- if c.getChildren():
- stack.append(c.getChildren())
- return None
-
- 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">']
- get_image = file_cache.get_image
- for child in self.root.children:
- child.render(page, out, get_image, error_lookup)
- out.append(u"</table>")
- return u"".join(out)
-
-# vim:set ts=4 sw=4 si et sta sts=4 :
More information about the Mpuls-commits
mailing list