def find_all(self): res = self.__firebase.get('/' + self.__collection, None) jsoncontent = json.loads(str(res).replace("\'", "\"")) notes = [] for note_id, value in res.items(): n = Note("") n.from_json(jsoncontent[note_id]) notes.append(n) return notes
def find_all(self): response = requests.get(self.__url) jsoncontent = json.loads(response.content) notes = [] if response.json(): for note_id in response.json(): n = Note("") n.from_json(jsoncontent[note_id]) notes.append(n) return notes
def show_notes(noteId=None): if noteId: notes = (list(db.notes.find({'noteId': noteId}))) print notes if notes: note = Note.from_json(notes[0]) # convert to python object note_title = note.title content = note.content noteId = note.noteId return render_template('show_note.html', title=note_title, content=content, noteId=noteId)
def update_note(): data = request.get_json(force=True, silent=True) print "POST data received" print data title = data.get("title") content = data.get("content") noteId = int(data.get("noteId")) the_note = db.notes.find_one({'noteId': noteId}) if the_note: print type(the_note) my_note = Note.from_json(the_note) my_note.title = title my_note.content = content else: my_note = Note(title, content, noteId=noteId) print the_note db.notes.find_and_modify(query={'noteId': noteId}, update=my_note.to_json(), upsert=True) return json.dumps({"success": True})