[albatross-users] Getting None in the __albform__?
Gregory Bond
gnb at itga.com.au
Mon Sep 16 15:43:09 EST 2002
The problem: I have a dict of IDs for which I need descriptions. (It's known
as "missing" in the code below.) When I run the attached script (which is a
cut down version of the original), it does the right thing (puts up the form
etc), but when I hit Submit I get the following traceback:
Template traceback (most recent call last):
Traceback (most recent call last):
File "/usr/local/lib/python2.1/site-packages/albatross/app.py", line 145, in run
self.merge_request(ctx)
File "/usr/local/lib/python2.1/site-packages/albatross/app.py", line 219, in merge_request
ctx.merge_request()
File "/usr/local/lib/python2.1/site-packages/albatross/context.py", line 294, in merge_request
self.set_value(name, value)
File "/usr/local/lib/python2.1/site-packages/albatross/context.py", line 321, in set_value
elems = string.split(name, ',')
File "/usr/local/lib/python2.1/string.py", line 114, in split
return s.split(sep, maxsplit)
AttributeError: 'None' object has no attribute 'split'
Having a look at the generated HTML, and doing the unpickle trick on
__albform__, I get the following:
{'desc_id1': 0, 'desc_id2': 0, None: 0}
Which is where I suspect the None in the traceback is coming from.
Any clues?
BTW: There orta be a neater way to run a template from a literal string, say
a ctx.run_template_str() function, for quick 1-pagers like this!
Greg,
New set of eyes, new set of bugs!
-------------- next part --------------
#! /usr/local/bin/python
templ = '''
<html>
<head></herad>
<body>
<table>
<tr><th>ID</th><th>Description</th></tr>
<al-form method="POST">
<al-for iter="s" expr="mkeys">
<tr>
<td><al-value expr="s.value()"></td>
<td><al-input type="text" nameexpr="'desc_%s' % s.value()"
expr="missing[s.value()]"
size="10"></td>
</al-for>
<tr>
<td colspan="2"><al-input type="submit" value="Submit"></td>
</tr>
</al-form>
</body>
</html>
'''
import sys
import albatross
from albatross.cgiapp import Request
class Input:
def page_enter(self, ctx):
ctx.locals.missing = { 'id1': '', 'id2': ''}
ctx.locals.mkeys = ctx.locals.missing.keys()
ctx.locals.mkeys.sort()
def page_display(self, ctx):
#ctx.run_template('input.html')
t = albatross.Template(ctx,'<magic>', templ)
t.to_html(ctx)
def page_execute(self, ctx):
print >> sys.stderr, "Never gets here"
app = albatross.SimpleApp('t2.py', '.', 'input', 'secret')
app.register_page('input', Input())
app.run(Request())
More information about the Albatross-users
mailing list