Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


handler.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    def update(self, request, validate=False, form=None, *args, **kwargs):

        try:
            object_id = getattr(getattr(self, self._object_name().lower()), 'id')
        except AttributeError:
            raise NoIdGiven

        model_attrs = self._set_put_attrs(request, 'model_attrs', **kwargs)
        form_attrs = self._set_put_attrs(request, 'form_attrs', **kwargs)

        inst = getattr(self, self._object_name().lower())
        form = form(form_attrs, instance=inst)

        if form.is_valid():
            for k,v in model_attrs.iteritems():
                setattr(inst, k, v)
            inst.save()
            if request.GET.get('return'):
                return inst
            return HttpMsg("%s with ID `%s` was updated." % (self._object_name(), object_id)).all_ok()
        return self._form_errors_to_json(form.errors.items())

tests.py

1
2
3
4
5
6
7
8
9
10
11
    def test_update_with_return(self):
        response = self.client.put('/api/1.0/task/2/update/?return=true', data={
            'name': 'Show me!'
        }, **self.auth2)
        self.assertEqual(response.content, 'here comes reaaaaaalllly long json ;)')

    def test_update_without_return(self):
        response = self.client.put('/api/1.0/task/1/update/', data={
            'name': 'Get child from school'
        }, **self.auth1)
        self.assertEqual(response.content, 'OK : Task with ID `1` was updated.')