[albatross-users] Request for hints on building a complex application

Fabian Fagerholm fabbe at paniq.net
Wed Jun 18 17:18:44 EST 2003


On Wed, 2003-06-18 at 02:37, Andrew McNamara wrote:
> I would suggest not having a destructor (and particularly, no commiting
> the changes in the destructor). My experience has been that having the
> application explicitly commit the changes better fits the way things work
> (in particular, if you get an exception, you don't want inconsistent
> state commited to the database).
> 
> A few more reasons for not defining a __del__ method are that the
> destructor is not guaranteed to be called (although it usually is),
> and cyclic garbage collection is disabled for instances of classes that
> define it (because the cycle breaker doesn't know what order to call
> the destructors in).

Good points. Also, the current destructor would have had to keep track
of whether any changes had been made to the object, otherwise a whole
bunch of unneccessary commits would have been made each time an
unmodified object was destroyed.

> Something like:
> 
>         <al-for iter="u" expr="userlist">
>          <tr>
>           <td><al-input nameexpr="'userlist[%d].text' % u.index()"></td>
>           <td><al-input nameexpr="'userlist[%d].checkbox' % u.index()"></td>
>          </tr>
>         </al-for>

I had something similar going, but confused myself with the value()
method of the iterator. However, using the above, I run into problems
when Albatross is trying to merge the request into the execution
context. When I submit the form, this happens:

Template traceback (most recent call last):

Traceback (most recent call last):
  File "/usr/lib/python2.2/site-packages/albatross/app.py", line 145, in run
    self.merge_request(ctx)
  File "/usr/lib/python2.2/site-packages/albatross/app.py", line 219, in merge_request
    ctx.merge_request()
  File "/usr/lib/python2.2/site-packages/albatross/context.py", line 297, in merge_request
    self.set_value(name, value)
  File "/usr/lib/python2.2/site-packages/albatross/context.py", line 323, in set_value
    if name[0] == '_':
TypeError: unsubscriptable object

Which object is it referring to? The request now has fields of the form
userlist[i].attr, where i is an integer and .attr is each of the
elements of my User object. Is it trying to find the first character of
the list name?

Also, I'm still a little confused as to what exactly is happening here.
Am I storing the actual list, complete with User objects, in the
session? Or am I only storing text -- ie. will I have to recreate the
list and the User objects in page_process()? I guess the confusion
arises because I'm actually redoing an application that has been
previously (badly) implemented with Java Servlets...

I suspect this is a question which comes up quite soon after you move to
anything more complex than the popview application. (In particular, when
you build an abstraction layer of your business logic with a
transactional database as a back-end.)

-- 
Fabian Fagerholm <fabbe at paniq.net>
paniq.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.object-craft.com.au/pipermail/albatross-users/attachments/20030618/dae9cea4/attachment.pgp>


More information about the Albatross-users mailing list