[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue designer/src/reports/Incubator.py designer...
From: |
Jason Cater |
Subject: |
gnue designer/src/reports/Incubator.py designer... |
Date: |
Wed, 01 Jan 2003 21:06:25 -0500 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jason Cater <address@hidden> 03/01/01 21:06:24
Modified files:
designer/src/reports: Incubator.py Instance.py
TemplateSupport.py TreeView.py
designer/src/reports/Standard: Incubator.py
reports : setup.py
reports/scripts: gnue-reports-server.in gnue-reports.in
reports/src/base: GRParser.py GRReport.py
reports/src/base/layout: ContainerElement.py GRDefault.py
GRField.py GRFirstRow.py GRFormula.py
GRLastRow.py GRLayout.py
GRLayoutElement.py GRNotFirstRow.py
GRNotLastRow.py GRParam.py
GRPassThru.py GRSection.py GRSumm.py
__init__.py
reports/src/client: GRRun.py
reports/src/server: GRServer.py
Removed files:
reports/src : GRConfig.py GRDataMapper.py GREngine.py
GRExceptions.py GRFilters.py GRLayout.py
GROutputAdapter.py GRParameters.py GRParser.py
GRReport.py GRReportInfo.py GRRun.py GRRunUI.py
GRServer.py GRServices.py GRSortOptions.py
GRSources.py
reports/src/base: GRLayout.py
Log message:
cleaning up reports structure
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/reports/Incubator.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/reports/Instance.py.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/reports/TemplateSupport.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/reports/TreeView.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/reports/Standard/Incubator.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/setup.py.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/scripts/gnue-reports-server.in.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/scripts/gnue-reports.in.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/GRParser.py.diff?tr1=1.31&tr2=1.32&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/GRReport.py.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/ContainerElement.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRDefault.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRField.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRFirstRow.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRFormula.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRLastRow.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRLayout.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRLayoutElement.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRNotFirstRow.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRNotLastRow.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRParam.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRPassThru.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRSection.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/GRSumm.py.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/base/layout/__init__.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/client/GRRun.py.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/reports/src/server/GRServer.py.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
Patches:
Index: gnue/designer/src/reports/Incubator.py
diff -c gnue/designer/src/reports/Incubator.py:1.8
gnue/designer/src/reports/Incubator.py:1.9
*** gnue/designer/src/reports/Incubator.py:1.8 Wed Jan 1 19:45:47 2003
--- gnue/designer/src/reports/Incubator.py Wed Jan 1 21:06:22 2003
***************
*** 28,34 ****
#
from gnue.common import GDebug, GParserHelpers
! from gnue.reports import GRParser, GRReport, GRLayout
from gnue.designer.base.Incubator import BaseIncubator
class Incubator(BaseIncubator):
--- 28,35 ----
#
from gnue.common import GDebug, GParserHelpers
! from gnue.reports.base import GRParser, GRReport
! from gnue.reports.base import layout as GRLayout
from gnue.designer.base.Incubator import BaseIncubator
class Incubator(BaseIncubator):
Index: gnue/designer/src/reports/Instance.py
diff -c gnue/designer/src/reports/Instance.py:1.14
gnue/designer/src/reports/Instance.py:1.15
*** gnue/designer/src/reports/Instance.py:1.14 Wed Jan 1 19:45:47 2003
--- gnue/designer/src/reports/Instance.py Wed Jan 1 21:06:22 2003
***************
*** 42,48 ****
from gnue.designer.base.tools.TriggerEditor import TriggerEditor
from gnue.designer.base.tools.EventEditor import EventEditor
! from gnue.reports import GRReport, GRParser, GRLayout, GRSources,
GRParameters, GRSortOptions
class Instance(BaseInstance):
--- 42,49 ----
from gnue.designer.base.tools.TriggerEditor import TriggerEditor
from gnue.designer.base.tools.EventEditor import EventEditor
! from gnue.reports.base import GRReport, GRParser, GRSources, GRParameters,
GRSortOptions
! from gnue.reports.base import layout as GRLayout
class Instance(BaseInstance):
Index: gnue/designer/src/reports/Standard/Incubator.py
diff -c gnue/designer/src/reports/Standard/Incubator.py:1.3
gnue/designer/src/reports/Standard/Incubator.py:1.4
*** gnue/designer/src/reports/Standard/Incubator.py:1.3 Wed Jan 1 19:45:47 2003
--- gnue/designer/src/reports/Standard/Incubator.py Wed Jan 1 21:06:22 2003
***************
*** 28,36 ****
#
from gnue.common import GDebug, GParserHelpers
! from gnue.reports import GRParser, GRReport, GRLayout
from gnue.designer.reports.Incubator import Incubator as BaseReportIncubator
class Incubator(BaseReportIncubator):
pass
!
\ No newline at end of file
--- 28,36 ----
#
from gnue.common import GDebug, GParserHelpers
! from gnue.reports.base import GRParser, GRReport, GRLayout
from gnue.designer.reports.Incubator import Incubator as BaseReportIncubator
class Incubator(BaseReportIncubator):
pass
!
Index: gnue/designer/src/reports/TemplateSupport.py
diff -c gnue/designer/src/reports/TemplateSupport.py:1.8
gnue/designer/src/reports/TemplateSupport.py:1.9
*** gnue/designer/src/reports/TemplateSupport.py:1.8 Wed Jan 1 19:45:47 2003
--- gnue/designer/src/reports/TemplateSupport.py Wed Jan 1 21:06:22 2003
***************
*** 28,34 ****
#
from gnue.designer.base.TemplateBase import *
! from gnue.reports.GRReport import GRReport
def createRootObject(instance):
--- 28,34 ----
#
from gnue.designer.base.TemplateBase import *
! from gnue.reports.base.GRReport import GRReport
def createRootObject(instance):
Index: gnue/designer/src/reports/TreeView.py
diff -c gnue/designer/src/reports/TreeView.py:1.5
gnue/designer/src/reports/TreeView.py:1.6
*** gnue/designer/src/reports/TreeView.py:1.5 Wed Jan 1 19:45:47 2003
--- gnue/designer/src/reports/TreeView.py Wed Jan 1 21:06:22 2003
***************
*** 30,36 ****
import sys, os
from wxPython.wx import *
from gnue.common import GDebug
! from gnue.reports import GRReport, GRLayout, GRSources, GRParameters,
GRSortOptions
from gnue.designer.base.PopupMenu import ObjectMenu
from gnue.designer.base.Icons import treeIconMap, treeIconList
from gnue.designer.base.tools.TreeView import TreeView as BaseTreeView
--- 30,37 ----
import sys, os
from wxPython.wx import *
from gnue.common import GDebug
! from gnue.reports.base import GRReport, GRLayout, GRSources, GRParameters,
GRSortOptions
! from gnue.reports.base import layout as GRLayout
from gnue.designer.base.PopupMenu import ObjectMenu
from gnue.designer.base.Icons import treeIconMap, treeIconList
from gnue.designer.base.tools.TreeView import TreeView as BaseTreeView
Index: gnue/reports/scripts/gnue-reports-server.in
diff -c gnue/reports/scripts/gnue-reports-server.in:1.2
gnue/reports/scripts/gnue-reports-server.in:1.3
*** gnue/reports/scripts/gnue-reports-server.in:1.2 Wed Jan 1 19:45:49 2003
--- gnue/reports/scripts/gnue-reports-server.in Wed Jan 1 21:06:23 2003
***************
*** 29,36 ****
if os.path.isfile(INST_GNUE_CONNECTIONS):
os.environ['GNUE_CONNECTIONS'] = INST_GNUE_CONNECTIONS
! from gnue.reports.GRRun import GRRun
if __name__ == '__main__':
GRServer().run()
!
--- 29,36 ----
if os.path.isfile(INST_GNUE_CONNECTIONS):
os.environ['GNUE_CONNECTIONS'] = INST_GNUE_CONNECTIONS
! from gnue.reports.server.GRServer import GRServer
if __name__ == '__main__':
GRServer().run()
!
Index: gnue/reports/scripts/gnue-reports.in
diff -c gnue/reports/scripts/gnue-reports.in:1.2
gnue/reports/scripts/gnue-reports.in:1.3
*** gnue/reports/scripts/gnue-reports.in:1.2 Wed Jan 1 19:45:49 2003
--- gnue/reports/scripts/gnue-reports.in Wed Jan 1 21:06:23 2003
***************
*** 29,36 ****
if os.path.isfile(INST_GNUE_CONNECTIONS):
os.environ['GNUE_CONNECTIONS'] = INST_GNUE_CONNECTIONS
! from gnue.reports.GRRun import GRRun
if __name__ == '__main__':
GRRun().run()
!
--- 29,36 ----
if os.path.isfile(INST_GNUE_CONNECTIONS):
os.environ['GNUE_CONNECTIONS'] = INST_GNUE_CONNECTIONS
! from gnue.reports.client.GRRun import GRRun
if __name__ == '__main__':
GRRun().run()
!
Index: gnue/reports/setup.py
diff -c gnue/reports/setup.py:1.23 gnue/reports/setup.py:1.24
*** gnue/reports/setup.py:1.23 Wed Jan 1 19:45:48 2003
--- gnue/reports/setup.py Wed Jan 1 21:06:22 2003
***************
*** 240,245 ****
--- 240,249 ----
) ],
packages = ["gnue.reports",
+ "gnue.reports.base",
+ "gnue.reports.base.layout",
+ "gnue.reports.client",
+ "gnue.reports.server",
"gnue.reports.adapters",
"gnue.reports.adapters.filters",
"gnue.reports.adapters.filters.general",
Index: gnue/reports/src/base/GRParser.py
diff -c gnue/reports/src/base/GRParser.py:1.31
gnue/reports/src/base/GRParser.py:1.32
*** gnue/reports/src/base/GRParser.py:1.31 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/GRParser.py Wed Jan 1 21:06:23 2003
***************
*** 29,35 ****
# HISTORY:
#
! import GRReport, GRSources, GRParameters, GRSortOptions, GRLayout
from gnue.common import GDataSource, GTypecast, GParser, GTrigger
import copy, types
--- 29,36 ----
# HISTORY:
#
! from gnue.reports.base import GRReport, GRSources, GRParameters, GRSortOptions
! from gnue.reports.base import layout as GRLayout
from gnue.common import GDataSource, GTypecast, GParser, GTrigger
import copy, types
Index: gnue/reports/src/base/GRReport.py
diff -c gnue/reports/src/base/GRReport.py:1.32
gnue/reports/src/base/GRReport.py:1.33
*** gnue/reports/src/base/GRReport.py:1.32 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/GRReport.py Wed Jan 1 21:06:23 2003
***************
*** 37,43 ****
import sys
import GRParser
import GRParameters
! import GRLayout
import GRSortOptions
import GRSources
import GRExceptions
--- 37,43 ----
import sys
import GRParser
import GRParameters
! import layout as GRLayout
import GRSortOptions
import GRSources
import GRExceptions
Index: gnue/reports/src/base/layout/ContainerElement.py
diff -c gnue/reports/src/base/layout/ContainerElement.py:1.51
gnue/reports/src/base/layout/ContainerElement.py:1.52
*** gnue/reports/src/base/layout/ContainerElement.py:1.51 Wed Jan 1
19:45:49 2003
--- gnue/reports/src/base/layout/ContainerElement.py Wed Jan 1 21:06:23 2003
***************
*** 36,259 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
############################################################
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from GRLayoutElement import GRLayoutElement
############################################################
***************
*** 325,656 ****
return self._parent.getAncestorWithSource(source)
else:
return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
-
--- 108,110 ----
Index: gnue/reports/src/base/layout/GRDefault.py
diff -c gnue/reports/src/base/layout/GRDefault.py:1.51
gnue/reports/src/base/layout/GRDefault.py:1.52
*** gnue/reports/src/base/layout/GRDefault.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRDefault.py Wed Jan 1 21:06:23 2003
***************
*** 38,452 ****
from xml.sax import saxutils
- ############################################################
- #
- # Used to send structural comment
- # Chose not to do "if COMMENT == 1: dest.write"
- # for performance reasons # TODO: Was this a good decision?
- #
- def _structuralComment(dest, text):
- dest.write(text)
-
- def _noStructuralComment(dest, text):
- pass
-
- structuralComment = _noStructuralComment
-
-
- ############################################################
- #
- # GRLayout
- #
- class GRLayout (GObj):
- def __init__(self, parent):
- GObj.__init__(self, parent, type='GRLayout')
- self._inits = (self.initialize,)
- self.suppressGNUeTags = 0
-
- def initialize(self):
- # Find the xml namespace in use by any child passthru objects
- # If there is more than one object attached to a layout
- # object, then create an unbound section to contain them.
- # This is a convenience for the layout engine code :)
-
- if len(self._children) > 1 or \
- ( len(self._children) and \
- self._children[0]._type != 'GRSection' ):
-
- temp = self._children[:]
- self._children = []
- section = GRSection(self)
- section._children = temp
- section._buildObject()
- elif len(self._children) == 0:
- raise GRExceptions.NoLayoutDefined, \
- "The layout section does not contain any instructions. What do I do?"
-
- self._xmlchildnamespace = self._findNamespace()
- self._parent._namespace = self._xmlchildnamespace
-
-
- # Find the xml namespace in use by any child passthru objects
- def _findNamespace(self, object=None):
- if object==None: object = self
- for child in object._children:
- try:
- if child._xmlnamespace:
- namespace = child._xmlnamespace
- else:
- namespace = self._findNamespace(child)
- if namespace:
- return namespace
- except AttributeError:
- pass
-
-
- #
- # Prepare for running
- #
- def prepare(self, mapper, parameters):
-
- self._mapper = mapper
- self._parameters = parameters
- self.walk(self.__prepare)
-
- # Used by prepare()
- def __prepare(self, object):
- if isinstance(object, GRLayoutElement):
-
- # This all looks confusing, but basically it simply figures out
- # what section a field or summary actually pulls from and also
- # makes sure a section, field, or summary isn't trying to use
- # a source outside of the source's scope. After it's satisfied
- # with the results, it adds the element to the mapper object.
-
- # TODO: This can probably be simplified by moving
- # TODO: the various functions to the actual child
- # TODO: object's phaseInits.
-
- parentSection = object.findParentOfType('GRSection',includeSelf=0)
-
- if isinstance(object, GRSection) and object._source != None:
- if parentSection is None:
- self._mapper.addSection(object._name, object._source, None)
- else:
- self._mapper.addSection(object._name,
- object._source,
- parentSection._name)
- object._mymapper = self._mapper.sectionMap[object._name]
- object._mymapper._object = object
-
- elif isinstance(object, GRField):
- s = parentSection.getAncestorWithSource(object._source)
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object.name, parentSection._name, object._source)
-
- object._section = s._name
-
- if hasattr(object,'section') and object.section:
- sec = string.lower(object.section)
- curr = s
- section = None
- while curr:
- if curr._name == sec:
- section = curr
- break
- curr = curr._parent.findParentOfType('GRSection')
-
- if section == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
- % (object.name, parentSection._name, object.section)
-
- object._section = section._name
-
- object._mymapper = self._mapper.sectionMap[object._section]
-
- GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
- % (object.name, object._section))
- self._mapper.addFieldToSection(object._section, object.name)
-
- elif isinstance(object, GRSumm):
- if object.section == None:
- s = object._parent.findParentOfType('GRSection')
- else:
- sec = string.lower(object.section)
- s = self._mapper.sectionMap[sec]._object
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object._field, object._parent.name, object._source)
-
- object._section = s._name
- object._mymapper = self._mapper.sectionMap[s._name]
-
- GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
- % (object._field, object.function, object._section))
- self._mapper.addSummaryToSection(object.function,
- object._section, object._field)
-
-
- #
- # Process layout and dump output.
- # self.prepare *must* be called prior to processing
- #
- def process(self, dest, includeStructuralComments=0):
-
- global structuralComment
- if includeStructuralComments:
- structuralComment = _structuralComment
-
- for child in self._children:
- structuralComment(dest, '<!-- [layout] -->')
- child.processAsController(dest, self._mapper)
- structuralComment(dest, '<!-- [/layout] -->\n')
-
-
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # inherit GRLayoutElement
- #
- class GRLayoutElement (GObj,GTriggerExtension):
- def __init__(self, parent=None, type='GRLayoutElement'):
- GTriggerExtension.__init__(self)
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
- self._inits = [self.primaryInit]
-
- # Called if section contains data
- def process(self, dest, *args, **parms):
- tag = self.getXmlTag()
- attrs = ""
- for attr in self.__dict__.keys():
- try: prefix, att = attr.split('__',1)
- except: continue
-
- if prefix in self._xmlnamespaces.keys():
- attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
-
- dest.write('<%s%s>' % (tag, attrs))
- rv = self._process(dest, *args, **parms)
- dest.write('</%s>' % tag)
-
- return rv
-
- # Called if section contains data (the non-namespace version)
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
- def primaryInit(self):
- if hasattr(self,'source') and self.source is not None:
- self._source = self.source
- else:
- try:
- self._source = self._parent._source
- except AttributeError:
- self._source = None
-
- if not self._xmlnamespaces:
- # Avoid any overhead if this element doesn't
- # contain namespace-qualified attributes
- self.process = self._process
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # that can themselves be containers
- #
- class ContainerElement (GRLayoutElement):
- def __init__(self, parent=None, type='GRContainerElement'):
- GRLayoutElement.__init__(self, parent, type=type)
- # TODO: remove.. this is for debugging
- self._name = "untitled"
-
-
- # Process all children, handling GRSections properly
- def processChildren(self, dest, mapper,
- isfirst, islast, firstSection, nextSection):
-
- first = isfirst or self._type == 'GRSection'
-
- while 1:
- if isinstance(self, GRSection) :
- self.processTrigger('On-Process')
-
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- else:
- # Handle GRSections specially as
- # they require extra logic
- if isinstance(child, GRSection):
- # If this is the top-most section for a datasource,
- # it needs to be called with processAsController.
- if child._mymapper.toplevel:
-
- GDebug.printMesg(10, "Calling new controlling section")
- child.processAsController(dest, mapper)
-
- # ..otherwise call the GRSection's process method.
- else:
- nextSection = child.process(dest, mapper,isfirst=1,
- islast=(nextSection == None) or \
- (nextSection._name not in
(child._childSections)),
- firstSection=firstSection,
nextSection=nextSection)
- # Don't allow the processing to enter trigger objects
- elif isinstance(child, GTrigger):
- pass
- else:
- # Handle the layout element.
- nextSection = child.process(dest, mapper, first, islast,
- firstSection, nextSection)
-
- first = 0
-
- if nextSection == self:
- firstSection, nextSection = self.getGotos(mapper)
- islast = (nextSection == None)
- else:
- break
-
- return nextSection
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
############################################################
#
--- 38,43 ----
***************
*** 474,656 ****
def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 65,68 ----
Index: gnue/reports/src/base/layout/GRField.py
diff -c gnue/reports/src/base/layout/GRField.py:1.51
gnue/reports/src/base/layout/GRField.py:1.52
*** gnue/reports/src/base/layout/GRField.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRField.py Wed Jan 1 21:06:23 2003
***************
*** 36,480 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
!
! ############################################################
! #
! # <section> tag
! #
! class GRSection (ContainerElement):
!
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRSection')
! self._childSections = []
! self._validTriggers = {'PRE-SECTION':'Pre-Section',
! 'POST-SECTION':'Post-Section',
! 'ON-PROCESS':'On-Process'}
!
! def _buildObject(self):
! if not hasattr(self,'name') or self.name == None:
! self._name = id(self)
! else:
! self._name = string.lower(self.name)
!
! # Keep track of "child" section names (for the firstRow stuff)
! psec = self._parent.findParentOfType('GRSection')
! if psec is not None:
! psec._childSections = self._childSections[:]
! psec._childSections.insert(0, self._name)
!
! return ContainerElement._buildObject(self)
!
!
! #
! # Retrieve the first row of data, if available.
! # Handle default data if no rows retrieved.
! #
! def processAsController(self, dest, mapper):
!
! GDebug.printMesg(10,
! "Controlling section %s's processAsController() called" % self._name)
!
! if self._source == None:
! # This is a dataless section...
! # simply process it's children
!
! self.process(dest, mapper, 1, 1, None, None)
!
! else:
! firstSection, nextSection = self.getGotos(mapper, 1)
!
! if firstSection:
! # This is a data-bound section and there
! # was data returned, so process section
! self.process(dest, mapper, 1, nextSection == None, self, nextSection)
!
! else:
! # This is a data-bound section and there
! # was no data returned, so generate default
! # text (if any)
!
! for c2 in self._children:
! if isinstance (c2, GRDefault):
! c2.processDefault(dest, mapper)
!
!
!
! #
! # Used internally to determine next section to move
! #
! def getGotos(self, mapper, init=0):
! # Determine the next section to process our data.
! # (i.e., handle section grouping)
! if init:
! goto, gotoNext = mapper.getFirstRecord(self._source)
! else:
! goto, gotoNext = mapper.getNextRecord(self._source)
!
! # Get the actual GRSection objects
! if not goto:
! return (None, None)
!
! firstSection = mapper.sectionMap[goto]._object
! if gotoNext:
! nextSection = mapper.sectionMap[gotoNext]._object
! else:
! nextSection = None
!
! # And return them
! return (firstSection, nextSection)
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if self._source == source:
! return self
! elif isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
! # Generic process() method. Process the
! # current record and handle any children.
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! self.processTrigger('Pre-Section')
! GDebug.printMesg(10,"Repeating Section %s" % self._name)
! structuralComment(dest,"<!-- [section:%s] -->" % self._name)
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
!
! try:
!
! structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
! mapper.sectionMap[self.name]._clearOnNextSet = 1
! except KeyError:
! pass
!
! structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
! GDebug.printMesg(10,"Leaving section %s" % self._name)
! self.processTrigger('Post-Section')
! return nextSection
!
!
! ############################################################
! #
! # <default> tag
! # Text in this tag is only displayed if datasource
! # returns no data. Note: this will be the only thing
! # in the section that will be displayed.
! #
! class GRDefault (GObj):
! def __init__(self, parent=None, type='GRDefault'):
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
!
! def processDefault(self, dest, mapper):
! structuralComment(dest,"<!-- [default] -->")
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! structuralComment(dest,"<!-- [/default] -->")
!
! def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
! return nextSection
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
############################################################
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from GRLayoutElement import GRLayoutElement
############################################################
***************
*** 493,656 ****
self.format)), '\r',''))
structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
-
--- 55,57 ----
Index: gnue/reports/src/base/layout/GRFirstRow.py
diff -c gnue/reports/src/base/layout/GRFirstRow.py:1.51
gnue/reports/src/base/layout/GRFirstRow.py:1.52
*** gnue/reports/src/base/layout/GRFirstRow.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRFirstRow.py Wed Jan 1 21:06:23 2003
***************
*** 36,591 ****
import GRExceptions
import string
from xml.sax import saxutils
- ############################################################
- #
- # Used to send structural comment
- # Chose not to do "if COMMENT == 1: dest.write"
- # for performance reasons # TODO: Was this a good decision?
- #
- def _structuralComment(dest, text):
- dest.write(text)
-
- def _noStructuralComment(dest, text):
- pass
-
- structuralComment = _noStructuralComment
-
-
- ############################################################
- #
- # GRLayout
- #
- class GRLayout (GObj):
- def __init__(self, parent):
- GObj.__init__(self, parent, type='GRLayout')
- self._inits = (self.initialize,)
- self.suppressGNUeTags = 0
-
- def initialize(self):
- # Find the xml namespace in use by any child passthru objects
- # If there is more than one object attached to a layout
- # object, then create an unbound section to contain them.
- # This is a convenience for the layout engine code :)
-
- if len(self._children) > 1 or \
- ( len(self._children) and \
- self._children[0]._type != 'GRSection' ):
-
- temp = self._children[:]
- self._children = []
- section = GRSection(self)
- section._children = temp
- section._buildObject()
- elif len(self._children) == 0:
- raise GRExceptions.NoLayoutDefined, \
- "The layout section does not contain any instructions. What do I do?"
-
- self._xmlchildnamespace = self._findNamespace()
- self._parent._namespace = self._xmlchildnamespace
-
-
- # Find the xml namespace in use by any child passthru objects
- def _findNamespace(self, object=None):
- if object==None: object = self
- for child in object._children:
- try:
- if child._xmlnamespace:
- namespace = child._xmlnamespace
- else:
- namespace = self._findNamespace(child)
- if namespace:
- return namespace
- except AttributeError:
- pass
-
-
- #
- # Prepare for running
- #
- def prepare(self, mapper, parameters):
-
- self._mapper = mapper
- self._parameters = parameters
- self.walk(self.__prepare)
-
- # Used by prepare()
- def __prepare(self, object):
- if isinstance(object, GRLayoutElement):
-
- # This all looks confusing, but basically it simply figures out
- # what section a field or summary actually pulls from and also
- # makes sure a section, field, or summary isn't trying to use
- # a source outside of the source's scope. After it's satisfied
- # with the results, it adds the element to the mapper object.
-
- # TODO: This can probably be simplified by moving
- # TODO: the various functions to the actual child
- # TODO: object's phaseInits.
-
- parentSection = object.findParentOfType('GRSection',includeSelf=0)
-
- if isinstance(object, GRSection) and object._source != None:
- if parentSection is None:
- self._mapper.addSection(object._name, object._source, None)
- else:
- self._mapper.addSection(object._name,
- object._source,
- parentSection._name)
- object._mymapper = self._mapper.sectionMap[object._name]
- object._mymapper._object = object
-
- elif isinstance(object, GRField):
- s = parentSection.getAncestorWithSource(object._source)
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object.name, parentSection._name, object._source)
-
- object._section = s._name
-
- if hasattr(object,'section') and object.section:
- sec = string.lower(object.section)
- curr = s
- section = None
- while curr:
- if curr._name == sec:
- section = curr
- break
- curr = curr._parent.findParentOfType('GRSection')
-
- if section == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
- % (object.name, parentSection._name, object.section)
-
- object._section = section._name
-
- object._mymapper = self._mapper.sectionMap[object._section]
-
- GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
- % (object.name, object._section))
- self._mapper.addFieldToSection(object._section, object.name)
-
- elif isinstance(object, GRSumm):
- if object.section == None:
- s = object._parent.findParentOfType('GRSection')
- else:
- sec = string.lower(object.section)
- s = self._mapper.sectionMap[sec]._object
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object._field, object._parent.name, object._source)
-
- object._section = s._name
- object._mymapper = self._mapper.sectionMap[s._name]
-
- GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
- % (object._field, object.function, object._section))
- self._mapper.addSummaryToSection(object.function,
- object._section, object._field)
-
-
- #
- # Process layout and dump output.
- # self.prepare *must* be called prior to processing
- #
- def process(self, dest, includeStructuralComments=0):
-
- global structuralComment
- if includeStructuralComments:
- structuralComment = _structuralComment
-
- for child in self._children:
- structuralComment(dest, '<!-- [layout] -->')
- child.processAsController(dest, self._mapper)
- structuralComment(dest, '<!-- [/layout] -->\n')
-
-
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # inherit GRLayoutElement
- #
- class GRLayoutElement (GObj,GTriggerExtension):
- def __init__(self, parent=None, type='GRLayoutElement'):
- GTriggerExtension.__init__(self)
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
- self._inits = [self.primaryInit]
-
- # Called if section contains data
- def process(self, dest, *args, **parms):
- tag = self.getXmlTag()
- attrs = ""
- for attr in self.__dict__.keys():
- try: prefix, att = attr.split('__',1)
- except: continue
-
- if prefix in self._xmlnamespaces.keys():
- attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
-
- dest.write('<%s%s>' % (tag, attrs))
- rv = self._process(dest, *args, **parms)
- dest.write('</%s>' % tag)
-
- return rv
-
- # Called if section contains data (the non-namespace version)
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
- def primaryInit(self):
- if hasattr(self,'source') and self.source is not None:
- self._source = self.source
- else:
- try:
- self._source = self._parent._source
- except AttributeError:
- self._source = None
-
- if not self._xmlnamespaces:
- # Avoid any overhead if this element doesn't
- # contain namespace-qualified attributes
- self.process = self._process
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # that can themselves be containers
- #
- class ContainerElement (GRLayoutElement):
- def __init__(self, parent=None, type='GRContainerElement'):
- GRLayoutElement.__init__(self, parent, type=type)
- # TODO: remove.. this is for debugging
- self._name = "untitled"
-
-
- # Process all children, handling GRSections properly
- def processChildren(self, dest, mapper,
- isfirst, islast, firstSection, nextSection):
-
- first = isfirst or self._type == 'GRSection'
-
- while 1:
- if isinstance(self, GRSection) :
- self.processTrigger('On-Process')
-
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- else:
- # Handle GRSections specially as
- # they require extra logic
- if isinstance(child, GRSection):
- # If this is the top-most section for a datasource,
- # it needs to be called with processAsController.
- if child._mymapper.toplevel:
-
- GDebug.printMesg(10, "Calling new controlling section")
- child.processAsController(dest, mapper)
-
- # ..otherwise call the GRSection's process method.
- else:
- nextSection = child.process(dest, mapper,isfirst=1,
- islast=(nextSection == None) or \
- (nextSection._name not in
(child._childSections)),
- firstSection=firstSection,
nextSection=nextSection)
- # Don't allow the processing to enter trigger objects
- elif isinstance(child, GTrigger):
- pass
- else:
- # Handle the layout element.
- nextSection = child.process(dest, mapper, first, islast,
- firstSection, nextSection)
-
- first = 0
-
- if nextSection == self:
- firstSection, nextSection = self.getGotos(mapper)
- islast = (nextSection == None)
- else:
- break
-
- return nextSection
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
class GRFirstRow(ContainerElement):
def __init__(self, parent):
ContainerElement.__init__(self, parent, 'GRFirstRow')
--- 36,44 ----
import GRExceptions
import string
from xml.sax import saxutils
+ from ContainerElement import ContainerElement
class GRFirstRow(ContainerElement):
def __init__(self, parent):
ContainerElement.__init__(self, parent, 'GRFirstRow')
***************
*** 594,656 ****
if isfirst:
nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
-
--- 47,49 ----
Index: gnue/reports/src/base/layout/GRFormula.py
diff -c gnue/reports/src/base/layout/GRFormula.py:1.51
gnue/reports/src/base/layout/GRFormula.py:1.52
*** gnue/reports/src/base/layout/GRFormula.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRFormula.py Wed Jan 1 21:06:23 2003
***************
*** 36,499 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
!
! ############################################################
! #
! # <section> tag
! #
! class GRSection (ContainerElement):
!
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRSection')
! self._childSections = []
! self._validTriggers = {'PRE-SECTION':'Pre-Section',
! 'POST-SECTION':'Post-Section',
! 'ON-PROCESS':'On-Process'}
!
! def _buildObject(self):
! if not hasattr(self,'name') or self.name == None:
! self._name = id(self)
! else:
! self._name = string.lower(self.name)
!
! # Keep track of "child" section names (for the firstRow stuff)
! psec = self._parent.findParentOfType('GRSection')
! if psec is not None:
! psec._childSections = self._childSections[:]
! psec._childSections.insert(0, self._name)
!
! return ContainerElement._buildObject(self)
!
!
! #
! # Retrieve the first row of data, if available.
! # Handle default data if no rows retrieved.
! #
! def processAsController(self, dest, mapper):
!
! GDebug.printMesg(10,
! "Controlling section %s's processAsController() called" % self._name)
!
! if self._source == None:
! # This is a dataless section...
! # simply process it's children
!
! self.process(dest, mapper, 1, 1, None, None)
!
! else:
! firstSection, nextSection = self.getGotos(mapper, 1)
!
! if firstSection:
! # This is a data-bound section and there
! # was data returned, so process section
! self.process(dest, mapper, 1, nextSection == None, self, nextSection)
!
! else:
! # This is a data-bound section and there
! # was no data returned, so generate default
! # text (if any)
!
! for c2 in self._children:
! if isinstance (c2, GRDefault):
! c2.processDefault(dest, mapper)
!
!
!
! #
! # Used internally to determine next section to move
! #
! def getGotos(self, mapper, init=0):
! # Determine the next section to process our data.
! # (i.e., handle section grouping)
! if init:
! goto, gotoNext = mapper.getFirstRecord(self._source)
! else:
! goto, gotoNext = mapper.getNextRecord(self._source)
!
! # Get the actual GRSection objects
! if not goto:
! return (None, None)
!
! firstSection = mapper.sectionMap[goto]._object
! if gotoNext:
! nextSection = mapper.sectionMap[gotoNext]._object
! else:
! nextSection = None
!
! # And return them
! return (firstSection, nextSection)
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if self._source == source:
! return self
! elif isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
! # Generic process() method. Process the
! # current record and handle any children.
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! self.processTrigger('Pre-Section')
! GDebug.printMesg(10,"Repeating Section %s" % self._name)
! structuralComment(dest,"<!-- [section:%s] -->" % self._name)
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
!
! try:
!
! structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
! mapper.sectionMap[self.name]._clearOnNextSet = 1
! except KeyError:
! pass
!
! structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
! GDebug.printMesg(10,"Leaving section %s" % self._name)
! self.processTrigger('Post-Section')
! return nextSection
!
!
! ############################################################
! #
! # <default> tag
! # Text in this tag is only displayed if datasource
! # returns no data. Note: this will be the only thing
! # in the section that will be displayed.
! #
! class GRDefault (GObj):
! def __init__(self, parent=None, type='GRDefault'):
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
!
! def processDefault(self, dest, mapper):
! structuralComment(dest,"<!-- [default] -->")
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! structuralComment(dest,"<!-- [/default] -->")
!
! def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
! return nextSection
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
!
!
! ############################################################
! #
! # <field> tag
! #
! class GRField (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRField')
! self._section = None
! self.format = None
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [field:%s] -->" % self.name)
! dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
! self.format)), '\r',''))
! structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
! return nextSection
!
############################################################
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from GRLayoutElement import GRLayoutElement
############################################################
Index: gnue/reports/src/base/layout/GRLastRow.py
diff -c gnue/reports/src/base/layout/GRLastRow.py:1.51
gnue/reports/src/base/layout/GRLastRow.py:1.52
*** gnue/reports/src/base/layout/GRLastRow.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRLastRow.py Wed Jan 1 21:06:23 2003
***************
*** 36,611 ****
import GRExceptions
import string
from xml.sax import saxutils
- ############################################################
- #
- # Used to send structural comment
- # Chose not to do "if COMMENT == 1: dest.write"
- # for performance reasons # TODO: Was this a good decision?
- #
- def _structuralComment(dest, text):
- dest.write(text)
-
- def _noStructuralComment(dest, text):
- pass
-
- structuralComment = _noStructuralComment
-
-
- ############################################################
- #
- # GRLayout
- #
- class GRLayout (GObj):
- def __init__(self, parent):
- GObj.__init__(self, parent, type='GRLayout')
- self._inits = (self.initialize,)
- self.suppressGNUeTags = 0
-
- def initialize(self):
- # Find the xml namespace in use by any child passthru objects
- # If there is more than one object attached to a layout
- # object, then create an unbound section to contain them.
- # This is a convenience for the layout engine code :)
-
- if len(self._children) > 1 or \
- ( len(self._children) and \
- self._children[0]._type != 'GRSection' ):
-
- temp = self._children[:]
- self._children = []
- section = GRSection(self)
- section._children = temp
- section._buildObject()
- elif len(self._children) == 0:
- raise GRExceptions.NoLayoutDefined, \
- "The layout section does not contain any instructions. What do I do?"
-
- self._xmlchildnamespace = self._findNamespace()
- self._parent._namespace = self._xmlchildnamespace
-
-
- # Find the xml namespace in use by any child passthru objects
- def _findNamespace(self, object=None):
- if object==None: object = self
- for child in object._children:
- try:
- if child._xmlnamespace:
- namespace = child._xmlnamespace
- else:
- namespace = self._findNamespace(child)
- if namespace:
- return namespace
- except AttributeError:
- pass
-
-
- #
- # Prepare for running
- #
- def prepare(self, mapper, parameters):
-
- self._mapper = mapper
- self._parameters = parameters
- self.walk(self.__prepare)
-
- # Used by prepare()
- def __prepare(self, object):
- if isinstance(object, GRLayoutElement):
-
- # This all looks confusing, but basically it simply figures out
- # what section a field or summary actually pulls from and also
- # makes sure a section, field, or summary isn't trying to use
- # a source outside of the source's scope. After it's satisfied
- # with the results, it adds the element to the mapper object.
-
- # TODO: This can probably be simplified by moving
- # TODO: the various functions to the actual child
- # TODO: object's phaseInits.
-
- parentSection = object.findParentOfType('GRSection',includeSelf=0)
-
- if isinstance(object, GRSection) and object._source != None:
- if parentSection is None:
- self._mapper.addSection(object._name, object._source, None)
- else:
- self._mapper.addSection(object._name,
- object._source,
- parentSection._name)
- object._mymapper = self._mapper.sectionMap[object._name]
- object._mymapper._object = object
-
- elif isinstance(object, GRField):
- s = parentSection.getAncestorWithSource(object._source)
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object.name, parentSection._name, object._source)
-
- object._section = s._name
-
- if hasattr(object,'section') and object.section:
- sec = string.lower(object.section)
- curr = s
- section = None
- while curr:
- if curr._name == sec:
- section = curr
- break
- curr = curr._parent.findParentOfType('GRSection')
-
- if section == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
- % (object.name, parentSection._name, object.section)
-
- object._section = section._name
-
- object._mymapper = self._mapper.sectionMap[object._section]
-
- GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
- % (object.name, object._section))
- self._mapper.addFieldToSection(object._section, object.name)
-
- elif isinstance(object, GRSumm):
- if object.section == None:
- s = object._parent.findParentOfType('GRSection')
- else:
- sec = string.lower(object.section)
- s = self._mapper.sectionMap[sec]._object
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object._field, object._parent.name, object._source)
-
- object._section = s._name
- object._mymapper = self._mapper.sectionMap[s._name]
-
- GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
- % (object._field, object.function, object._section))
- self._mapper.addSummaryToSection(object.function,
- object._section, object._field)
-
-
- #
- # Process layout and dump output.
- # self.prepare *must* be called prior to processing
- #
- def process(self, dest, includeStructuralComments=0):
-
- global structuralComment
- if includeStructuralComments:
- structuralComment = _structuralComment
-
- for child in self._children:
- structuralComment(dest, '<!-- [layout] -->')
- child.processAsController(dest, self._mapper)
- structuralComment(dest, '<!-- [/layout] -->\n')
-
-
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # inherit GRLayoutElement
- #
- class GRLayoutElement (GObj,GTriggerExtension):
- def __init__(self, parent=None, type='GRLayoutElement'):
- GTriggerExtension.__init__(self)
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
- self._inits = [self.primaryInit]
-
- # Called if section contains data
- def process(self, dest, *args, **parms):
- tag = self.getXmlTag()
- attrs = ""
- for attr in self.__dict__.keys():
- try: prefix, att = attr.split('__',1)
- except: continue
-
- if prefix in self._xmlnamespaces.keys():
- attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
-
- dest.write('<%s%s>' % (tag, attrs))
- rv = self._process(dest, *args, **parms)
- dest.write('</%s>' % tag)
-
- return rv
-
- # Called if section contains data (the non-namespace version)
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
- def primaryInit(self):
- if hasattr(self,'source') and self.source is not None:
- self._source = self.source
- else:
- try:
- self._source = self._parent._source
- except AttributeError:
- self._source = None
-
- if not self._xmlnamespaces:
- # Avoid any overhead if this element doesn't
- # contain namespace-qualified attributes
- self.process = self._process
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # that can themselves be containers
- #
- class ContainerElement (GRLayoutElement):
- def __init__(self, parent=None, type='GRContainerElement'):
- GRLayoutElement.__init__(self, parent, type=type)
- # TODO: remove.. this is for debugging
- self._name = "untitled"
-
-
- # Process all children, handling GRSections properly
- def processChildren(self, dest, mapper,
- isfirst, islast, firstSection, nextSection):
-
- first = isfirst or self._type == 'GRSection'
-
- while 1:
- if isinstance(self, GRSection) :
- self.processTrigger('On-Process')
-
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- else:
- # Handle GRSections specially as
- # they require extra logic
- if isinstance(child, GRSection):
- # If this is the top-most section for a datasource,
- # it needs to be called with processAsController.
- if child._mymapper.toplevel:
-
- GDebug.printMesg(10, "Calling new controlling section")
- child.processAsController(dest, mapper)
-
- # ..otherwise call the GRSection's process method.
- else:
- nextSection = child.process(dest, mapper,isfirst=1,
- islast=(nextSection == None) or \
- (nextSection._name not in
(child._childSections)),
- firstSection=firstSection,
nextSection=nextSection)
- # Don't allow the processing to enter trigger objects
- elif isinstance(child, GTrigger):
- pass
- else:
- # Handle the layout element.
- nextSection = child.process(dest, mapper, first, islast,
- firstSection, nextSection)
-
- first = 0
-
- if nextSection == self:
- firstSection, nextSection = self.getGotos(mapper)
- islast = (nextSection == None)
- else:
- break
-
- return nextSection
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
class GRLastRow(ContainerElement):
def __init__(self, parent):
--- 36,44 ----
import GRExceptions
import string
from xml.sax import saxutils
+ from ContainerElement import ContainerElement
class GRLastRow(ContainerElement):
def __init__(self, parent):
***************
*** 615,656 ****
if islast:
nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 48,51 ----
Index: gnue/reports/src/base/layout/GRLayout.py
diff -c gnue/reports/src/base/layout/GRLayout.py:1.51
gnue/reports/src/base/layout/GRLayout.py:1.52
*** gnue/reports/src/base/layout/GRLayout.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRLayout.py Wed Jan 1 21:06:24 2003
***************
*** 40,60 ****
############################################################
#
- # Used to send structural comment
- # Chose not to do "if COMMENT == 1: dest.write"
- # for performance reasons # TODO: Was this a good decision?
- #
- def _structuralComment(dest, text):
- dest.write(text)
-
- def _noStructuralComment(dest, text):
- pass
-
- structuralComment = _noStructuralComment
-
-
- ############################################################
- #
# GRLayout
#
class GRLayout (GObj):
--- 40,45 ----
***************
*** 204,656 ****
structuralComment(dest, '<!-- [/layout] -->\n')
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # inherit GRLayoutElement
- #
- class GRLayoutElement (GObj,GTriggerExtension):
- def __init__(self, parent=None, type='GRLayoutElement'):
- GTriggerExtension.__init__(self)
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
- self._inits = [self.primaryInit]
-
- # Called if section contains data
- def process(self, dest, *args, **parms):
- tag = self.getXmlTag()
- attrs = ""
- for attr in self.__dict__.keys():
- try: prefix, att = attr.split('__',1)
- except: continue
-
- if prefix in self._xmlnamespaces.keys():
- attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
-
- dest.write('<%s%s>' % (tag, attrs))
- rv = self._process(dest, *args, **parms)
- dest.write('</%s>' % tag)
-
- return rv
-
- # Called if section contains data (the non-namespace version)
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
- def primaryInit(self):
- if hasattr(self,'source') and self.source is not None:
- self._source = self.source
- else:
- try:
- self._source = self._parent._source
- except AttributeError:
- self._source = None
-
- if not self._xmlnamespaces:
- # Avoid any overhead if this element doesn't
- # contain namespace-qualified attributes
- self.process = self._process
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # that can themselves be containers
- #
- class ContainerElement (GRLayoutElement):
- def __init__(self, parent=None, type='GRContainerElement'):
- GRLayoutElement.__init__(self, parent, type=type)
- # TODO: remove.. this is for debugging
- self._name = "untitled"
-
-
- # Process all children, handling GRSections properly
- def processChildren(self, dest, mapper,
- isfirst, islast, firstSection, nextSection):
-
- first = isfirst or self._type == 'GRSection'
-
- while 1:
- if isinstance(self, GRSection) :
- self.processTrigger('On-Process')
-
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- else:
- # Handle GRSections specially as
- # they require extra logic
- if isinstance(child, GRSection):
- # If this is the top-most section for a datasource,
- # it needs to be called with processAsController.
- if child._mymapper.toplevel:
-
- GDebug.printMesg(10, "Calling new controlling section")
- child.processAsController(dest, mapper)
-
- # ..otherwise call the GRSection's process method.
- else:
- nextSection = child.process(dest, mapper,isfirst=1,
- islast=(nextSection == None) or \
- (nextSection._name not in
(child._childSections)),
- firstSection=firstSection,
nextSection=nextSection)
- # Don't allow the processing to enter trigger objects
- elif isinstance(child, GTrigger):
- pass
- else:
- # Handle the layout element.
- nextSection = child.process(dest, mapper, first, islast,
- firstSection, nextSection)
-
- first = 0
-
- if nextSection == self:
- firstSection, nextSection = self.getGotos(mapper)
- islast = (nextSection == None)
- else:
- break
-
- return nextSection
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 189,192 ----
Index: gnue/reports/src/base/layout/GRLayoutElement.py
diff -c gnue/reports/src/base/layout/GRLayoutElement.py:1.51
gnue/reports/src/base/layout/GRLayoutElement.py:1.52
*** gnue/reports/src/base/layout/GRLayoutElement.py:1.51 Wed Jan 1
19:45:49 2003
--- gnue/reports/src/base/layout/GRLayoutElement.py Wed Jan 1 21:06:24 2003
***************
*** 40,213 ****
############################################################
#
- # Used to send structural comment
- # Chose not to do "if COMMENT == 1: dest.write"
- # for performance reasons # TODO: Was this a good decision?
- #
- def _structuralComment(dest, text):
- dest.write(text)
-
- def _noStructuralComment(dest, text):
- pass
-
- structuralComment = _noStructuralComment
-
-
- ############################################################
- #
- # GRLayout
- #
- class GRLayout (GObj):
- def __init__(self, parent):
- GObj.__init__(self, parent, type='GRLayout')
- self._inits = (self.initialize,)
- self.suppressGNUeTags = 0
-
- def initialize(self):
- # Find the xml namespace in use by any child passthru objects
- # If there is more than one object attached to a layout
- # object, then create an unbound section to contain them.
- # This is a convenience for the layout engine code :)
-
- if len(self._children) > 1 or \
- ( len(self._children) and \
- self._children[0]._type != 'GRSection' ):
-
- temp = self._children[:]
- self._children = []
- section = GRSection(self)
- section._children = temp
- section._buildObject()
- elif len(self._children) == 0:
- raise GRExceptions.NoLayoutDefined, \
- "The layout section does not contain any instructions. What do I do?"
-
- self._xmlchildnamespace = self._findNamespace()
- self._parent._namespace = self._xmlchildnamespace
-
-
- # Find the xml namespace in use by any child passthru objects
- def _findNamespace(self, object=None):
- if object==None: object = self
- for child in object._children:
- try:
- if child._xmlnamespace:
- namespace = child._xmlnamespace
- else:
- namespace = self._findNamespace(child)
- if namespace:
- return namespace
- except AttributeError:
- pass
-
-
- #
- # Prepare for running
- #
- def prepare(self, mapper, parameters):
-
- self._mapper = mapper
- self._parameters = parameters
- self.walk(self.__prepare)
-
- # Used by prepare()
- def __prepare(self, object):
- if isinstance(object, GRLayoutElement):
-
- # This all looks confusing, but basically it simply figures out
- # what section a field or summary actually pulls from and also
- # makes sure a section, field, or summary isn't trying to use
- # a source outside of the source's scope. After it's satisfied
- # with the results, it adds the element to the mapper object.
-
- # TODO: This can probably be simplified by moving
- # TODO: the various functions to the actual child
- # TODO: object's phaseInits.
-
- parentSection = object.findParentOfType('GRSection',includeSelf=0)
-
- if isinstance(object, GRSection) and object._source != None:
- if parentSection is None:
- self._mapper.addSection(object._name, object._source, None)
- else:
- self._mapper.addSection(object._name,
- object._source,
- parentSection._name)
- object._mymapper = self._mapper.sectionMap[object._name]
- object._mymapper._object = object
-
- elif isinstance(object, GRField):
- s = parentSection.getAncestorWithSource(object._source)
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object.name, parentSection._name, object._source)
-
- object._section = s._name
-
- if hasattr(object,'section') and object.section:
- sec = string.lower(object.section)
- curr = s
- section = None
- while curr:
- if curr._name == sec:
- section = curr
- break
- curr = curr._parent.findParentOfType('GRSection')
-
- if section == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
- % (object.name, parentSection._name, object.section)
-
- object._section = section._name
-
- object._mymapper = self._mapper.sectionMap[object._section]
-
- GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
- % (object.name, object._section))
- self._mapper.addFieldToSection(object._section, object.name)
-
- elif isinstance(object, GRSumm):
- if object.section == None:
- s = object._parent.findParentOfType('GRSection')
- else:
- sec = string.lower(object.section)
- s = self._mapper.sectionMap[sec]._object
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object._field, object._parent.name, object._source)
-
- object._section = s._name
- object._mymapper = self._mapper.sectionMap[s._name]
-
- GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
- % (object._field, object.function, object._section))
- self._mapper.addSummaryToSection(object.function,
- object._section, object._field)
-
-
- #
- # Process layout and dump output.
- # self.prepare *must* be called prior to processing
- #
- def process(self, dest, includeStructuralComments=0):
-
- global structuralComment
- if includeStructuralComments:
- structuralComment = _structuralComment
-
- for child in self._children:
- structuralComment(dest, '<!-- [layout] -->')
- child.processAsController(dest, self._mapper)
- structuralComment(dest, '<!-- [/layout] -->\n')
-
-
-
-
- ############################################################
- #
# Any elements contained within a <layout> element
# inherit GRLayoutElement
#
--- 40,45 ----
***************
*** 227,240 ****
for attr in self.__dict__.keys():
try: prefix, att = attr.split('__',1)
except: continue
!
if prefix in self._xmlnamespaces.keys():
attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
dest.write('<%s%s>' % (tag, attrs))
rv = self._process(dest, *args, **parms)
dest.write('</%s>' % tag)
!
return rv
# Called if section contains data (the non-namespace version)
--- 59,72 ----
for attr in self.__dict__.keys():
try: prefix, att = attr.split('__',1)
except: continue
!
if prefix in self._xmlnamespaces.keys():
attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
dest.write('<%s%s>' % (tag, attrs))
rv = self._process(dest, *args, **parms)
dest.write('</%s>' % tag)
!
return rv
# Called if section contains data (the non-namespace version)
***************
*** 254,656 ****
# Avoid any overhead if this element doesn't
# contain namespace-qualified attributes
self.process = self._process
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # that can themselves be containers
- #
- class ContainerElement (GRLayoutElement):
- def __init__(self, parent=None, type='GRContainerElement'):
- GRLayoutElement.__init__(self, parent, type=type)
- # TODO: remove.. this is for debugging
- self._name = "untitled"
-
-
- # Process all children, handling GRSections properly
- def processChildren(self, dest, mapper,
- isfirst, islast, firstSection, nextSection):
-
- first = isfirst or self._type == 'GRSection'
-
- while 1:
- if isinstance(self, GRSection) :
- self.processTrigger('On-Process')
-
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- else:
- # Handle GRSections specially as
- # they require extra logic
- if isinstance(child, GRSection):
- # If this is the top-most section for a datasource,
- # it needs to be called with processAsController.
- if child._mymapper.toplevel:
-
- GDebug.printMesg(10, "Calling new controlling section")
- child.processAsController(dest, mapper)
-
- # ..otherwise call the GRSection's process method.
- else:
- nextSection = child.process(dest, mapper,isfirst=1,
- islast=(nextSection == None) or \
- (nextSection._name not in
(child._childSections)),
- firstSection=firstSection,
nextSection=nextSection)
- # Don't allow the processing to enter trigger objects
- elif isinstance(child, GTrigger):
- pass
- else:
- # Handle the layout element.
- nextSection = child.process(dest, mapper, first, islast,
- firstSection, nextSection)
-
- first = 0
-
- if nextSection == self:
- firstSection, nextSection = self.getGotos(mapper)
- islast = (nextSection == None)
- else:
- break
-
- return nextSection
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 86,89 ----
Index: gnue/reports/src/base/layout/GRNotFirstRow.py
diff -c gnue/reports/src/base/layout/GRNotFirstRow.py:1.51
gnue/reports/src/base/layout/GRNotFirstRow.py:1.52
*** gnue/reports/src/base/layout/GRNotFirstRow.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRNotFirstRow.py Wed Jan 1 21:06:24 2003
***************
*** 36,600 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
!
! ############################################################
! #
! # <section> tag
! #
! class GRSection (ContainerElement):
!
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRSection')
! self._childSections = []
! self._validTriggers = {'PRE-SECTION':'Pre-Section',
! 'POST-SECTION':'Post-Section',
! 'ON-PROCESS':'On-Process'}
!
! def _buildObject(self):
! if not hasattr(self,'name') or self.name == None:
! self._name = id(self)
! else:
! self._name = string.lower(self.name)
!
! # Keep track of "child" section names (for the firstRow stuff)
! psec = self._parent.findParentOfType('GRSection')
! if psec is not None:
! psec._childSections = self._childSections[:]
! psec._childSections.insert(0, self._name)
!
! return ContainerElement._buildObject(self)
!
!
! #
! # Retrieve the first row of data, if available.
! # Handle default data if no rows retrieved.
! #
! def processAsController(self, dest, mapper):
!
! GDebug.printMesg(10,
! "Controlling section %s's processAsController() called" % self._name)
!
! if self._source == None:
! # This is a dataless section...
! # simply process it's children
!
! self.process(dest, mapper, 1, 1, None, None)
!
! else:
! firstSection, nextSection = self.getGotos(mapper, 1)
!
! if firstSection:
! # This is a data-bound section and there
! # was data returned, so process section
! self.process(dest, mapper, 1, nextSection == None, self, nextSection)
!
! else:
! # This is a data-bound section and there
! # was no data returned, so generate default
! # text (if any)
!
! for c2 in self._children:
! if isinstance (c2, GRDefault):
! c2.processDefault(dest, mapper)
!
!
!
! #
! # Used internally to determine next section to move
! #
! def getGotos(self, mapper, init=0):
! # Determine the next section to process our data.
! # (i.e., handle section grouping)
! if init:
! goto, gotoNext = mapper.getFirstRecord(self._source)
! else:
! goto, gotoNext = mapper.getNextRecord(self._source)
!
! # Get the actual GRSection objects
! if not goto:
! return (None, None)
!
! firstSection = mapper.sectionMap[goto]._object
! if gotoNext:
! nextSection = mapper.sectionMap[gotoNext]._object
! else:
! nextSection = None
!
! # And return them
! return (firstSection, nextSection)
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if self._source == source:
! return self
! elif isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
! # Generic process() method. Process the
! # current record and handle any children.
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! self.processTrigger('Pre-Section')
! GDebug.printMesg(10,"Repeating Section %s" % self._name)
! structuralComment(dest,"<!-- [section:%s] -->" % self._name)
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
!
! try:
!
! structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
! mapper.sectionMap[self.name]._clearOnNextSet = 1
! except KeyError:
! pass
!
! structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
! GDebug.printMesg(10,"Leaving section %s" % self._name)
! self.processTrigger('Post-Section')
! return nextSection
!
!
! ############################################################
! #
! # <default> tag
! # Text in this tag is only displayed if datasource
! # returns no data. Note: this will be the only thing
! # in the section that will be displayed.
! #
! class GRDefault (GObj):
! def __init__(self, parent=None, type='GRDefault'):
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
!
! def processDefault(self, dest, mapper):
! structuralComment(dest,"<!-- [default] -->")
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! structuralComment(dest,"<!-- [/default] -->")
!
! def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
! return nextSection
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
!
!
! ############################################################
! #
! # <field> tag
! #
! class GRField (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRField')
! self._section = None
! self.format = None
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [field:%s] -->" % self.name)
! dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
! self.format)), '\r',''))
! structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
! return nextSection
!
!
!
! ############################################################
! #
! # <formula> tag
! #
! class GRFormula (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRFormula')
! self.section = None
! self.format = None
! self._inits = [self.init]
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! return GRLayoutElement._buildObject(self)
!
! def init(self):
! code = ""
! for f in self.getChildrenAsContent().code.split('\n'):
! if f.strip()[:1] != '#':
! code += f + ' '
! self._code = code
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
! # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/formula] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # <summ> tag
! #
! class GRSumm (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRSumm')
! self.section = None
! self.function = "count"
! self.format = None
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! self._field = string.lower(self.field)
! return GRLayoutElement._buildObject(self)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
! dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/summ] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # Parameters
! #
! class GRParam(GRLayoutElement, GRStubParam):
! _typestub = 'GRParam'
!
! def __init__(self, parent):
! # This is passed parent=None so that
! # the GObj.__init__ doesn't add this
! # object twice to its parent (icky)
! GRLayoutElement.__init__(self, parent=None)
! GRStubParam.__init__(self, parent)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [param:%s] -->" % self.name)
! dest.write (self.getFormattedValue())
! structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
! return nextSection
!
!
!
!
! ############################################################
! #
! # Logic support within sections
! #
!
! class GRFirstRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRFirstRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if isfirst:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
class GRNotFirstRow(ContainerElement):
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from ContainerElement import ContainerElement
class GRNotFirstRow(ContainerElement):
***************
*** 605,656 ****
if not isfirst:
nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 47,50 ----
Index: gnue/reports/src/base/layout/GRNotLastRow.py
diff -c gnue/reports/src/base/layout/GRNotLastRow.py:1.51
gnue/reports/src/base/layout/GRNotLastRow.py:1.52
*** gnue/reports/src/base/layout/GRNotLastRow.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRNotLastRow.py Wed Jan 1 21:06:24 2003
***************
*** 36,620 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
!
! ############################################################
! #
! # <section> tag
! #
! class GRSection (ContainerElement):
!
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRSection')
! self._childSections = []
! self._validTriggers = {'PRE-SECTION':'Pre-Section',
! 'POST-SECTION':'Post-Section',
! 'ON-PROCESS':'On-Process'}
!
! def _buildObject(self):
! if not hasattr(self,'name') or self.name == None:
! self._name = id(self)
! else:
! self._name = string.lower(self.name)
!
! # Keep track of "child" section names (for the firstRow stuff)
! psec = self._parent.findParentOfType('GRSection')
! if psec is not None:
! psec._childSections = self._childSections[:]
! psec._childSections.insert(0, self._name)
!
! return ContainerElement._buildObject(self)
!
!
! #
! # Retrieve the first row of data, if available.
! # Handle default data if no rows retrieved.
! #
! def processAsController(self, dest, mapper):
!
! GDebug.printMesg(10,
! "Controlling section %s's processAsController() called" % self._name)
!
! if self._source == None:
! # This is a dataless section...
! # simply process it's children
!
! self.process(dest, mapper, 1, 1, None, None)
!
! else:
! firstSection, nextSection = self.getGotos(mapper, 1)
!
! if firstSection:
! # This is a data-bound section and there
! # was data returned, so process section
! self.process(dest, mapper, 1, nextSection == None, self, nextSection)
!
! else:
! # This is a data-bound section and there
! # was no data returned, so generate default
! # text (if any)
!
! for c2 in self._children:
! if isinstance (c2, GRDefault):
! c2.processDefault(dest, mapper)
!
!
!
! #
! # Used internally to determine next section to move
! #
! def getGotos(self, mapper, init=0):
! # Determine the next section to process our data.
! # (i.e., handle section grouping)
! if init:
! goto, gotoNext = mapper.getFirstRecord(self._source)
! else:
! goto, gotoNext = mapper.getNextRecord(self._source)
!
! # Get the actual GRSection objects
! if not goto:
! return (None, None)
!
! firstSection = mapper.sectionMap[goto]._object
! if gotoNext:
! nextSection = mapper.sectionMap[gotoNext]._object
! else:
! nextSection = None
!
! # And return them
! return (firstSection, nextSection)
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if self._source == source:
! return self
! elif isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
! # Generic process() method. Process the
! # current record and handle any children.
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! self.processTrigger('Pre-Section')
! GDebug.printMesg(10,"Repeating Section %s" % self._name)
! structuralComment(dest,"<!-- [section:%s] -->" % self._name)
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
!
! try:
!
! structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
! mapper.sectionMap[self.name]._clearOnNextSet = 1
! except KeyError:
! pass
!
! structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
! GDebug.printMesg(10,"Leaving section %s" % self._name)
! self.processTrigger('Post-Section')
! return nextSection
!
!
! ############################################################
! #
! # <default> tag
! # Text in this tag is only displayed if datasource
! # returns no data. Note: this will be the only thing
! # in the section that will be displayed.
! #
! class GRDefault (GObj):
! def __init__(self, parent=None, type='GRDefault'):
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
!
! def processDefault(self, dest, mapper):
! structuralComment(dest,"<!-- [default] -->")
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! structuralComment(dest,"<!-- [/default] -->")
!
! def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
! return nextSection
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
!
!
! ############################################################
! #
! # <field> tag
! #
! class GRField (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRField')
! self._section = None
! self.format = None
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [field:%s] -->" % self.name)
! dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
! self.format)), '\r',''))
! structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
! return nextSection
!
!
!
! ############################################################
! #
! # <formula> tag
! #
! class GRFormula (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRFormula')
! self.section = None
! self.format = None
! self._inits = [self.init]
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! return GRLayoutElement._buildObject(self)
!
! def init(self):
! code = ""
! for f in self.getChildrenAsContent().code.split('\n'):
! if f.strip()[:1] != '#':
! code += f + ' '
! self._code = code
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
! # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/formula] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # <summ> tag
! #
! class GRSumm (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRSumm')
! self.section = None
! self.function = "count"
! self.format = None
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! self._field = string.lower(self.field)
! return GRLayoutElement._buildObject(self)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
! dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/summ] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # Parameters
! #
! class GRParam(GRLayoutElement, GRStubParam):
! _typestub = 'GRParam'
!
! def __init__(self, parent):
! # This is passed parent=None so that
! # the GObj.__init__ doesn't add this
! # object twice to its parent (icky)
! GRLayoutElement.__init__(self, parent=None)
! GRStubParam.__init__(self, parent)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [param:%s] -->" % self.name)
! dest.write (self.getFormattedValue())
! structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
! return nextSection
!
!
!
!
! ############################################################
! #
! # Logic support within sections
! #
!
! class GRFirstRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRFirstRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if isfirst:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
!
!
! class GRNotFirstRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRNotFirstRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if not isfirst:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
!
! class GRLastRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRLastRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if islast:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
class GRNotLastRow(ContainerElement):
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from ContainerElement import ContainerElement
class GRNotLastRow(ContainerElement):
***************
*** 625,656 ****
if not islast:
nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 47,50 ----
Index: gnue/reports/src/base/layout/GRParam.py
diff -c gnue/reports/src/base/layout/GRParam.py:1.51
gnue/reports/src/base/layout/GRParam.py:1.52
*** gnue/reports/src/base/layout/GRParam.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRParam.py Wed Jan 1 21:06:24 2003
***************
*** 36,562 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
!
! ############################################################
! #
! # <section> tag
! #
! class GRSection (ContainerElement):
!
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRSection')
! self._childSections = []
! self._validTriggers = {'PRE-SECTION':'Pre-Section',
! 'POST-SECTION':'Post-Section',
! 'ON-PROCESS':'On-Process'}
!
! def _buildObject(self):
! if not hasattr(self,'name') or self.name == None:
! self._name = id(self)
! else:
! self._name = string.lower(self.name)
!
! # Keep track of "child" section names (for the firstRow stuff)
! psec = self._parent.findParentOfType('GRSection')
! if psec is not None:
! psec._childSections = self._childSections[:]
! psec._childSections.insert(0, self._name)
!
! return ContainerElement._buildObject(self)
!
!
! #
! # Retrieve the first row of data, if available.
! # Handle default data if no rows retrieved.
! #
! def processAsController(self, dest, mapper):
!
! GDebug.printMesg(10,
! "Controlling section %s's processAsController() called" % self._name)
!
! if self._source == None:
! # This is a dataless section...
! # simply process it's children
!
! self.process(dest, mapper, 1, 1, None, None)
!
! else:
! firstSection, nextSection = self.getGotos(mapper, 1)
!
! if firstSection:
! # This is a data-bound section and there
! # was data returned, so process section
! self.process(dest, mapper, 1, nextSection == None, self, nextSection)
!
! else:
! # This is a data-bound section and there
! # was no data returned, so generate default
! # text (if any)
!
! for c2 in self._children:
! if isinstance (c2, GRDefault):
! c2.processDefault(dest, mapper)
!
!
!
! #
! # Used internally to determine next section to move
! #
! def getGotos(self, mapper, init=0):
! # Determine the next section to process our data.
! # (i.e., handle section grouping)
! if init:
! goto, gotoNext = mapper.getFirstRecord(self._source)
! else:
! goto, gotoNext = mapper.getNextRecord(self._source)
!
! # Get the actual GRSection objects
! if not goto:
! return (None, None)
!
! firstSection = mapper.sectionMap[goto]._object
! if gotoNext:
! nextSection = mapper.sectionMap[gotoNext]._object
! else:
! nextSection = None
!
! # And return them
! return (firstSection, nextSection)
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if self._source == source:
! return self
! elif isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
! # Generic process() method. Process the
! # current record and handle any children.
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! self.processTrigger('Pre-Section')
! GDebug.printMesg(10,"Repeating Section %s" % self._name)
! structuralComment(dest,"<!-- [section:%s] -->" % self._name)
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
!
! try:
!
! structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
! mapper.sectionMap[self.name]._clearOnNextSet = 1
! except KeyError:
! pass
!
! structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
! GDebug.printMesg(10,"Leaving section %s" % self._name)
! self.processTrigger('Post-Section')
! return nextSection
!
!
! ############################################################
! #
! # <default> tag
! # Text in this tag is only displayed if datasource
! # returns no data. Note: this will be the only thing
! # in the section that will be displayed.
! #
! class GRDefault (GObj):
! def __init__(self, parent=None, type='GRDefault'):
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
!
! def processDefault(self, dest, mapper):
! structuralComment(dest,"<!-- [default] -->")
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! structuralComment(dest,"<!-- [/default] -->")
!
! def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
! return nextSection
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
!
!
! ############################################################
! #
! # <field> tag
! #
! class GRField (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRField')
! self._section = None
! self.format = None
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [field:%s] -->" % self.name)
! dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
! self.format)), '\r',''))
! structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
! return nextSection
!
!
!
! ############################################################
! #
! # <formula> tag
! #
! class GRFormula (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRFormula')
! self.section = None
! self.format = None
! self._inits = [self.init]
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! return GRLayoutElement._buildObject(self)
!
! def init(self):
! code = ""
! for f in self.getChildrenAsContent().code.split('\n'):
! if f.strip()[:1] != '#':
! code += f + ' '
! self._code = code
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
! # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/formula] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # <summ> tag
! #
! class GRSumm (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRSumm')
! self.section = None
! self.function = "count"
! self.format = None
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! self._field = string.lower(self.field)
! return GRLayoutElement._buildObject(self)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
! dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/summ] -->")
! return nextSection
!
!
############################################################
#
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from GRLayoutElement import GRLayoutElement
############################################################
#
***************
*** 577,656 ****
dest.write (self.getFormattedValue())
structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
-
--- 57,59 ----
Index: gnue/reports/src/base/layout/GRPassThru.py
diff -c gnue/reports/src/base/layout/GRPassThru.py:1.51
gnue/reports/src/base/layout/GRPassThru.py:1.52
*** gnue/reports/src/base/layout/GRPassThru.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRPassThru.py Wed Jan 1 21:06:24 2003
***************
*** 36,631 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
!
! ############################################################
! #
! # <section> tag
! #
! class GRSection (ContainerElement):
!
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRSection')
! self._childSections = []
! self._validTriggers = {'PRE-SECTION':'Pre-Section',
! 'POST-SECTION':'Post-Section',
! 'ON-PROCESS':'On-Process'}
!
! def _buildObject(self):
! if not hasattr(self,'name') or self.name == None:
! self._name = id(self)
! else:
! self._name = string.lower(self.name)
!
! # Keep track of "child" section names (for the firstRow stuff)
! psec = self._parent.findParentOfType('GRSection')
! if psec is not None:
! psec._childSections = self._childSections[:]
! psec._childSections.insert(0, self._name)
!
! return ContainerElement._buildObject(self)
!
!
! #
! # Retrieve the first row of data, if available.
! # Handle default data if no rows retrieved.
! #
! def processAsController(self, dest, mapper):
!
! GDebug.printMesg(10,
! "Controlling section %s's processAsController() called" % self._name)
!
! if self._source == None:
! # This is a dataless section...
! # simply process it's children
!
! self.process(dest, mapper, 1, 1, None, None)
!
! else:
! firstSection, nextSection = self.getGotos(mapper, 1)
!
! if firstSection:
! # This is a data-bound section and there
! # was data returned, so process section
! self.process(dest, mapper, 1, nextSection == None, self, nextSection)
!
! else:
! # This is a data-bound section and there
! # was no data returned, so generate default
! # text (if any)
!
! for c2 in self._children:
! if isinstance (c2, GRDefault):
! c2.processDefault(dest, mapper)
!
!
!
! #
! # Used internally to determine next section to move
! #
! def getGotos(self, mapper, init=0):
! # Determine the next section to process our data.
! # (i.e., handle section grouping)
! if init:
! goto, gotoNext = mapper.getFirstRecord(self._source)
! else:
! goto, gotoNext = mapper.getNextRecord(self._source)
!
! # Get the actual GRSection objects
! if not goto:
! return (None, None)
!
! firstSection = mapper.sectionMap[goto]._object
! if gotoNext:
! nextSection = mapper.sectionMap[gotoNext]._object
! else:
! nextSection = None
!
! # And return them
! return (firstSection, nextSection)
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if self._source == source:
! return self
! elif isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
!
! # Generic process() method. Process the
! # current record and handle any children.
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! self.processTrigger('Pre-Section')
! GDebug.printMesg(10,"Repeating Section %s" % self._name)
! structuralComment(dest,"<!-- [section:%s] -->" % self._name)
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
!
! try:
!
! structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
! mapper.sectionMap[self.name]._clearOnNextSet = 1
! except KeyError:
! pass
!
! structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
! GDebug.printMesg(10,"Leaving section %s" % self._name)
! self.processTrigger('Post-Section')
! return nextSection
!
!
! ############################################################
! #
! # <default> tag
! # Text in this tag is only displayed if datasource
! # returns no data. Note: this will be the only thing
! # in the section that will be displayed.
! #
! class GRDefault (GObj):
! def __init__(self, parent=None, type='GRDefault'):
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
!
! def processDefault(self, dest, mapper):
! structuralComment(dest,"<!-- [default] -->")
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! structuralComment(dest,"<!-- [/default] -->")
!
! def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
! return nextSection
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
!
!
! ############################################################
! #
! # <field> tag
! #
! class GRField (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRField')
! self._section = None
! self.format = None
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [field:%s] -->" % self.name)
! dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
! self.format)), '\r',''))
! structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
! return nextSection
!
!
!
! ############################################################
! #
! # <formula> tag
! #
! class GRFormula (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRFormula')
! self.section = None
! self.format = None
! self._inits = [self.init]
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! return GRLayoutElement._buildObject(self)
!
! def init(self):
! code = ""
! for f in self.getChildrenAsContent().code.split('\n'):
! if f.strip()[:1] != '#':
! code += f + ' '
! self._code = code
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
! # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/formula] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # <summ> tag
! #
! class GRSumm (GRLayoutElement):
! def __init__(self, parent):
! GRLayoutElement.__init__(self, parent, 'GRSumm')
! self.section = None
! self.function = "count"
! self.format = None
!
! def _buildObject(self):
! if self.section:
! self._section = string.lower(self.section)
! else:
! self._section = None
!
! self._field = string.lower(self.field)
! return GRLayoutElement._buildObject(self)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
! dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
! structuralComment(dest,"<!-- [/summ] -->")
! return nextSection
!
!
!
! ############################################################
! #
! # Parameters
! #
! class GRParam(GRLayoutElement, GRStubParam):
! _typestub = 'GRParam'
!
! def __init__(self, parent):
! # This is passed parent=None so that
! # the GObj.__init__ doesn't add this
! # object twice to its parent (icky)
! GRLayoutElement.__init__(self, parent=None)
! GRStubParam.__init__(self, parent)
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! structuralComment(dest,"<!-- [param:%s] -->" % self.name)
! dest.write (self.getFormattedValue())
! structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
! return nextSection
!
!
!
!
! ############################################################
! #
! # Logic support within sections
! #
!
! class GRFirstRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRFirstRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if isfirst:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
!
!
! class GRNotFirstRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRNotFirstRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if not isfirst:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
!
! class GRLastRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRLastRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if islast:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
!
! class GRNotLastRow(ContainerElement):
! def __init__(self, parent):
! ContainerElement.__init__(self, parent, 'GRNotLastRow')
!
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! if not islast:
! nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
! return nextSection
!
############################################################
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from ContainerElement import ContainerElement
############################################################
Index: gnue/reports/src/base/layout/GRSection.py
diff -c gnue/reports/src/base/layout/GRSection.py:1.51
gnue/reports/src/base/layout/GRSection.py:1.52
*** gnue/reports/src/base/layout/GRSection.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRSection.py Wed Jan 1 21:06:24 2003
***************
*** 36,331 ****
import GRExceptions
import string
from xml.sax import saxutils
!
!
! ############################################################
! #
! # Used to send structural comment
! # Chose not to do "if COMMENT == 1: dest.write"
! # for performance reasons # TODO: Was this a good decision?
! #
! def _structuralComment(dest, text):
! dest.write(text)
!
! def _noStructuralComment(dest, text):
! pass
!
! structuralComment = _noStructuralComment
!
!
! ############################################################
! #
! # GRLayout
! #
! class GRLayout (GObj):
! def __init__(self, parent):
! GObj.__init__(self, parent, type='GRLayout')
! self._inits = (self.initialize,)
! self.suppressGNUeTags = 0
!
! def initialize(self):
! # Find the xml namespace in use by any child passthru objects
! # If there is more than one object attached to a layout
! # object, then create an unbound section to contain them.
! # This is a convenience for the layout engine code :)
!
! if len(self._children) > 1 or \
! ( len(self._children) and \
! self._children[0]._type != 'GRSection' ):
!
! temp = self._children[:]
! self._children = []
! section = GRSection(self)
! section._children = temp
! section._buildObject()
! elif len(self._children) == 0:
! raise GRExceptions.NoLayoutDefined, \
! "The layout section does not contain any instructions. What do I do?"
!
! self._xmlchildnamespace = self._findNamespace()
! self._parent._namespace = self._xmlchildnamespace
!
!
! # Find the xml namespace in use by any child passthru objects
! def _findNamespace(self, object=None):
! if object==None: object = self
! for child in object._children:
! try:
! if child._xmlnamespace:
! namespace = child._xmlnamespace
! else:
! namespace = self._findNamespace(child)
! if namespace:
! return namespace
! except AttributeError:
! pass
!
!
! #
! # Prepare for running
! #
! def prepare(self, mapper, parameters):
!
! self._mapper = mapper
! self._parameters = parameters
! self.walk(self.__prepare)
!
! # Used by prepare()
! def __prepare(self, object):
! if isinstance(object, GRLayoutElement):
!
! # This all looks confusing, but basically it simply figures out
! # what section a field or summary actually pulls from and also
! # makes sure a section, field, or summary isn't trying to use
! # a source outside of the source's scope. After it's satisfied
! # with the results, it adds the element to the mapper object.
!
! # TODO: This can probably be simplified by moving
! # TODO: the various functions to the actual child
! # TODO: object's phaseInits.
!
! parentSection = object.findParentOfType('GRSection',includeSelf=0)
!
! if isinstance(object, GRSection) and object._source != None:
! if parentSection is None:
! self._mapper.addSection(object._name, object._source, None)
! else:
! self._mapper.addSection(object._name,
! object._source,
! parentSection._name)
! object._mymapper = self._mapper.sectionMap[object._name]
! object._mymapper._object = object
!
! elif isinstance(object, GRField):
! s = parentSection.getAncestorWithSource(object._source)
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object.name, parentSection._name, object._source)
!
! object._section = s._name
!
! if hasattr(object,'section') and object.section:
! sec = string.lower(object.section)
! curr = s
! section = None
! while curr:
! if curr._name == sec:
! section = curr
! break
! curr = curr._parent.findParentOfType('GRSection')
!
! if section == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
! % (object.name, parentSection._name, object.section)
!
! object._section = section._name
!
! object._mymapper = self._mapper.sectionMap[object._section]
!
! GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
! % (object.name, object._section))
! self._mapper.addFieldToSection(object._section, object.name)
!
! elif isinstance(object, GRSumm):
! if object.section == None:
! s = object._parent.findParentOfType('GRSection')
! else:
! sec = string.lower(object.section)
! s = self._mapper.sectionMap[sec]._object
! if s == None:
! raise GRExceptions.SourceOutOfScope, \
! 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
! % (object._field, object._parent.name, object._source)
!
! object._section = s._name
! object._mymapper = self._mapper.sectionMap[s._name]
!
! GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
! % (object._field, object.function, object._section))
! self._mapper.addSummaryToSection(object.function,
! object._section, object._field)
!
!
! #
! # Process layout and dump output.
! # self.prepare *must* be called prior to processing
! #
! def process(self, dest, includeStructuralComments=0):
!
! global structuralComment
! if includeStructuralComments:
! structuralComment = _structuralComment
!
! for child in self._children:
! structuralComment(dest, '<!-- [layout] -->')
! child.processAsController(dest, self._mapper)
! structuralComment(dest, '<!-- [/layout] -->\n')
!
!
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # inherit GRLayoutElement
! #
! class GRLayoutElement (GObj,GTriggerExtension):
! def __init__(self, parent=None, type='GRLayoutElement'):
! GTriggerExtension.__init__(self)
! GObj.__init__(self, parent, type=type)
! self.name = None
! self._source = None
! self._mymapper = None
! self._inits = [self.primaryInit]
!
! # Called if section contains data
! def process(self, dest, *args, **parms):
! tag = self.getXmlTag()
! attrs = ""
! for attr in self.__dict__.keys():
! try: prefix, att = attr.split('__',1)
! except: continue
!
! if prefix in self._xmlnamespaces.keys():
! attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
!
! dest.write('<%s%s>' % (tag, attrs))
! rv = self._process(dest, *args, **parms)
! dest.write('</%s>' % tag)
!
! return rv
!
! # Called if section contains data (the non-namespace version)
! def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
! return nextSection
!
! def primaryInit(self):
! if hasattr(self,'source') and self.source is not None:
! self._source = self.source
! else:
! try:
! self._source = self._parent._source
! except AttributeError:
! self._source = None
!
! if not self._xmlnamespaces:
! # Avoid any overhead if this element doesn't
! # contain namespace-qualified attributes
! self.process = self._process
!
!
! ############################################################
! #
! # Any elements contained within a <layout> element
! # that can themselves be containers
! #
! class ContainerElement (GRLayoutElement):
! def __init__(self, parent=None, type='GRContainerElement'):
! GRLayoutElement.__init__(self, parent, type=type)
! # TODO: remove.. this is for debugging
! self._name = "untitled"
!
!
! # Process all children, handling GRSections properly
! def processChildren(self, dest, mapper,
! isfirst, islast, firstSection, nextSection):
!
! first = isfirst or self._type == 'GRSection'
!
! while 1:
! if isinstance(self, GRSection) :
! self.processTrigger('On-Process')
!
! for child in self._children:
! if child._type == "_content_":
! dest.write(child.getContent())
! else:
! # Handle GRSections specially as
! # they require extra logic
! if isinstance(child, GRSection):
! # If this is the top-most section for a datasource,
! # it needs to be called with processAsController.
! if child._mymapper.toplevel:
!
! GDebug.printMesg(10, "Calling new controlling section")
! child.processAsController(dest, mapper)
!
! # ..otherwise call the GRSection's process method.
! else:
! nextSection = child.process(dest, mapper,isfirst=1,
! islast=(nextSection == None) or \
! (nextSection._name not in
(child._childSections)),
! firstSection=firstSection,
nextSection=nextSection)
! # Don't allow the processing to enter trigger objects
! elif isinstance(child, GTrigger):
! pass
! else:
! # Handle the layout element.
! nextSection = child.process(dest, mapper, first, islast,
! firstSection, nextSection)
!
! first = 0
!
! if nextSection == self:
! firstSection, nextSection = self.getGotos(mapper)
! islast = (nextSection == None)
! else:
! break
!
! return nextSection
!
!
! #
! # getAncestorWithSource()
! #
! def getAncestorWithSource(self, source):
! if isinstance(self._parent, GRSection):
! return self._parent.getAncestorWithSource(source)
! else:
! return None
!
############################################################
--- 36,42 ----
import GRExceptions
import string
from xml.sax import saxutils
! from GRLayoutElement import GRLayoutElement
############################################################
***************
*** 446,656 ****
GDebug.printMesg(10,"Leaving section %s" % self._name)
self.processTrigger('Post-Section')
return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # <summ> tag
- #
- class GRSumm (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRSumm')
- self.section = None
- self.function = "count"
- self.format = None
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- self._field = string.lower(self.field)
- return GRLayoutElement._buildObject(self)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section,
self._field, self.function))
- dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/summ] -->")
- return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 157,160 ----
Index: gnue/reports/src/base/layout/GRSumm.py
diff -c gnue/reports/src/base/layout/GRSumm.py:1.51
gnue/reports/src/base/layout/GRSumm.py:1.52
*** gnue/reports/src/base/layout/GRSumm.py:1.51 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/base/layout/GRSumm.py Wed Jan 1 21:06:24 2003
***************
*** 28,537 ****
#
! from gnue.common.GObjects import *
! from gnue.common import GDebug, GConditions
! from gnue.common.GTrigger import GTrigger,GTriggerExtension
!
from GRParameters import GRStubParam
import GRExceptions
import string
from xml.sax import saxutils
############################################################
#
- # Used to send structural comment
- # Chose not to do "if COMMENT == 1: dest.write"
- # for performance reasons # TODO: Was this a good decision?
- #
- def _structuralComment(dest, text):
- dest.write(text)
-
- def _noStructuralComment(dest, text):
- pass
-
- structuralComment = _noStructuralComment
-
-
- ############################################################
- #
- # GRLayout
- #
- class GRLayout (GObj):
- def __init__(self, parent):
- GObj.__init__(self, parent, type='GRLayout')
- self._inits = (self.initialize,)
- self.suppressGNUeTags = 0
-
- def initialize(self):
- # Find the xml namespace in use by any child passthru objects
- # If there is more than one object attached to a layout
- # object, then create an unbound section to contain them.
- # This is a convenience for the layout engine code :)
-
- if len(self._children) > 1 or \
- ( len(self._children) and \
- self._children[0]._type != 'GRSection' ):
-
- temp = self._children[:]
- self._children = []
- section = GRSection(self)
- section._children = temp
- section._buildObject()
- elif len(self._children) == 0:
- raise GRExceptions.NoLayoutDefined, \
- "The layout section does not contain any instructions. What do I do?"
-
- self._xmlchildnamespace = self._findNamespace()
- self._parent._namespace = self._xmlchildnamespace
-
-
- # Find the xml namespace in use by any child passthru objects
- def _findNamespace(self, object=None):
- if object==None: object = self
- for child in object._children:
- try:
- if child._xmlnamespace:
- namespace = child._xmlnamespace
- else:
- namespace = self._findNamespace(child)
- if namespace:
- return namespace
- except AttributeError:
- pass
-
-
- #
- # Prepare for running
- #
- def prepare(self, mapper, parameters):
-
- self._mapper = mapper
- self._parameters = parameters
- self.walk(self.__prepare)
-
- # Used by prepare()
- def __prepare(self, object):
- if isinstance(object, GRLayoutElement):
-
- # This all looks confusing, but basically it simply figures out
- # what section a field or summary actually pulls from and also
- # makes sure a section, field, or summary isn't trying to use
- # a source outside of the source's scope. After it's satisfied
- # with the results, it adds the element to the mapper object.
-
- # TODO: This can probably be simplified by moving
- # TODO: the various functions to the actual child
- # TODO: object's phaseInits.
-
- parentSection = object.findParentOfType('GRSection',includeSelf=0)
-
- if isinstance(object, GRSection) and object._source != None:
- if parentSection is None:
- self._mapper.addSection(object._name, object._source, None)
- else:
- self._mapper.addSection(object._name,
- object._source,
- parentSection._name)
- object._mymapper = self._mapper.sectionMap[object._name]
- object._mymapper._object = object
-
- elif isinstance(object, GRField):
- s = parentSection.getAncestorWithSource(object._source)
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object.name, parentSection._name, object._source)
-
- object._section = s._name
-
- if hasattr(object,'section') and object.section:
- sec = string.lower(object.section)
- curr = s
- section = None
- while curr:
- if curr._name == sec:
- section = curr
- break
- curr = curr._parent.findParentOfType('GRSection')
-
- if section == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Field "%s" in section "%s" uses out-of-scope section "%s"' \
- % (object.name, parentSection._name, object.section)
-
- object._section = section._name
-
- object._mymapper = self._mapper.sectionMap[object._section]
-
- GDebug.printMesg(6,'Mapping field "%s" to section "%s"' \
- % (object.name, object._section))
- self._mapper.addFieldToSection(object._section, object.name)
-
- elif isinstance(object, GRSumm):
- if object.section == None:
- s = object._parent.findParentOfType('GRSection')
- else:
- sec = string.lower(object.section)
- s = self._mapper.sectionMap[sec]._object
- if s == None:
- raise GRExceptions.SourceOutOfScope, \
- 'Summary "%s" in section "%s" uses out-of-scope source "%s"' \
- % (object._field, object._parent.name, object._source)
-
- object._section = s._name
- object._mymapper = self._mapper.sectionMap[s._name]
-
- GDebug.printMesg(6,'Mapping summary %s [%s] to section %s' \
- % (object._field, object.function, object._section))
- self._mapper.addSummaryToSection(object.function,
- object._section, object._field)
-
-
- #
- # Process layout and dump output.
- # self.prepare *must* be called prior to processing
- #
- def process(self, dest, includeStructuralComments=0):
-
- global structuralComment
- if includeStructuralComments:
- structuralComment = _structuralComment
-
- for child in self._children:
- structuralComment(dest, '<!-- [layout] -->')
- child.processAsController(dest, self._mapper)
- structuralComment(dest, '<!-- [/layout] -->\n')
-
-
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # inherit GRLayoutElement
- #
- class GRLayoutElement (GObj,GTriggerExtension):
- def __init__(self, parent=None, type='GRLayoutElement'):
- GTriggerExtension.__init__(self)
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
- self._inits = [self.primaryInit]
-
- # Called if section contains data
- def process(self, dest, *args, **parms):
- tag = self.getXmlTag()
- attrs = ""
- for attr in self.__dict__.keys():
- try: prefix, att = attr.split('__',1)
- except: continue
-
- if prefix in self._xmlnamespaces.keys():
- attrs += ' %s="%s"' % (att, saxutils.escape(self.__dict__[attr]))
-
- dest.write('<%s%s>' % (tag, attrs))
- rv = self._process(dest, *args, **parms)
- dest.write('</%s>' % tag)
-
- return rv
-
- # Called if section contains data (the non-namespace version)
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
- def primaryInit(self):
- if hasattr(self,'source') and self.source is not None:
- self._source = self.source
- else:
- try:
- self._source = self._parent._source
- except AttributeError:
- self._source = None
-
- if not self._xmlnamespaces:
- # Avoid any overhead if this element doesn't
- # contain namespace-qualified attributes
- self.process = self._process
-
-
- ############################################################
- #
- # Any elements contained within a <layout> element
- # that can themselves be containers
- #
- class ContainerElement (GRLayoutElement):
- def __init__(self, parent=None, type='GRContainerElement'):
- GRLayoutElement.__init__(self, parent, type=type)
- # TODO: remove.. this is for debugging
- self._name = "untitled"
-
-
- # Process all children, handling GRSections properly
- def processChildren(self, dest, mapper,
- isfirst, islast, firstSection, nextSection):
-
- first = isfirst or self._type == 'GRSection'
-
- while 1:
- if isinstance(self, GRSection) :
- self.processTrigger('On-Process')
-
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- else:
- # Handle GRSections specially as
- # they require extra logic
- if isinstance(child, GRSection):
- # If this is the top-most section for a datasource,
- # it needs to be called with processAsController.
- if child._mymapper.toplevel:
-
- GDebug.printMesg(10, "Calling new controlling section")
- child.processAsController(dest, mapper)
-
- # ..otherwise call the GRSection's process method.
- else:
- nextSection = child.process(dest, mapper,isfirst=1,
- islast=(nextSection == None) or \
- (nextSection._name not in
(child._childSections)),
- firstSection=firstSection,
nextSection=nextSection)
- # Don't allow the processing to enter trigger objects
- elif isinstance(child, GTrigger):
- pass
- else:
- # Handle the layout element.
- nextSection = child.process(dest, mapper, first, islast,
- firstSection, nextSection)
-
- first = 0
-
- if nextSection == self:
- firstSection, nextSection = self.getGotos(mapper)
- islast = (nextSection == None)
- else:
- break
-
- return nextSection
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
-
- ############################################################
- #
- # <section> tag
- #
- class GRSection (ContainerElement):
-
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRSection')
- self._childSections = []
- self._validTriggers = {'PRE-SECTION':'Pre-Section',
- 'POST-SECTION':'Post-Section',
- 'ON-PROCESS':'On-Process'}
-
- def _buildObject(self):
- if not hasattr(self,'name') or self.name == None:
- self._name = id(self)
- else:
- self._name = string.lower(self.name)
-
- # Keep track of "child" section names (for the firstRow stuff)
- psec = self._parent.findParentOfType('GRSection')
- if psec is not None:
- psec._childSections = self._childSections[:]
- psec._childSections.insert(0, self._name)
-
- return ContainerElement._buildObject(self)
-
-
- #
- # Retrieve the first row of data, if available.
- # Handle default data if no rows retrieved.
- #
- def processAsController(self, dest, mapper):
-
- GDebug.printMesg(10,
- "Controlling section %s's processAsController() called" % self._name)
-
- if self._source == None:
- # This is a dataless section...
- # simply process it's children
-
- self.process(dest, mapper, 1, 1, None, None)
-
- else:
- firstSection, nextSection = self.getGotos(mapper, 1)
-
- if firstSection:
- # This is a data-bound section and there
- # was data returned, so process section
- self.process(dest, mapper, 1, nextSection == None, self, nextSection)
-
- else:
- # This is a data-bound section and there
- # was no data returned, so generate default
- # text (if any)
-
- for c2 in self._children:
- if isinstance (c2, GRDefault):
- c2.processDefault(dest, mapper)
-
-
-
- #
- # Used internally to determine next section to move
- #
- def getGotos(self, mapper, init=0):
- # Determine the next section to process our data.
- # (i.e., handle section grouping)
- if init:
- goto, gotoNext = mapper.getFirstRecord(self._source)
- else:
- goto, gotoNext = mapper.getNextRecord(self._source)
-
- # Get the actual GRSection objects
- if not goto:
- return (None, None)
-
- firstSection = mapper.sectionMap[goto]._object
- if gotoNext:
- nextSection = mapper.sectionMap[gotoNext]._object
- else:
- nextSection = None
-
- # And return them
- return (firstSection, nextSection)
-
-
- #
- # getAncestorWithSource()
- #
- def getAncestorWithSource(self, source):
- if self._source == source:
- return self
- elif isinstance(self._parent, GRSection):
- return self._parent.getAncestorWithSource(source)
- else:
- return None
-
-
- # Generic process() method. Process the
- # current record and handle any children.
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- self.processTrigger('Pre-Section')
- GDebug.printMesg(10,"Repeating Section %s" % self._name)
- structuralComment(dest,"<!-- [section:%s] -->" % self._name)
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
-
- try:
-
- structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" %
self._name)
- mapper.sectionMap[self.name]._clearOnNextSet = 1
- except KeyError:
- pass
-
- structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
- GDebug.printMesg(10,"Leaving section %s" % self._name)
- self.processTrigger('Post-Section')
- return nextSection
-
-
- ############################################################
- #
- # <default> tag
- # Text in this tag is only displayed if datasource
- # returns no data. Note: this will be the only thing
- # in the section that will be displayed.
- #
- class GRDefault (GObj):
- def __init__(self, parent=None, type='GRDefault'):
- GObj.__init__(self, parent, type=type)
- self.name = None
- self._source = None
- self._mymapper = None
-
- def processDefault(self, dest, mapper):
- structuralComment(dest,"<!-- [default] -->")
- for child in self._children:
- if child._type == "_content_":
- dest.write(child.getContent())
- structuralComment(dest,"<!-- [/default] -->")
-
- def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
- return nextSection
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- return nextSection
-
-
-
- ############################################################
- #
- # <field> tag
- #
- class GRField (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRField')
- self._section = None
- self.format = None
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [field:%s] -->" % self.name)
- dest.write (string.replace(saxutils.escape("%s" %
self._mymapper.getField(self.name,
- self.format)), '\r',''))
- structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
- return nextSection
-
-
-
- ############################################################
- #
- # <formula> tag
- #
- class GRFormula (GRLayoutElement):
- def __init__(self, parent):
- GRLayoutElement.__init__(self, parent, 'GRFormula')
- self.section = None
- self.format = None
- self._inits = [self.init]
-
- def _buildObject(self):
- if self.section:
- self._section = string.lower(self.section)
- else:
- self._section = None
-
- return GRLayoutElement._buildObject(self)
-
- def init(self):
- code = ""
- for f in self.getChildrenAsContent().code.split('\n'):
- if f.strip()[:1] != '#':
- code += f + ' '
- self._code = code
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [formula:%s] -->" % (self.section))
- # dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
- structuralComment(dest,"<!-- [/formula] -->")
- return nextSection
-
-
-
- ############################################################
- #
# <summ> tag
#
class GRSumm (GRLayoutElement):
--- 28,43 ----
#
! from gnue.common import GDebug
from GRParameters import GRStubParam
import GRExceptions
import string
+ from GRLayoutElement import GRLayoutElement
from xml.sax import saxutils
############################################################
#
# <summ> tag
#
class GRSumm (GRLayoutElement):
***************
*** 555,656 ****
dest.write (self._mymapper.getSummary(self._field, self.function,
self.format))
structuralComment(dest,"<!-- [/summ] -->")
return nextSection
-
-
-
- ############################################################
- #
- # Parameters
- #
- class GRParam(GRLayoutElement, GRStubParam):
- _typestub = 'GRParam'
-
- def __init__(self, parent):
- # This is passed parent=None so that
- # the GObj.__init__ doesn't add this
- # object twice to its parent (icky)
- GRLayoutElement.__init__(self, parent=None)
- GRStubParam.__init__(self, parent)
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- structuralComment(dest,"<!-- [param:%s] -->" % self.name)
- dest.write (self.getFormattedValue())
- structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
- return nextSection
-
-
-
-
- ############################################################
- #
- # Logic support within sections
- #
-
- class GRFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- class GRNotFirstRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotFirstRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not isfirst:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
- class GRNotLastRow(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRNotLastRow')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- if not islast:
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- return nextSection
-
-
-
- ############################################################
- #
- # Any namespaced tags designed to
- # simply pass thru our layout engine
- #
- class GRPassThru(ContainerElement):
- def __init__(self, parent):
- ContainerElement.__init__(self, parent, 'GRPassThru')
-
- def _process(self, dest, mapper, isfirst, islast, firstSection,
nextSection):
- dest.write('<%s' % self._xmltag)
- for attr in self._loadedxmlattrs.keys():
- dest.write(' %s="%s"' % (attr,
saxutils.escape(str(self._loadedxmlattrs[attr]))))
-
- if len(self._children):
- dest.write('>')
- nextSection = self.processChildren(dest, mapper, isfirst, islast,
firstSection, nextSection)
- dest.write('</%s>' % self._xmltag)
- else:
- dest.write('/>')
-
- return nextSection
-
- def getXmlTag(self):
- return self._xmltag
--- 61,64 ----
Index: gnue/reports/src/base/layout/__init__.py
diff -c gnue/reports/src/base/layout/__init__.py:1.1
gnue/reports/src/base/layout/__init__.py:1.2
*** gnue/reports/src/base/layout/__init__.py:1.1 Wed Jan 1 20:36:28 2003
--- gnue/reports/src/base/layout/__init__.py Wed Jan 1 21:06:24 2003
***************
*** 0 ****
--- 1,43 ----
+ #
+ # This file is part of GNU Enterprise.
+ #
+ # GNU Enterprise is free software; you can redistribute it
+ # and/or modify it under the terms of the GNU General Public
+ # License as published by the Free Software Foundation; either
+ # version 2, or (at your option) any later version.
+ #
+ # GNU Enterprise 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 General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public
+ # License along with program; see the file COPYING. If not,
+ # write to the Free Software Foundation, Inc., 59 Temple Place
+ # - Suite 330, Boston, MA 02111-1307, USA.
+ #
+ # Copyright 2000-2003 Free Software Foundation
+ #
+ # FILE:
+ # layout/__init__.py
+ #
+ # DESCRIPTION:
+ # Classes related to the Layout section
+ #
+ # NOTES:
+ #
+
+ from GRLayout import GRLayout
+ from GRLayoutElement import GRLayoutElement
+ from ContainerElement import ContainerElement
+ from GRSection import GRSection
+ from GRDefault import GRDefault
+ from GRField import GRField
+ from GRFormula import GRFormula
+ from GRSumm import GRSumm
+ from GRParam import GRParam
+ from GRFirstRow import GRFirstRow
+ from GRNotFirstRow import GRNotFirstRow
+ from GRLastRow import GRLastRow
+ from GRNotLastRow import GRNotLastRow
+ from GRPassThru import GRPassThru
Index: gnue/reports/src/client/GRRun.py
diff -c gnue/reports/src/client/GRRun.py:1.23
gnue/reports/src/client/GRRun.py:1.24
*** gnue/reports/src/client/GRRun.py:1.23 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/client/GRRun.py Wed Jan 1 21:06:24 2003
***************
*** 31,41 ****
from gnue.reports import VERSION
from gnue.common import GDebug
from gnue.common.GClientApp import GClientApp
! from GREngine import GREngine
! import GRFilters
! import GRExceptions
from GRRunUI import GRRunUI
! from GRReportInfo import GRReportInfo
import string, sys
import tempfile
from gnue.reports.GRConfig import ConfigOptions
--- 31,40 ----
from gnue.reports import VERSION
from gnue.common import GDebug
from gnue.common.GClientApp import GClientApp
! from gnue.reports.base.GREngine import GREngine
! from gnue.reports.base import GRFilters, GRExceptions
from GRRunUI import GRRunUI
! from gnue.reports.base.GRReportInfo import GRReportInfo
import string, sys
import tempfile
from gnue.reports.GRConfig import ConfigOptions
Index: gnue/reports/src/server/GRServer.py
diff -c gnue/reports/src/server/GRServer.py:1.10
gnue/reports/src/server/GRServer.py:1.11
*** gnue/reports/src/server/GRServer.py:1.10 Wed Jan 1 19:45:49 2003
--- gnue/reports/src/server/GRServer.py Wed Jan 1 21:06:24 2003
***************
*** 29,37 ****
from gnue.common import GDebug, GComm, GServerApp, GConfig
! from GREngine import GREngine
! from GRConfig import ConfigOptions
! import GRExceptions
import string, sys, time
from gnue.reports import VERSION
--- 29,37 ----
from gnue.common import GDebug, GComm, GServerApp, GConfig
! from gnue.reports.base.GREngine import GREngine
! from gnue.reports.base.GRConfig import ConfigOptions
! from gnue.reports.base import GRExceptions
import string, sys, time
from gnue.reports import VERSION
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue designer/src/reports/Incubator.py designer...,
Jason Cater <=