On Jul 6, 2:44 pm, Jug <
j...@fantasymail.de> wrote:
> Hello,
>
> I have some general questions:
>
> 1) How can the client call custom methods in my handler class?
They can't. This is REST, not RPC. The only available methods you
have, are GET/POST/PUT and DELETE.
> 2) Can I use my read method for registered and anonymous or do I have
> to copy it to an AnonymousHandler?
Yes. Patches welcome.
> 3) How can I use the validate decorator (or a normal form) but allow
> clients to change only one field (i.e. sending (new) data for only one
> field)?
Hopefully I have a good answer for this one :-)
In piston.forms, there's a basic subclass of django.forms.ModelForm,
which has an additional method, namely 'merge_from_initial'. This
method will fill out the form based on the initial data it got, via
the initial keyword argument.
Untested code, but basically how you use it:
from piston.forms import ModelForm
class SomeForm(ModelForm):
...
@validate(SomeForm)
def update(self, request):
obj = get_object_or_404(...)
form = SomeForm(initial=obj)
form.merge_from_initial()
if form.is_valid(): # well, redundant really, since @validate
takes care of that
form.save()
That'll allow the client to only send one field, and the rest of the
values will be filled from the object.
HTH,
Jesper