[albatross-users] Albatross Form Question
Michael C. Neel
neel at mediapulse.com
Sat Apr 3 10:20:50 EST 2004
> There is also some mention of creating __setitem__ and __getitem__ methods
> for my customer object, to allow a more "loop" like approach to setting
> and getting. Although I can see how these would work nicely if my
> customer data was stored in a dictionary, I don't see how to use them when
> my customer data is accessed via methods.
>
> I'm afraid what I may have done is built a customer object that isn't as
> python friendly as it could be. I really liked the idea of having a
> 'firstName' method that could retrieve, store, and run sanity checks but
> perhaps I need to work with the customer class in some other way?
>
> Or perhaps I just need to come to terms with having a bulky
> CustomerController?
No, you have what you need, just not up on python enough yet (hint: read
Dive into Python =). Using hasattr, getattr, and setattr your
controller wouldn't need to know anthing at all about the underling
cusror object. Using some calls to mysql for table info, and/or using
c.description information you could preform basic checks on the data.
You would still need to hook in complex checks such as is this a valid
email, but it wouldn't be much.
You also have a dictionary of class members in vars(self) if that
approach helps. I'm assuming your using MySQLdb? In which case you can
also use a DictCursor class/mixin if getting the result set back as a
dict would help.
Your going down the right path I think. If you get a solid Controller
class, albatross has the tools to expose that Controller in the
template, leaving your app logic to the app and not mundane
get-validate-update. Then agin, so much of what we do on the web is
get-validate-update you may find yourself with nothing to do =p.
Mike
More information about the Albatross-users
mailing list