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