Example #1
0
def append_log_impl(args):
    try:
        user = user_by_user_id(args['user_id'])
        logs = []
        if args['logs'] is None:
            return Response(True, "Logs Appended",
                            LogSchema(many=True).dumps(logs).data).output()
        for log_dict in args['logs']:
            validate(log_dict)
            log = None
            if log_dict.has_key('id') and log_dict['id'] is not None:
                log = log_by_id(log_dict['id'])
                if log is None:
                    log = ReadingLog()
            else:
                log = ReadingLog()
            log.book = find_book_with_name(log_dict['book_name']).id
            log.date = parse(log_dict['date'])
            log.pages = log_dict['pages']
            log.uuid = log_dict['uuid']
            log.user = user.user_id
            db.session.add(log)
            logs.append(log)
        db.session.commit()
        return Response(True, "Logs Appended",
                        LogSchema(many=True).dumps(logs).data).output()
    except Exception as e:
        return Response(False, str(e), None).output()
Example #2
0
def append_log_impl(args):
    try:
        user = user_by_user_id(args['user_id'])
        logs = []
        if args['logs'] is None:
            return Response(True, "Logs Appended", LogSchema(many=True).dumps(logs).data).output()
        for log_dict in args['logs']:
            validate(log_dict)
            log = None
            if log_dict.has_key('id') and log_dict['id'] is not None:
                log = log_by_id(log_dict['id'])
                if log is None:
                    log = ReadingLog()
            else:
                log = ReadingLog()
            log.book = find_book_with_name(log_dict['book_name']).id
            log.date = parse(log_dict['date'])
            log.pages = log_dict['pages']
            log.uuid = log_dict['uuid']
            log.user = user.user_id
            db.session.add(log)
            logs.append(log)
        db.session.commit()
        return Response(True, "Logs Appended", LogSchema(many=True).dumps(logs).data).output()
    except Exception as e:
        return Response(False, str(e), None).output()
Example #3
0
def delete_log_impl(args):
    try:
        user = user_by_user_id(args['user_id'])
        log = log_by_id(args['log_id'])
        db.session.delete(log)
        db.session.commit()
        return simple_response(True, "Log Deleted")
    except Exception as e:
        return Response(False, str(e), None).output()
Example #4
0
def delete_log_impl(args):
    try:
        user = user_by_user_id(args['user_id'])
        log = log_by_id(args['log_id'])
        db.session.delete(log)
        db.session.commit()
        return simple_response(True, "Log Deleted")
    except Exception as e:
        return Response(False, str(e), None).output()
Example #5
0
def update_log_impl(args):
    try:
        user = user_by_user_id(args['user_id'])
        log = log_by_id(args['log_id'])
        log.pages = args['pages'] if args['pages'] is not None else log.pages
        log.date = parse(args['date']) if args['date'] is not None else log.date
        db.session.commit()
        return Response(True, "Log Updated", LogSchema().dumps(log).data).output()
    except Exception as e:
        return Response(False, str(e), None).output()
Example #6
0
def update_log_impl(args):
    try:
        user = user_by_user_id(args['user_id'])
        log = log_by_id(args['log_id'])
        log.pages = args['pages'] if args['pages'] is not None else log.pages
        log.date = parse(
            args['date']) if args['date'] is not None else log.date
        db.session.commit()
        return Response(True, "Log Updated",
                        LogSchema().dumps(log).data).output()
    except Exception as e:
        return Response(False, str(e), None).output()