XSLTools

examples/Common/DemoApp.py

602:538454a419e2
2007-07-07 paulb [project @ 2007-07-07 16:54:23 by paulb] Fixed filename used for the dictionary demo.
     1 #!/usr/bin/env python     2      3 """     4 A demonstration of XSLTools. This is a quick and dirty combination of an     5 adapter, employing lots of resources, and the index page resource.     6 """     7      8 # Import the things which publish parts of the application.     9     10 from WebStack.Resources.ResourceMap import MapResource    11 import os, sys    12     13 # Here are all the example applications.    14     15 import Candidate    16 import Configurator    17 import Dictionary    18 from Dictionary.Dict import Dict    19 import Questionnaire    20 import PEP241    21 import Recursive    22 import VerySimple    23 import VerySimpleWithLogin    24     25 # A very simple index page.    26     27 from WebStack.Generic import ContentType    28     29 # Configuration settings.    30 # NOTE: Change the filesystem encoding if appropriate.    31     32 fsencoding = "iso-8859-15"    33     34 # Resource classes.    35     36 class DemoResource:    37     def respond(self, trans):    38         trans.set_content_type(ContentType("text/html"))    39         trans.get_response_stream().write("""    40 <html>    41   <head>    42     <title>XSLTools Examples</title>    43   </head>    44   <body>    45     <h1>XSLTools Examples</h1>    46     <p>Here are some of the examples supplied with XSLTools:</p>    47     <ul>    48       <li><a href="candidate">A job candidate profile editor</a></li>    49       <li><a href="configurator">A Webshop-style system configurator</a></li>    50       <li><a href="dictionary">A simple word lookup interface</a></li>    51       <li><a href="questionnaire">A questionnaire generator</a></li>    52       <li><a href="pep241">A Python package repository user interface</a></li>    53       <li><a href="recursive">A recursive template example</a></li>    54       <li><a href="verysimple">A very simple example</a></li>    55       <li><a href="verysimplewithlogin">A very simple example requiring a login</a></li>    56     </ul>    57     <p>You can run all of the examples independently, too. See the    58        <code>examples</code> directory for the code.</p>    59   </body>    60 </html>""")    61         trans.set_response_code(200)    62     63 # Find out where our example document will be for the dictionary example.    64     65 def get_site(host):    66     67     """    68     Define the resource mapping, using the server 'host' URL to initialise some    69     examples.    70     """    71     72     # Find a file for use with the Dictionary example.    73     74     exec_dir = os.path.split(sys.argv[0])[0]    75     parts = os.path.split(exec_dir)    76     if parts[-1] == "tools":    77         parts = parts[:-1]    78     parts += ("docs", "gpl-3.0.txt")    79     doc = os.path.join(*parts)    80     dict = Dict(doc)    81     82     # Define the site resource itself.    83     84     resource = MapResource({    85     86         # Use the current working directory so that the installed package can still run    87         # the demo.    88     89         "candidate" : Candidate.get_site(fsencoding, use_cwd=1),    90         "configurator" : Configurator.get_site(),    91         "dictionary" : Dictionary.get_site(dict),    92         "questionnaire" : Questionnaire.get_site(),    93         "pep241" : PEP241.get_site(),    94         "recursive" : Recursive.get_site(),    95         "verysimple" : VerySimple.get_site(),    96         "verysimplewithlogin" : VerySimpleWithLogin.get_site(host),    97         "" : DemoResource(),    98         })    99    100     return resource   101    102 # Resource preparation ahead of time - useful for making installations.   103    104 def prepare_resources():   105     for module in [Candidate, Configurator, Dictionary, Questionnaire, PEP241, Recursive, VerySimple, VerySimpleWithLogin]:   106         module.prepare_resources()   107    108 # vim: tabstop=4 expandtab shiftwidth=4