Ejemplo n.º 1
0
 def post(self):
     payload = json.loads(self.request.body)
     # Create the new note
     if self.payload_valid(payload):
         note = Note(parent=self.profile, body=cgi.escape(payload["body"]))
         note.put()
         self.response.set_status(201)
         return self.render_json(note.as_dict())
     else:
         self.response.set_status(500)
         return self.render_json({"errors": ["You must provide a body to create a new note!"]})
Ejemplo n.º 2
0
    def delete(self, note_id):
        note_id = int(note_id)

        m = Note.get_by_id(note_id, self.profile)

        if m:
            m.delete()
            self.response.set_status(204)
        else:
            self.response.set_status(204)  # ???
Ejemplo n.º 3
0
    def put(self, note_id):
        payload = json.loads(self.request.body)

        note_id = int(note_id)
        note = Note.get_by_id(note_id, self.profile)

        # Try catch required for missing notes
        if note:
            if self.payload_valid(payload):
                body_newline_replaced = payload["body"].replace("<br>", "\n")
                note.body = cgi.escape(body_newline_replaced)
                note.tags = payload.get("tags", [])  # default to an empty list
                note.put()
                # no content implies successful update
                self.response.set_status(204)
            else:
                return self.render_json({"errors": ["You must provide a body!"]})
        else:
            self.response.set_status(404)