CLIFFORD ILKAY wrote:
It would be nice to have a way of not having to write the fiddly HTML bits, whether using tables or DIV tags, and do something like:
self.writeln(self.form.userID.label()) self.writeln(self.form.userID.tag())
self.form.userID.label() and .tag() would expand out to either the appropriate table row/cell tag or DIV tag. I guess this is what something like Cheetah template is allegedly able to do, though I have not figured out how to do that yet.
We do have a divDump() method in there. That with CSS and you can pretty much have what you're asking for. To make FormKit itself output the "chrome" of html surrounding label, tag, error, etc... well, we've provided two ways. Anything else is up to you ;-)
I did not see the divDump() method anywhere in the Class Reference PDF. Perhaps I missed it.
One thing that we like to do is the dictionary substitution, also. Then you can just assign-up your bits like this:
subDict = { 'pass' : self.form.userID.tag(), 'name' : self.form.userName.tag(), }
Or whatever.
Then, use the '''%(pass)s''' % subDict form. Is pretty decent poor-man's templating.
I think I have to play with this to understand. Here is what I have done.
... in the __init__ method
newForm.addField(Fields.TextField('fname',[notEmpty],label="First Name"))
newForm.addField(Fields.TextField('mname',label="Middle Name"))
newForm.addField(Fields.TextField('lname',[notEmpty],label="Last Name"))
... in the writeContent() method
if self.form.fname.error():
self.writeln('''\t<tr><td class="errorLabel">Please enter a first name</td>''')
self.writeln('''\t<td class="errorField">%s</td></tr>''' % self.form.fname.tag())
else:
self.writeln('''\t<tr><td>%s</td>''' % self.form.fname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.fname.tag())
self.writeln('''\t<tr><td>%s</td>''' % self.form.mname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.mname.tag())
if self.form.lname.error():
self.writeln('''\t<tr><td class="errorLabel">Please enter a last name</td>''')
self.writeln('''\t<td class="errorField">%s</td></tr>''' % self.form.lname.tag())
else:
self.writeln('''\t<tr><td>%s</td>''' % self.form.lname.label())
self.writeln('''\t<td>%s</td></tr>''' % self.form.lname.tag())
This seems to work though I have a couple of questions about it.
1. When I click on the Submit button, if I do not enter a Middle Name, the form will not POST successfully. That is strange considering that Middle Name is not mandatory. If I enter anything in Middle Name, the form will POST. The only difference I can see between Middle Name and the other fields is that it is not mandatory and as such, I do not test for an error condition. How can I get the form to POST with a blank Middle Name field?
2. I am using SQLObject to map the PostgreSQL tables to Python objects. I have that part prototyped and working. Once I get past the hurdle above, I have to transfer the contents of the form fields above to the Person object attributes. According to the Class Reference, I think I should be using self.form.value(fieldName) to do this. e.g.
if self.form.isSuccessful():
newPerson = Person(
firstName = self.form.value(fname),
middleName = self.form.value(mname),
lastName = self.form.value(lname),
)... where Person is a SQLObject class corresponding to a PostgreSQL table. Am I on the right track?
Regards,
Clifford Ilkay Dinamis Corporation 3266 Yonge Street, Suite 1419 Toronto, Ontario Canada M4N 3P6
Tel: 416-410-3326
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss
