from flask_security import current_user def set_logging_information(obj, timestamp): obj.created_at = timestamp obj.updated_at = timestamp user_id = get_current_user_id() if user_id: obj.created_by = user_id obj.updated_by = user_id def update_logging_information(obj, timestamp): obj.updated_at = timestamp user_id = get_current_user_id() if user_id: obj.updated_by = user_id def get_current_user_id(): try: if current_user and current_user.is_authenticated: return current_user.id else: return None except Exception: # This will catch any errors if current_user is not available (e.g., in API context) return None