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

Andrew McNamara andrewm at object-craft.com.au
Wed Jun 18 09:37:14 EST 2003


>So far, I've implemented a User class that loads information from the
>SQL database, and updates the SQL table with changes in the destructor.
>There's also a rollback method to cancel any changes and a commit method
>to save things on demand. The attributes of a User are implemented using
>__getattr__ and __setattr__, so they behave like variables, but I can
>input-check them if needed.

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).

>I've implemented a login mechanism that seems to work with the User
>objects. Now I'm trying to construct a user management page. The page
>consists of an HTML table with each user's information on separate rows.
>I can generate the table nicely with an <al-for> tag and a list of User
>objects passed through the execution context to the template. But I
>can't seem to make the table "active". I'd like to make some table cells
><al-input>'s so that an administrator can simply edit the information
>directly and press Submit to activate all changes at once.
>
>Currently, the code snippets that do this look as follows:
>
>mgusers.py:
>def page_display(ctx):
>    from Done import User
>    ctx.locals.userlist = User.getAll() # returns a list of User obj's
>    ctx.run_template('mgusers.html')
>
>mgusers.html:
>... table begins, <al-form> etc...
><al-for iter="u" expr="userlist">
> <tr>
>  <td><al-value expr="u.value().uid"></td>
>  <td><al-input type="text" ... ? ...></td>
>  <td><al-input type="checkbox" ... ? ...></td>
> </tr>
></al-for>
>... submit button, table ends, form ends ...

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>

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list