[snowy] Return a complete JSON response to PUT requests.



commit 24963b625ea68f119c62f590d75b9089fbb690a3
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Tue May 19 12:27:06 2009 -0700

    Return a complete JSON response to PUT requests.
    
    Do not bail out of NotesHandler.update early if there are no changes; always want to return proper response.
---
 api/handlers.py |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/api/handlers.py b/api/handlers.py
index 38c12c7..70f5fda 100644
--- a/api/handlers.py
+++ b/api/handlers.py
@@ -104,8 +104,6 @@ class NotesHandler(BaseHandler):
 
         update = json.loads(request.raw_post_data)
         changes = update['note-changes']
-        if len(changes) == 0:
-            return
 
         current_sync_rev = user.get_profile().latest_sync_rev
         new_sync_rev = current_sync_rev + 1
@@ -146,14 +144,15 @@ class NotesHandler(BaseHandler):
             note.save()
 
         profile = user.get_profile()
-        profile.latest_sync_rev = new_sync_rev
-        profile.save()
-
-        # TODO: Would like to be able to return this. Why does it break the update?
-        #       Is it related to how the transaction is handled?
-        #       Must we commit manually first?
-#        return {'latest-sync-revision': new_sync_rev,
-#                 'notes': [simple_describe_note(n) for n in notes]}
+        if len(changes) > 0:
+            profile.latest_sync_rev = new_sync_rev
+            profile.save()
+        
+        return {
+            'latest-sync-revision': profile.latest_sync_rev,
+            'notes': [simple_describe_note(n) for n in Note.objects.filter(author=user)]
+        }
+
 
 # http://domain/api/1.0/user/notes/id
 class NoteHandler(BaseHandler):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]