Say you have an input form. I can imagine having X states with this
form:
- Show the empty form to be filled out
- validate form input and either:
- save the data and show OK-screen
- discard the data, show the errors and give the user
the possibility to re-enter
Ok, this is quite some functionality for only 1 form, what do yo think
is a best practice to keep all of this compact in a CherryPy class?
cheers,
Guyon
In the app I am building, I tried to do a lot of stuff using a single
default method, and it ended up getting very messy, with a lot of 'if'
statements.
So, try it with one class, and if you don't like the results, re-build
! CherryPy is straightforward enough that you can restructure quickly.
cheers
S
I've taken no offence, it's a difficult question I suppose ;)
I started building my app, with the following structure. It still has
to show if it is a good way of doing it, but I like it so far.
---------
#--- addurl functions
def addurl(self, url=None, title=None, description=None, tags=None,
action=None):
""" show entry page """
if not isLoggedIn(): httptools.redirect('/auth/login')
if not action:
return self.show_addurl(None, url, title, description, tags)
else:
errors = self.validate_addurl(url, title, description, tags)
if errors:
return self.show_addurl(errors, url, title, description,
tags)
else:
return self.process_addurl(url, title, description, tags)
addurl.exposed = True
---------------------------
It has 1 exposed method: addurl. This one is also called from the form
with an action parameter. This way I know if the request comes from the
form.
So, if no action is present: show the form (show_addurl).
If action is present, check input for errors (validate_addurl)
If errors, show_addurl+errors
if no errors, process_addurl.
Thank you all! I've taken no offence, it's a difficult question I suppose ;) I started building my app, with the following structure. It still has to show if it is a good way of doing it, but I like it so far.
Say you have an input form. I can imagine having X states with this
form:
- Show the empty form to be filled out
- validate form input and either:
- save the data and show OK-screen
- discard the data, show the errors and give the user
the possibility to re-enter
This looks pretty cool, though I haven't been trying it out yet. I am
working on a del.icio.us - clone to get to know CherryPy. The features
are pretty much there, but it really needs a refactoring job. This
might clean up the form handling code a bit. I'll try it out and let
you know!
thanx,