#!/usr/bin/python
#################################################################
# generate html for main page dynamically from an executable
# Python script, not a pre-coded HTML file; this lets us 
# import the expected input field name and the selection table 
# values from a common Python module file; changes in either 
# now only have to be made in one place, the Python module file.
#################################################################

REPLY = """Content-type: text/html

<html><body>
<title>Languages2</title>
<h1>Hello World selector</h1>
<P>Similar to file <a href="languages.html">languages.html</a>, but 
this page is dynamically generated by a Python CGI script, using 
selection list and input field names imported from a common Python 
module on the server. Only the common module must be maintained as 
new languages are added, because it is shared with the reply script.

To see the code that generates this page and the reply, click
<a href="getfile.cgi?filename=languages2.cgi">here</a>, 
<a href="getfile.cgi?filename=languages2reply.cgi">here</a>, 
<a href="getfile.cgi?filename=languages2common.py">here</a>, and
<a href="getfile.cgi?filename=formMockup.py">here</a>.</P>
<hr>
<form method=POST action="languages2reply.cgi">
    <P><B>Select a programming language:</B>
    <P><select name=%s>
        <option>All
        %s
        <option>Other
    </select>
    <P><input type=Submit>
</form>
</body></html>
"""

import string
from languages2common import hellos, inputkey

options = []
for lang in hellos.keys():
    options.append('<option>' + lang)      # wrap table keys in html code
options = string.join(options, '\n\t')
print REPLY % (inputkey, options)          # field name and values from module

