473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

ADD HTML to the code

Could someone tell me how to add some HTML tags to this program. I want
to be able to change the background color, add some headers, and put a
table below the map that will be displayed. Could someone please tell
me how to add this to the current program. Thanks in advance.

Red.py

""" Publisher example """

def query(req, building=""):
# NOTE: best way to understand this is to see the output,
# that is, to "view source" on the generated web page
# read common header for any google mapping
f = file('/home/ta/public_html/maplish/googleHead.html','r')
t = f.read()
f.close()
# define the two buildings we know (because no SQL is done here)
buildings = [ ("cb", "Cambus Office", "-91.552977", "41.659655")
]
buildings += [ ("va/hardlib", "VA/Hardin Library", "-91.549501",
"41.662348") ]
buildings += [ ("hancher", "Hancher Auditorium", "-91.538214",
"41.669529") ]
buildings += [ ("currier", "Currier Hall", "-91.534996",
"41.666163") ]
buildings += [ ("schaeffer", "Schaeffer Hall", "-91.535296",
"41.660969") ]
buildings += [ ("shospital", "South Hospital", "-91.548900",
"41.658885") ]
str = '' # in case no buildings match, use empty string
for x in buildings:
a,b,c,d = x # isolate all the tuple components into a,b,c,d
if building.lower() == a:
# construct javascript, using Python %s to substitute names
and data
# see http://docs.python.org/lib/typesseq-strings.html if
needed
str = 'var bldg%s = new GPoint( %s, %s);\n' % (a, c, d)
str += 'var mrk%s = new GMarker( bldg%s );\n' % (a, a)
str += 'var htm%s = "%s";\n' % (a, b)
str += 'GEvent.addListener(mrk%s,"click",function() {' % a
str += 'mrk%s.openInfoWindowHtml(htm%s); });\n' % (a, a)
str += 'map.addOverlay(mrk%s);\n' % a
# output markers, if any
t = t + str
# then add trailing html to finish page
trail = "//]]> </script> </body> </html>"
t = t + trail
return t

htaccess

SetHandler python-program
PythonHandler mod_python.publisher
PythonDebug On

googleHead.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<TITLE>University of Iowa Cambus</TITLE>
<script
src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAoq-X4K0kg9eYo1EhqRtUSxRepKXVB5XJtiHJ0W4XJYyDQ5hNnxQKi 9AqI9J1B9uwt8TVJptjDwSqPA"
type="text/javascript"></script>
</head>
<body>
<form action="query" method="get">
Street Address in Iowa City:
<input type="text" name="address">
</form>
<p>
<div id="map" style="width: 800px; height: 600px"></div>
<script type="text/javascript">
//<![CDATA[

var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.centerAndZoom(new GPoint(-91.527786,41.661114), 2);

Dec 4 '05 #1
3 2522
"Little" <co************@yahoo.com> wrote:
Could someone tell me how to add some HTML tags to this program. I want
to be able to change the background color, add some headers, and put a
table below the map that will be displayed. Could someone please tell
me how to add this to the current program.


the code reads the first part of the HTML from the googleHead.html file,
and the rest is added in the section that starts with the

# then add trailing html to finish page

comment.

assuming that you know how you want the HTML to look (styles and headers
should go into the googleHead file, the table into the "trailing html" part), a
text editor and the string chapters from the python tutorial should be enough
to get you going:

http://docs.python.org/tut/tut.html

</F>

Dec 5 '05 #2
Fredrik Lundh wrote:
"Little" <co************@yahoo.com> wrote:

Could someone tell me how to add some HTML tags to this program. I want
to be able to change the background color, add some headers, and put a
table below the map that will be displayed. Could someone please tell
me how to add this to the current program.

the code reads the first part of the HTML from the googleHead.html file,
and the rest is added in the section that starts with the

# then add trailing html to finish page

comment.

assuming that you know how you want the HTML to look (styles and headers
should go into the googleHead file, the table into the "trailing html" part), a
text editor and the string chapters from the python tutorial should be enough
to get you going:

http://docs.python.org/tut/tut.html


You might also want to think about the version below, which (though
untested) uses rather commoner ways of expressing the same ideas:

""" Publisher example """

def query(req, building=""):
# NOTE: best way to understand this is to see the output,
# that is, to "view source" on the generated web page
# read common header for any google mapping
f = file('/home/ta/public_html/maplish/googleHead.html','r')
t = f.read()
f.close()
# define the two buildings we know (because no SQL is done here)
# Did I say two? Obviously there are six now ...
# We just build the list as a single literal value
buildings = [
("cb", "Cambus Office", "-91.552977", "41.659655"),
("va/hardlib", "VA/Hardin Library", "-91.549501","41.662348"),
("hancher", "Hancher Auditorium", "-91.538214","41.669529"),
("currier", "Currier Hall", "-91.534996","41.666163"),
("schaeffer", "Schaeffer Hall", "-91.535296","41.660969"),
("shospital", "South Hospital", "-91.548900","41.658885")
]
st = [t] # in case no buildings match, use empty string
for a, b, c, d in buildings:
if building.lower() == a:
# construct javascript, using Python %s to substitute names
and data
# see http://docs.python.org/lib/typesseq-strings.html if needed
st.append('var bldg%s = new GPoint( %s, %s);\n' % (a, c, d)])
st.append('var mrk%s = new GMarker( bldg%s );\n' % (a, a))
st.append('var htm%s = "%s";\n' % (a, b))
st.append('GEvent.addListener(mrk%s,"click",functi on() {' % a)
st.append('mrk%s.openInfoWindowHtml(htm%s); });\n' % (a, a))
st.append('map.addOverlay(mrk%s);\n' % a)
# output markers, if any
# then add trailing html to finish page
trail = "//]]> </script> </body> </html>"
return "".join(st)+trail

Note that "str" is the name of a built-in data type, so I changed it to
"st".

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Dec 5 '05 #3
Little wrote:
Could someone tell me how to add some HTML tags to this program. I want
to be able to change the background color, add some headers, and put a
table below the map that will be displayed. Could someone please tell
me how to add this to the current program. Thanks in advance.

(snip)
Do yourself a favor : check the various templating tools available,
choose one that fits you taste, and stop embedding half-baked html in
your Python code.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Dec 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
10
by: Andrew Poulos | last post by:
While this works on IE 6: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>aiff</title> <meta http-equiv="Content-Type"...
3
by: mca | last post by:
Hi everyone, I'm new to asp.net and i have a question about separating the html code from the programming code. i have an unknown numbers of entries in my table. I want to make a hyperlink...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
7
by: Xah Lee | last post by:
Summary: when encountering ex as a unit in css, FireFox (and iCab) did not take into account the font-family. Detail: http://xahlee.org/js/ff_pre_ex.html Xah xah@xahlee.org ∑...
26
by: webrod | last post by:
Hi, I have some php pages with a lot of HTML code. I am looking for a HTML validator tool (like TIDY). TIDY is not good enough with PHP tags (it removes a lot of php code). Do you have any...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
1
by: since | last post by:
I figured I would post my solution to the following. Resizable column tables. Search and replace values in a table. (IE only) Scrollable tables. Sortable tables. It is based on a lot...
11
Dormilich
by: Dormilich | last post by:
Lately I have seen so much awful HTML, that I like to show what a HTML document should look like, regarding the requirements from the W3C. the absolute minimum is defined as: or expressed in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.