def edit_note(note_id): user_obj = model.User.objects(username=login.username())[0] if not ObjectId.is_valid(note_id): abort(400) if not model.Note.objects(pk=note_id, author=user_obj): abort(404) try: body = request.json['body'] subject = request.json['subject'] except: abort(400) if body != '': model.Note.objects(pk=note_id, author=user_obj)[0].update(set__body=body) if subject != '': model.Note.objects(pk=note_id, author=user_obj)[0].update(set__subject=subject) model.Note.objects(pk=note_id, author=user_obj)[0].update(set__modification_time=datetime.now()) return jsonify({ 'success': True, 'message': 'Note was edited', 'data': None })
def get_all_notes(): user_obj = model.User.objects(username=login.username())[0] if model.Note.objects(author=user_obj).count == 0: return jsonify({ 'success': True, 'message': 'List of notes.', 'data': [] }) notes = [note.to_mongo() for note in model.Note.objects(author=user_obj)] for note in notes: note['note_id'] = str(note['_id']) del note['_id'] note['creation_time'] = int(note['creation_time'].strftime("%s")) * 1000 note['modification_time'] = int(note['modification_time'].strftime("%s")) * 1000 del note['body'] del note['author'] return jsonify({ 'success': True, 'message': 'List of notes.', 'data': notes })
def make_note(): user_obj = model.User.objects(username=login.username())[0] try: body = request.json['body'] subject = request.json['subject'] except: abort(400) if len(subject) > 100: abort(413) if len(body) > 3000: abort(413) if len(subject) == 0: subject = 'New note' model.Note(author = user_obj, body=body, subject=subject, creation_time=datetime.now(), modification_time = datetime.now()).save() return jsonify({ 'success': True, 'message': 'Note was added.', 'data': None })
def edit_note(note_id): user_obj = model.User.objects(username=login.username())[0] if not ObjectId.is_valid(note_id): abort(400) if not model.Note.objects(pk=note_id, author=user_obj): abort(404) try: body = request.json['body'] subject = request.json['subject'] except: abort(400) if body != '': model.Note.objects(pk=note_id, author=user_obj)[0].update(set__body=body) if subject != '': model.Note.objects(pk=note_id, author=user_obj)[0].update(set__subject=subject) model.Note.objects( pk=note_id, author=user_obj)[0].update(set__modification_time=datetime.now()) return jsonify({ 'success': True, 'message': 'Note was edited', 'data': None })
def make_note(): user_obj = model.User.objects(username=login.username())[0] try: body = request.json['body'] subject = request.json['subject'] except: abort(400) if len(subject) > 100: abort(413) if len(body) > 3000: abort(413) if len(subject) == 0: subject = 'New note' model.Note(author=user_obj, body=body, subject=subject, creation_time=datetime.now(), modification_time=datetime.now()).save() return jsonify({ 'success': True, 'message': 'Note was added.', 'data': None })
def get_all_notes(): user_obj = model.User.objects(username=login.username())[0] if model.Note.objects(author=user_obj).count == 0: return jsonify({ 'success': True, 'message': 'List of notes.', 'data': [] }) notes = [note.to_mongo() for note in model.Note.objects(author=user_obj)] for note in notes: note['note_id'] = str(note['_id']) del note['_id'] note['creation_time'] = int( note['creation_time'].strftime("%s")) * 1000 note['modification_time'] = int( note['modification_time'].strftime("%s")) * 1000 del note['body'] del note['author'] return jsonify({ 'success': True, 'message': 'List of notes.', 'data': notes })
def delete_note(note_id): user_obj = model.User.objects(username=login.username())[0] if not ObjectId.is_valid(note_id): abort(400) if not model.Note.objects(pk=note_id, author=user_obj): abort(404) model.Note.objects(pk=note_id, author=user_obj)[0].delete() return jsonify({ 'success': True, 'message': 'Note was deleted', 'data': None })
def get_note(note_id): user_obj = model.User.objects(username=login.username())[0] if not ObjectId.is_valid(note_id): abort(404) if not model.Note.objects(pk=note_id, author=user_obj): abort(404) note = model.Note.objects(pk=note_id, author=user_obj)[0].to_mongo() note['note_id'] = str(note['_id']) del note['_id'] note['creation_time'] = int(note['creation_time'].strftime("%s")) * 1000 note['modification_time'] = int( note['modification_time'].strftime("%s")) * 1000 del note['author'] return jsonify({'success': True, 'message': 'One note.', 'data': note})
def get_note(note_id): user_obj = model.User.objects(username=login.username())[0] if not ObjectId.is_valid(note_id): abort(404) if not model.Note.objects(pk=note_id, author=user_obj): abort(404) note = model.Note.objects(pk=note_id, author=user_obj)[0].to_mongo() note['note_id'] = str(note['_id']) del note['_id'] note['creation_time'] = int(note['creation_time'].strftime("%s")) * 1000 note['modification_time'] = int(note['modification_time'].strftime("%s")) * 1000 del note['author'] return jsonify({ 'success': True, 'message': 'One note.', 'data': note })