[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnumed-devel] forms concept (instead of placeholders)

From: Jerzy Luszawski
Subject: [Gnumed-devel] forms concept (instead of placeholders)
Date: Sat, 3 Oct 2009 21:22:26 +0200
User-agent: KMail/1.9.10


I continue to develop my branch of gnumed, and seeing the latest posts about 
placeholders, I decided to share my concept of generating all kind of printouts.

1. My needs:
        - all data from backend should be available to a form, so no fixed list 
of placeholders is acceptable
        - a form may contain data from unknown number of records (1 or more)
        - a form should be editable after creation
        - a form with data need NOT be stored in backend after creation

2. Using OpenOffice Writer with Python bridge did not work for me

3. Currently the best option IMHO is preparing data for a form in XML format, 
then process it with XSLT template to get a HTML file. This file is easily 
loaded into OO Writer or displayed in browser. so it can be previewed, edited 
and printed out. The XML can also be exported to another application if needed. 
This may be a common path for many uses.

4. The key for implementation is the decission to fetch data for the template 
directly from backend using SQL query. This query is stored together with 
template (a new field in ref.paperwork_templates is required, I added 
'sql_query'::text). It may have parameters just like any other query executed 
via gmPG2.run_ro_queries.  It returns all data at once, no need to collect data 
from multiple objects.
Now just few easy steps are required:
        get the template
        fetch data (== execute the sql query with supplied parameters), making 
valid XML document from them
        apply XSLT from template

5. The nice thing about postgresql is that it can output a table in XML format 
(see query_to_xml function). Using it I can avoid the problem of characters 
that need to be escaped in XML. The drawback is the ugly look with many quotes, 
which may be confusing.

6. I enclose in the attached file the class cFormXSLT I use for this processing.
The typical invocation is like this:
        #get a template object
        template = 
        #get a form object based on this template
        _report = cFormXSLT(template)
        #process it: fetch data, apply stylesheet
        #parameters are prepared like for any gmPG2.run_ro_queries
        _report.process(sql_parameters = {'pkeys': 
self.__curr_node_data['pk_episode']})        #you can pass more pkeys if you 
        #display (I always preview the reports in OO Writer)

7. This approach is the most flexible and does not need any changes in 
application code to get a form. You can make single or multi-row templates. You 
have the possibility to use CSS or other formatting. 
An example SQL queries are here:

An example XSL template:

To resolve problem of text fields with multiple paragraphs (hard line breaks) I 
filter these fields through a function 'xml_paragraphs', then add corresponding 
template in XSLT. The function is here:

8. Enjoy. Comments and improvements welcomed ;-)

Jerzy Luszawski

Description: application/python

reply via email to

[Prev in Thread] Current Thread [Next in Thread]