473,386 Members | 1,602 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,386 software developers and data experts.

Putting in an html table

Could someone start me on putting in a table into this code, and some
HTML tags. I would to make the table below the map and have a header at
the top. Thanks for the help.

""" 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

Dec 4 '05 #1
1 1471
Little wrote:
Could someone start me on putting in a table into this code, and some
HTML tags. I would to make the table below the map and have a header at
the top. Thanks for the help.

""" 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')
Never hardcode a path.
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") ]
# avoid useless operations
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")
]

str = '' # in case no buildings match, use empty string # don't use 'str' as an identifier, it will shadow the builtin str type.

for x in buildings:
a,b,c,d = x # isolate all the tuple components into a,b,c,d
if building.lower() == a:
If what you want is to find the building matching the one given as
argument, you should build a dict, not a list of tuples.

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")
}

Now you don't need to loop and compare, a simple :
buildings.get(building.lower())
should be enough

(NB : Anyway, this dict should not be hardcoded. Put this in a separate
conf file, in a db, or whatever, but keep it out of the code.)

# 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
string concatenation is not an efficient idiom. In a loop, the common
idiom is to use a list and join it, but here I guess a triple quoted
string and simple templating trick would be better.

# output markers, if any
t = t + str
# then add trailing html to finish page
trail = "//]]> </script> </body> </html>"
t = t + trail
return t


This is definitevely not how I would do HTML/js in Python. There are a
lot of templating / HTML generation tools available, that allow to
cleanly separate logic from presentation.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Dec 5 '05 #2

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

Similar topics

4
by: Eric Kincl | last post by:
Hello, its been a while since I posted/looked here... my normal email client doesn't handle newsgroups :( (ximian evolution) I was wondering how you stick a file into a database, and then...
1
by: newtda | last post by:
What I am trying to do is when the user clicks on the date th month/date/year appears in the text box like this: 1/15/2004. Ho would I do this. This is not home work, but it is for a client o...
3
by: Jamie Jackson | last post by:
Is there a way to outline a group of cells in a table, similar (sorta) to the <fieldset> tag? Only possible with clever css borders? Thanks, Jamie
6
by: dedejavu | last post by:
Hi all you JS experts, Is there any way to put a blinking ibeam cursor in middle of td text - the same way it would blink if I clicked in the middle of the text in a text input? To further...
4
by: jty202 | last post by:
I have raw formated data (comma separated), and I like to store it in a good datatype/collection object. And display the data in the data object in a HTML table. The data looks like this: ...
1
by: Ed West | last post by:
Hello, How can I put a textbox control into a cell of an asp:Table? I was not able to do it from the properties sheet, so I put it in via html tab, but now I can't select it from the Design tab...
1
by: Bart Lateur | last post by:
I'm trying to put a utton at the bottom (right) of a TD cell, irrespective of what else is in there. Usually, with other HTML block elements, we're told to use position: relative on the...
1
by: nagamalli26 | last post by:
hai iam new php. i am creating admin side. i wrote this, phpcode: <?php //include_once("config.php"); $con=mysql_connect("localhost","root",""); mysql_select_db("happysalary"); ?>
1
by: egiblock | last post by:
i have a page that is showing the table and font text correctly, but the table border for the first row is not showing up . i can't find what's wrong. html code: <table width="90%" border="0"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.