Search the web
Sign In
New User? Sign Up
ClearSilver
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Multiptle lines of output   Message List  
Reply | Forward Message #1235 of 1347 |
Re: Multiptle lines of output

On 12/07/08 Dan uttered the following other thing:
> Brandon Long(blong@...)@2008.12.06 21:19:08 -0800:
> > On 12/06/08 Dan uttered the following other thing:
> > > Hi. I am trying to figure out how to display multiple lines of several
> > > values. I know this is basic and done all the time in CGIs, but I am
> > > having trouble wrapping the template around it.
> > >
> > > I am reading data from a text file in python one line at a time. For all
> > > lines in the file I want to display each line as a set (list) of values
> > > on a form in a page. Displaying one line is easy in template, but how
> > > would I store multiple lines in HDF and read in a template??
> >
> > I'm not sure what you're trying to do, exactly, but:
>
> Sorry, let me try to explain better.
>
> The file is really irrelevant, it could be a database instead. If it
> were a database, I would read a row from a table, each row's culumns
> would be separate variables. So I just need to read rows of data, and
> display them in html.
>
> In this case it's DNS data:
>
> type | hostname | ip address | time
>
> They're displayed as default values in a form, which can be submitted
> back to the CGI and written back.

x =
for (type, hostname, ipaddr, t) in dnsdata:
ncgi.hdf.setValue("Entry.%d.type" % x, type)
ncgi.hdf.setValue("Entry.%d.hostname" % x, hostname)
ncgi.hdf.setValue("Entry.%d.ipaddr" % x, ipaddr)
ncgi.hdf.setValue("Entry.%d.time" % x, t)

Then, in the template:

<form action=>
<?cs each:entry = Entry ?>
<input type=text name="entry.<?cs var:name(entry) ?>.type"
value="<?cs var:html_escape(entry.type) ?>">
<input type=text name="entry.<?cs var:name(entry) ?>.hostname"
value="<?cs var:html_escape(entry.hostname) ?>">
<input type=text name="entry.<?cs var:name(entry) ?>.ipaddr"
value="<?cs var:html_escape(entry.ipaddr) ?>">
<input type=text name="entry.<?cs var:name(entry) ?>.time"
value="<?cs var:html_escape(entry.time) ?>">
<?cs /each ?>
</form>

And then, to read them back:

node = ncgi.hdf.getChild("Query.entry")
dnslist = []
while node != None:
dtype = node.getValue("type", "")
hostname = node.getValue("hostname", "")
ipaddr = node.getValue("ipaddr", "")
t = node.getValue("time", "")
dnslist.append( (dtype, hostname, ipaddr, t) )
node = node.next()

Obviously, you'll probably use different input elements, and you
need to actually validate the results, but that's the basic gist.

Brandon
--
"There are Gods older than the ones you know, their true names long
forgotten. They are still here. We do not even think of them as
Gods, but we worship them today."
-- PLIF 2001-07-12 http://www.plif.com/archive/wc274.gif



Tue Dec 9, 2008 11:22 pm

blong42
Offline Offline
Send Email Send Email

Forward
Message #1235 of 1347 |
Expand Messages Author Sort by Date

Hi. I am trying to figure out how to display multiple lines of several values. I know this is basic and done all the time in CGIs, but I am having trouble...
Dan
strangepics
Offline Send Email
Dec 6, 2008
4:21 pm

... I'm not sure what you're trying to do, exactly, but: foo.hdf: Option.1 = Foo Option.2 = Bar Option.3 = Baz foo.cs: <form action=/foo.do> <?cs each:opt =...
Brandon Long
blong42
Offline Send Email
Dec 7, 2008
5:19 am

... Sorry, let me try to explain better. The file is really irrelevant, it could be a database instead. If it were a database, I would read a row from a table,...
Dan
strangepics
Offline Send Email
Dec 9, 2008
6:39 pm

... x = for (type, hostname, ipaddr, t) in dnsdata: ncgi.hdf.setValue("Entry.%d.type" % x, type) ncgi.hdf.setValue("Entry.%d.hostname" % x, hostname) ...
Brandon Long
blong42
Offline Send Email
Dec 9, 2008
11:22 pm

... Thanks, that makes sense, but I still can't seem to get values out of HDF (empty). Is there a way to dump the whole HDF for debugging? Thanks....
Dan
strangepics
Offline Send Email
Dec 12, 2008
3:17 pm

... Actually I had a bug. It works now. However I have trouble understanding how it works (in the template). Thanks....
Dan
strangepics
Offline Send Email
Dec 12, 2008
4:42 pm

There are some debugging HDF values which we use to cause the HDF contents to be dumped into the rendered page. ...
David Jeske
jeskeca
Offline Send Email
Dec 12, 2008
8:14 pm

... Thanks!...
Dan
strangepics
Offline Send Email
Dec 14, 2008
5:14 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help