Example #1
0
def get_document(document_id):
    if get_connection() is None:
        try_reconnecting()
    if request.method == 'GET':
        try:
            result = load_document(document_id, current_user.get_id())
            return respond_with(result)
        except Exception, e:
            print e
            reset_connection()
            return 'Error while loading the document.', 500
Example #2
0
def login():
    if get_connection() is None:
        try_reconnecting()
    req = request.get_json()
    if req and 'username' in req and 'password' in req:
        try:
            user = load_user(req['username'])
            if user and req['password'] == user.token:
                login_user(user, remember=True)
                user.token = None
                return respond_with(user.__dict__)
        except Exception, e:
            reset_connection()
            return str(e) + " Please try again later.", 500
Example #3
0
         result = load_document(document_id, current_user.get_id())
         return respond_with(result)
     except Exception, e:
         print e
         reset_connection()
         return 'Error while loading the document.', 500
 if request.method == 'POST':
     successful = False
     try:
         user_doc_id = load_user_doc_id(document_id, current_user.get_id())
         successful = save_document(request.get_json(), user_doc_id,
                                    document_id, current_user.get_id(),
                                    request.get_json()['task_id'])
     except Exception, e:
         print e
         reset_connection()
     if successful:
         return ""
     else:
         return "An error occurred while saving the document.", 500
 if request.method == 'DELETE':
     successful = False
     try:
         successful = delete_document(document_id)
     except Exception, e:
         print e
         reset_connection()
     if not successful:
         return 'Deletion unsuccessful.', 500
     else:
         return 'Deleted.', 200