[albatross-users] Need some hints on: filling in a grid

Michael C. Neel neel at mediapulse.com
Sat Feb 28 01:45:58 EST 2004


Aliases to the rescue!

I'm going off of the general idea here, you'll have to adapt it, but say
it's a 3x3 grid.  If we can number each box 1-9 and assume a setup like:

123
456
789

The first we setup a box class, with an albatross alias:

class Box(object):

	def __init__(self, position):
		self.postition = position
		self.value = ''

	def albatross_alias(self):
		# this must be unique
		# in a pinch, you can do some id() and time() trickery
to make up 
		# a unique value
		return self.position

... Then in our page module populate a list ...

ctx.locals.boxes = []
for i in range(1,10):
	ctx.locals.boxes.append(Box(i))

... Then in the template ...

<al-for expr="boxes" iter="row" cols="3">
	<tr>
		<al-for expr="row.value()" iter="cell">
			<td>
				<al-input type="text"
alias="cell.value().value">
			</td>
		</al-for>
	</tr>
</al-for>

... And back in the page module on submit ...

for box in ctx.locals.boxes:
	do_something(box.value)

Mike

> -----Original Message-----
> From: albatross-users-admin at object-craft.com.au 
> [mailto:albatross-users-admin at object-craft.com.au] On Behalf 
> Of Gregory Bond
> Sent: Friday, February 27, 2004 1:31 AM
> To: albatross-users at object-craft.com.au
> Subject: [albatross-users] Need some hints on: filling in a grid
> 
> 
> I have an application where the user needs to fill in some 
> entries on a grid.  
> Typical size might be 20 rows by 5 columns, and maybe 20% of 
> the squares would 
> need to be entered. (If it helps, the entries should all be 
> integers > 0).
> 
> I'm struggling to find a natural way to handle this in Albatross.
> 
> My first cut did something like this:
> 
>  <al-for iter="r" expr="range(rows)">
>    <tr>
>      <al-for iter="c" expr="range(cols)">
> 	<td>
>           <al-input type="text" namexpr="'r%dc%d' % 
> (r.value(), c.value())" />
>         </td>
> etc
> 
> This has 3 problems, more or less, as it stands:
> 
> - Finding out which cells are entered is awkward:
> 	for r in range(rows): 
> 	  for c in range(cols):
> 	    v = getattr(ctx.locals, 'r%dc%d' % (r, c))
> 	    if v: 
> 	      # Do stuff
> 	      # may need to be "v is not None" depending on blanks etc
> 
> - If I discover an error in the page_process() (i.e. 
> mis-typed cell contents),
> then redisplaying the page without navigating to a new one 
> blanks all the
> cells.  This is a surprise.....  and a pain if if forces a 
> bunch of re-typing.
> It seems the "fill in the default value from ctx.locals" is 
> not working for
> al-input when nameexpr is used instead of name?
> 
> - (this is a web problem more than an Albatross problem...) 
> When typing in a 
> cell, the browser keeps "helpfully" suggesting possible 
> completions in little 
> tool-tip-like boxes.  This is a HUGE PITA.
> 
> Any clues or ideas?
> 
> 
> 
> _______________________________________________
> Albatross-users mailing list
> Albatross-users at object-craft.com.au
> https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albat
ross-users




More information about the Albatross-users mailing list