On 30 January 2003, Nicola Larosa said: > Sorry for the length. > > I am working on an app that has a user authentication part. I need the > following paths: [...] > /config/user/add > returns a form with empty fields for a new user > > /config/user/[loginName]/modify > returns a form with current values for a known user > > /config/user/validate > used as a form action, validates values for a added or modified user > > /config/user/[loginName]/delete > deletes a known user Err, did you mean to say "/config/user/[loginName]/validate"? If so, this makes sense. If not, how do you know which user to validate? Assuming I'm correct, this looks URL scheme sensible to me. Of course it means that no user can have a login name "add" in your system, but if you can live with that, then so can I. ;-) I didn't read Titus' response carefully, so I'm not sure if I'm about to duplicate his advice. Anyways, here's what I'd do: config/user.ptl: _q_export = ['add'] def add [html] (request): # ... emit form to create a user ... class UserUI: _q_exports = ['modify', 'delete'] def __init__ (self, name): self.user = database.get_user(name) if not self.user: raise TraversalError("no such user %r" % name) def delete [html] (self, request): database.del_user(self.user) 'User %s deleted
\n' % self.user.id def modify [html] (self, request): # ... emit form to edit self.user ... def _q_getname (request, name): return UserUI(request, name) The trick, of course, is that creating a user and editing a user are very similar, and you want to reuse the same code. You've already figured out that you want a UserForm class, but it's not clear that you've figured out what to put in it. Here's a starting point: from quixote.form import Form class UserForm (Form): def __init__ (self, user=None): Form.__init__(self) if user is None: # creating a new user self.add_widget("string", "user_id", title="User ID") self.user = None else: # modifying an existing user self.user = user self.add_widget("password", "password1", title="Password") self.add_widget("password", "password2", title="Verify password") self.add_widget("string", "email", title="E-mail address") def _render_visible_widgets (self, request): if self.user: # no 'user_id' widget -- just report existing user ID # (emulates format used by default _render_widget_row()) '\n' ' User ID \n' % self.user.id Form._render_visible_widgets(self, request) See form/form.ptl for how the various Form._render_*() methods interact. Obviously, the process() and action() methods will also branch on self.user: eg. if self.user is None, then process() has to make sure a valid user ID was entered and create a new user object, and action() has to add it to your database. Or something like that. Hope this clarifies things -- Greg -- Greg Ward - software developer gward@mems-exchange.org MEMS Exchange http://www.mems-exchange.org %s