Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion django forms (media) + pyjamas
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeremy  
View profile  
 More options Mar 4 2009, 7:17 am
From: Jeremy <finde...@gmail.com>
Date: Wed, 4 Mar 2009 07:17:38 -0500
Local: Wed, Mar 4 2009 7:17 am
Subject: RE: django forms (media) + pyjamas
Sure, I'll do that tonight and will make it a bit more non-trivial with a ModelForm that allows you to save/edit the form with an instance or a new form.
The problem that this example solves is field validation based on an existing form. It can work with a modelform too...so you would just write processing logic then write f.save() to write it to the database. If it's invalid you return the errors and pyjamas processes them and displays them. What it doesn't solve is translating a form automatically into pyjamas, but it is very easy to wrap it so it only takes a few lines of code per form in pyjamas to dynamically display it...I'm a control freak though and like to build up each form so I can determine style and everything. But it's not hard to write a form handler in pyjamas to handle and display the errors. I'll include all of that tonight when I get home.
-----Original Message-----
From: lkcl <luke.leigh...@googlemail.com>
Sent: Wednesday, March 04, 2009 5:44 AM
To: pyjamas-dev <pyjamas-dev@googlegroups.com>
Subject: Re: django forms (media) + pyjamas

On Mar 4, 5:12 am, Jeremy <finde...@gmail.com> wrote:
> Here's a basic server side example of using django forms with an rpc
> service...the rpc service is taken from the wiki on Google Code and
> modified. Not that if you don't go through builderrors, you'll end up
> with proxy objects which won't work when pickling. The rpc url will
> point to processor. The Pyjamas RPC works like in the book, only it
> needs to check for 'success' is true or false in the results and can
> then loop through the results and assign error values to your html. In
> the past I have written a try/except wrapper around the __call__
> method_map function and processed the errors in the service if a
> certain exception was raised with a form object, but I don't know
> where that example was.

 oo that would be handy to have.

> #BSD licensed

> from django.http import HttpResponse
> from django.utils import simplejson
> from django import forms

> class JSONRPCService(object):
>     #taken fromhttp://code.google.com/p/pyjamas/wiki/DjangoWithPyjamas, BSD licensed
> and modified

<snip>

> class SimpleForm(forms.Form):
>     testfield = forms.CharField(max_length=100)

> def builderrors(form):
>     d = {}
>     for error in form.errors.keys():
>         if error not in d:
>             d[error] = []
>         for errorval in form.errors[error]:
>             d[error].append(unicode(errorval))

> class FormProcessor(JSONRPCService):
>     def __init__(self):
>         self.method_map = {
>             'process':self.process
>         }
>         super(FormProcess,self).__init__()
>     def process(self,request,params):
>         f = SimpleForm(request.POST)
>         if f.is_valid():
>             #do stuff
>             return {'success':True}
>         else:
>             return {'success'False,'errors':builderrors(f)}

> processor = FormProcessor()

 err.... err....

 intuitively i think this is utterly utterly cool - but i don't
understand it :)

 would you mind doing a couple of things:

 1) putting together a really simple example which uses this

 2) throwing it at either the wiki, the bugtracker or the pyjamas-dev
"Files"

 3) sending a 2-3 sentence para answering the questions "what does
this FormProcessor provide? what problem does it solve?"

 i.e. is it a way for alain to "hook into" any existing django "Forms"
code that he has written, such that he can "re-present" it via a
JSONRPC interface, using like... an additional 2 lines of code per
form?

because if so, that would be utterly cool.

l.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.