Source code for: 'languages2.py'


#!/usr/bin/python
"""
generate HTML for main page dynamically from an executable Python script, 
not a precoded 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><title>Languages2</title>
<body text="#000000" leftmargin=0 topmargin=0 bgcolor="#C2C2C6">
<table width=850 border=0 cellspacing=0 cellpadding=0>
  <tr>
  <td align=center>

<h1>Hello World selector</h1>
<table width=650>
<tr><td>

<P>Similar to file <a href="../ebiz/enterprise/python/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.py?filename=languages2.py">here</a>,
<a href="getfile.py?filename=languages2reply.py">here</a>, and
<a href="getfile.py?filename=languages2common.py">here</a>.
</P>
<hr>
<form method=POST action="/cgi-bin/languages.py">
    <P><B>Select a programming language:</B>
    <P><select name=%s>
        <option>All
        %s
        <option>Other
    </select>
    <P><input type=Submit>
</form>
</body></html>
"""

from languages2common import hellos, inputkey

options = []
for lang in hellos:                        # we could sort keys too
    options.append('<option>' + lang)      # wrap table keys in HTML code
options = '\n\t'.join(options)
print(REPLY % (inputkey, options))         # field name and values from module