[albatross-users] Albatross Form Question

Michael C. Neel neel at mediapulse.com
Sat Apr 3 00:16:25 EST 2004


Search the list and the docs for the alias attribute for input tags, it 
will do exactly what you need.  A quick summary; you add an 
albatross_alias method to your customer class that takes no arguments 
and returns a unique string for the object's instance - in your case 
using the pri key from the mysql table would be enough.  Then in the 
template, use alias="c.firstname" instead of name and expr.

Note the albatross is going to look for a variable not a method.  I 
think there are two ways you can do this, one is add a method .update() 
in which you call on processing to actually commit the changes to the 
database, the other would be looking into adding a custom __setattr__ 
method that provides the actions you need.

If your new to python, but an experienced programmer, a good book is 
Dive Into Python, which is free at http://diveintopython.org/.

Mike

alan.junk at sunwave.com wrote:
> Hello Everyone,
> 
> I've spent the last few days drooling over albatross, reading
> documentation and code samples.  It looks like a dream come true the
> things I have to program.
> 
> Unfortunately, now that I have finally sat down to write my first
> albatross application, I'm feeling very lost.  In addition to being new to
> albatross, I'm also a python newbie, so I am not sure if I am even
> approaching my problem from the right direction.
> 
> Let me explain.
> 
> Outside of albatross, I currently create customer objects in python and
> manipulate them.  For instance:
> 
> # create customer object
> c = customer(username)
> 
> # read firstname of customer
> firstname = c.firstName()
> 
> # set firstname of customer
> c.firstname('bob')
> 
> Most of the what the object does is simply manipulate a MySQL backend, but
> it also runs some checks.
> 
> Inside albatross, I want to create forms (some of them multipaged and
> stateful) that will read and manipulate my customer object.
> 
> After browsing the albatross docs, I came up with an albatross tag like
> this on a form:
> 
> First Name: <al-input type="TEXT" name="firstName" expr="c.firstName()">
> 
> When I load the form, it shows me an input field with the customer
> object's firstName() value inside it.  Good so far.
> 
> The part that I'm hung up on is saving form input.  I am able to do it
> with something like this:
> 
> def page_process(self, ctx):
> ...
> c = customer(username)
> c.firstName(ctx.get_value('firstName'))
> c.lastName(ctx.get_value('lastName'))
> ...and so on...
> 
> This works but it feels kludgy.  It also seems totally in opposition to
> the spirit of albatross.  The bigger my form is the more it bloats my
> python code, and if I want to add a field to my form (that will be saved,
> anyhow), I have to edit the python script and that feels weird.
> 
> Am I approaching this from the wrong direction? Any advice?
> 
> Thank you!
> 
> Alan
> 
> 
> 
> 
> _______________________________________________
> Albatross-users mailing list
> Albatross-users at object-craft.com.au
> https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users



More information about the Albatross-users mailing list