AJAX and CherryPy: Most of the application becomes Javascript rather than python?

162 views
Skip to first unread message

brahmaforces

unread,
Jun 5, 2008, 5:21:51 AM6/5/08
to cherrypy-users
Hi All,

In creating my web system I wanted to create a string of Select Boxes
where the selection in one results in the appearance of the 2nd with
values that depend on the Selection in the 1st and this severaltimes
over. In general one could use the postback method or the AJAX method.
The post back method is obsolete from an interface point of view. This
leaves the AJAX method.

My issue is this. If AJAX functionality is the way to go on the client
side, then most of the coding is done on the client side in Javascript
and very little coding is required on the server side in Python. And
the whole point was/is to code in the beloved Python!

So what is the approach that you all are taking. If one accepts AJAX
as the way to create non refresh convenient widgets and functionality,
does that mean that we can only code in python for the left over
stuff, and most of the programming is consumated in Javascript?

If this is the case, where does that leave cherrypy, because CP is
primarily to allow programmers to code for the web in python. The AJAX
model makes most of the code client side.

I googled and searched the groups but found no discussion on this. I
find that if I want to make things happen AJAXLY ie non refersh, then
there is little server side code. Is this true?

bernard.chhun

unread,
Jun 6, 2008, 9:10:38 AM6/6/08
to cherrypy-users
hey brahmaforces,

it all depends on the amount of the things you do on the server side I
guess. I'm currently coding this
huge client/inventory/rental system with CherryPy using bits of
XmlHttpRequest here and there. I'd say the amount of code
for the user interface is almost as lengthy as the server side one.
I tend to use javascript libraries such as JQuery or ExtJs to ease DOM
manipulation so it's just a matter of
linking your stuff together instead of rewriting your own javascript
for your interface. You just need to choose carefully where you should
add javascript.

let's say I have a rental form that I need to fill with a client, some
dates and items to rent.

The user wants to add a new rental so it goes to the rental adding
form. There's an autocomplete ajax call to get the client once the
user begins typing a name/phone number.
There's also a handy javascript calendar to select the rental starting
and ending dates. Here, it's just a matter of choosing the jquery
calendar widget so there ain't too much coding to do for you.
Adding items also uses some autcomplete as the user types the item
number. the autocomplete then fills up the rest of the item's
information. And saving the rental uses a simple POST.

If the user wants to edit that particular rental, he goes into the
rental modification form (which is the same as the rental adding one
with a particular flag). Once there, I don't use javascript to fill in
the information that was entered in the 1st step. I give all those
informations to the form template and fill everything up adding the
client, the dates and a loop to add every items. all done by Python
and Cheetah Template. Once everything is added, I sprinkle the
necessary javascript on the inputs/select boxes/check boxes. That part
is really easy with JQuery.

There ya go. I hope my example has cleared your vision on the matter a
bit. In short, Python handles the data and whatever-template-language-
that-spits-HTML/CSS/Javascript does the rest.
There's plenty of Python in there!

Bernard

brahmaforces

unread,
Jun 7, 2008, 1:39:42 AM6/7/08
to cherrypy-users
Ill check out Jquery, any other recommendations for javascript object
libraries that work well and dont have too much of a learning curve.
ie i dont want to waste my time learning another framework in too much
detail something that provides widgets and simple objects without
providing a large api?

bernard.chhun

unread,
Jun 7, 2008, 5:32:25 PM6/7/08
to cherrypy-users
mooFX & JQuery are both great choices man :)

I have this little preference over JQuery as I've worked more often
with it.

arjuna

unread,
Jun 10, 2008, 1:25:16 AM6/10/08
to cherryp...@googlegroups.com
Thanks bro...will add these to my list of explorations to tweak the perfect development environment, which thus far includes cherrypy and  Mako...
--
Best regards,
arjuna
http://www.brahmaforces.com
Reply all
Reply to author
Forward
0 new messages