[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8083 - trunk/gnue-designer/src/templates/reports
From: |
btami |
Subject: |
[gnue] r8083 - trunk/gnue-designer/src/templates/reports |
Date: |
Thu, 27 Oct 2005 11:10:12 -0500 (CDT) |
Author: btami
Date: 2005-10-27 11:10:11 -0500 (Thu, 27 Oct 2005)
New Revision: 8083
Added:
trunk/gnue-designer/src/templates/reports/CharReport.py
Log:
simple Char report wizard
Added: trunk/gnue-designer/src/templates/reports/CharReport.py
===================================================================
--- trunk/gnue-designer/src/templates/reports/CharReport.py 2005-10-27
07:45:09 UTC (rev 8082)
+++ trunk/gnue-designer/src/templates/reports/CharReport.py 2005-10-27
16:10:11 UTC (rev 8083)
@@ -0,0 +1,259 @@
+#
+# 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 2001-2005 Free Software Foundation
+#
+# FILE:
+# Simple.py
+#
+# DESCRIPTION:
+# Implements a basic report template
+#
+# NOTES:
+# While functional, the primary purpose of this wizard is
+# as a "learning-by-example" tool.
+
+
+from gnue.designer.reports.TemplateSupport import *
+import string
+
+# NOTE: It is VERY important that in any references to a
+# "<insert type here> wizard", the word "wizard" must be
+# in lower case, as many proper names such as "Foobar Wizard"
+# have been trademarked. (No, I'm not kidding :)
+#
+
+
+class CharReportTemplate(ReportTemplate):
+
+ # The first step in our wizard.
+ # The template parser will initially
+ # call GetStep(FIRST_STEP).
+ FIRST_STEP = '0'
+
+
+ ###############
+ #
+ # Initialize any runtime variables
+ #
+ def Start(self, report, current):
+ self.report = report
+ self.current = current
+
+
+ ###############
+ #
+ # Return the markup for a specific page
+ #
+ def GetStep(self, stepCode):
+
+ #
+ # Step #1 / Get Title, et al
+ #
+ if stepCode == '0':
+ return { 'title': 'Basic Report Information',
+ 'content': (WizardText('Welcome to the sample report
wizard.'),
+ WizardText('To create your report, I need to know
some basic information.\n\n'
+ 'First, what shall I call your report?
This name will appear in '
+ 'the title bar.'),
+ WizardInput('title', label='Report Title:',
required=1,
+ size=40),
+ WizardText('What connection should this report
use to connect to the database?'),
+ WizardInput('connection',label='Connection:',
required=1,
+ set=self.GetAvailableConnections()),
+ WizardText('You may be asked to login to this
connection.'),
+ ),
+ 'prev': None,
+ 'next': '1' }
+
+
+ #
+ # Step #2 / Get Base Table
+ #
+ elif stepCode == '1':
+
+ # TODO: If the connection changed between steps,
+ # TODO: variables['table'] and variables['fields']
+ # TODO: should be cleared.
+
+ return { 'title': 'Select Base Table/Source',
+ 'content': (WizardText('Now, please select the base table for
your report.'),
+ WizardInput('table', label='Base Table:',
required=1, lines=5,
+
set=self.GetAvailableSources(self.variables['connection'])), ),
+ 'prev': '0',
+ 'next': '2' }
+
+
+ #
+ # Step #3 / Get Columns to Include
+ #
+ elif stepCode == '2':
+
+ # TODO: If the table changed between steps,
+ # TODO: variables['fields'] should be cleared.
+
+ return { 'title': 'Select Fields to Include',
+ 'content': (WizardText('Which fields shall I include in your
report?'),
+ WizardInput('fields', label='Columns:',
required=1,
+ maxSelections=-1, orderable=1,
+ set=self.GetAvailableFields( \
+ self.variables['connection'],
+ self.variables['table'])), ),
+ 'prev': '1',
+ 'next': None }
+
+
+
+ ###############
+ #
+ # Verify contents of current step
+ # Return None if no problems, otherwise
+ # return a tuple of error message strings
+ #
+ def ValidateStep(self, stepCode):
+
+ # The Simple wizard uses basic "required"
+ # settings in the page markup, so doesn't
+ # need any special validation.
+ return None
+
+
+
+ ###############
+ #
+ # We have all the data, so generate our report. This
+ # is called after the user clicks the "Finish" button.
+ # No more user input is allowed at this point.
+ #
+ def Finalize(self):
+ self.instance.wizardName = TemplateInformation['Name']
+
+ # We will use the table name as the basis for all our
+ # object names. We will add a prefix based on the object
+ # type to the table name. Capitalize the first letter and
+ # strip all spaces...
+ if len(self.variables['table']) == 1:
+ tableKey = string.upper(self.variables['table'])
+ else:
+ tableKey = string.upper(self.variables['table'][0]) + \
+ string.replace(self.variables['table'][1:],' ','_')
+
+ # Get the common report objects
+ report = self.report
+ sources = self.current['sources']
+ layout = self.current['layout']
+
+ # Set the basic attributes of the report
+ report['title'] = self.variables['title']
+
+ self.AddElement('trigger', report, {'name':"timestamp", 'type':"NAMED"}, \
+ content ="from datetime import datetime \nreturn
datetime.now()")
+
+ # Create a single datasource based on user's input
+ datasource = self.AddElement('datasource', sources,
+ { 'connection': self.variables['connection'],
+ 'table': self.variables['table'],
+ 'type': 'object',
+ 'name': 'dts%s' % tableKey })
+
+ schema = self.GetSourceSchema(self.variables['connection'],
+ self.variables['table'])
+
+ # Make a map of all the field schemas we will need
+ # We will not actually create the entries at this point
+ # because we want to keep in the order that the user
+ # specified
+ fields = {}
+ for field in schema.findChildrenOfType ('GSField', False, True):
+ if field.name in self.variables['fields']:
+ fields[field.name] = field
+
+ out_report = self.AddElement('out:chreport', layout, {'width':"80",
'height':"66"})
+ out_pageheader = self.AddElement('out:pageheader', out_report,
{'height':"5"})
+ self.AddElement('out:label', out_pageheader, {'width':"80",
'align':"center", 'x':"0", 'y':"1"}, \
+ content=self.variables['title'])
+
+ start = 0
+ for name in self.variables['fields']:
+ field = fields[name]
+ attrs = {}
+ if hasattr (field, 'length'):
+ length = field.length
+ else:
+ length = 10
+ attrs ['width'] = length
+ attrs['y'] = 3
+ attrs['x'] = start
+ if field.type == 'number':
+ attrs['align'] = "right"
+ start += length + 1
+ self.AddElement('out:label', out_pageheader, attrs, content=field.name)
+ attrs['y'] = 4
+ self.AddElement('out:label', out_pageheader, attrs, content="-"*length)
+
+ section = self.AddElement('section', out_report, {'name': "detailes",
'source': datasource.name})
+ out_detail = self.AddElement('out:detail', section, {'height':"2"})
+
+ # Add each field
+ start = 0
+ for name in self.variables['fields']:
+ field = fields[name]
+ attrs = {}
+ if hasattr (field, 'length'):
+ length = field.length
+ else:
+ length = 10
+ attrs ['width'] = length
+ attrs['y'] = 0
+ attrs['x'] = start
+ if field.type == 'number':
+ attrs['align'] = "right"
+ start += length + 1
+ out_label = self.AddElement('out:label', out_detail, attrs)
+ self.AddElement('field', out_label, {'name':field.name})
+
+ out_pagefooter = self.AddElement('out:pagefooter', out_report,
{'height':"2"})
+ self.AddElement('out:label', out_pagefooter, {'width':"11", 'x':"0",
'y':"1"}, \
+ content='Printed at:')
+ out_label = self.AddElement('out:label', out_pagefooter, {'width':"25",
'x':"12", 'y':"1"})
+ section = self.AddElement('section', out_label, {'name': "unbound"})
+ formula = self.AddElement('formula', section, {'name':"stamp"})
+ trigger = self.AddElement('trigger', formula, {'type':"On-Process",
'src':"timestamp"})
+
+ # That's it... we're done.
+ return 1
+
+
+############
+#
+# Basic information about this template
+#
+TemplateInformation = {
+ 'Product': 'reports',
+ 'ProductStyle': 'GNUe:Reports:Char',
+ 'BaseID' : 'CharReport',
+ 'BaseClass' : CharReportTemplate,
+ 'Name' : 'Char report wizard',
+ 'Description' : 'Creates a simple single-source report.',
+ 'Version' : '0.0.1',
+ 'Author' : 'The GNUe Designer Team',
+ 'Behavior': WIZARD
+}
+
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8083 - trunk/gnue-designer/src/templates/reports,
btami <=