import logging

from troposphere.query import only_current_tokens


logger = logging.getLogger(__name__)


def has_valid_token(user):
    """
    Returns boolean indicating if there are non-expired authentication
    tokens associated with the user.
    """
    logger.info(hasattr(user, "auth_tokens"))
    non_expired_tokens = user.auth_tokens.filter(only_current_tokens())
    return len(non_expired_tokens) > 0


def get_current_tokens(user):
    """
    Returns the non-expired authentication tokens.
    """
    logger.info(hasattr(user, "auth_tokens"))
    return user.auth_tokens.filter(only_current_tokens())

import logging

from troposphere.query import only_current_tokens


logger = logging.getLogger(__name__)


def has_valid_token(user):
    """
    Returns boolean indicating if there are non-expired authentication
    tokens associated with the user.
    """
    logger.info("user has auth_tokens attributes? %s" %
        (hasattr(user, "auth_tokens")))

    return user.auth_tokens.filter(only_current_tokens()).exists()


def get_current_tokens(user):
    """
    Returns the non-expired authentication tokens.
    """
    logger.info("user has auth_tokens attributes? %s" %
        (hasattr(user, "auth_tokens")))

    return user.auth_tokens.filter(only_current_tokens())

Use exists() check from QuerySet; give logger-info context
Use exists() check from QuerySet; give logger-info context

  import logging
  
  from troposphere.query import only_current_tokens
  
  
  logger = logging.getLogger(__name__)
  
  
  def has_valid_token(user):
      """
      Returns boolean indicating if there are non-expired authentication
      tokens associated with the user.
      """
+     logger.info("user has auth_tokens attributes? %s" %
-     logger.info(hasattr(user, "auth_tokens"))
+         (hasattr(user, "auth_tokens")))
+ 
-     non_expired_tokens = user.auth_tokens.filter(only_current_tokens())
+     return user.auth_tokens.filter(only_current_tokens()).exists()
-     return len(non_expired_tokens) > 0
  
  
  def get_current_tokens(user):
      """
      Returns the non-expired authentication tokens.
      """
+     logger.info("user has auth_tokens attributes? %s" %
-     logger.info(hasattr(user, "auth_tokens"))
+         (hasattr(user, "auth_tokens")))
+ 
      return user.auth_tokens.filter(only_current_tokens())
  
Use exists() check from QuerySet; give logger-info context
## Code Before:
import logging

from troposphere.query import only_current_tokens


logger = logging.getLogger(__name__)


def has_valid_token(user):
    """
    Returns boolean indicating if there are non-expired authentication
    tokens associated with the user.
    """
    logger.info(hasattr(user, "auth_tokens"))
    non_expired_tokens = user.auth_tokens.filter(only_current_tokens())
    return len(non_expired_tokens) > 0


def get_current_tokens(user):
    """
    Returns the non-expired authentication tokens.
    """
    logger.info(hasattr(user, "auth_tokens"))
    return user.auth_tokens.filter(only_current_tokens())

## Instruction:
Use exists() check from QuerySet; give logger-info context
## Code After:
import logging

from troposphere.query import only_current_tokens


logger = logging.getLogger(__name__)


def has_valid_token(user):
    """
    Returns boolean indicating if there are non-expired authentication
    tokens associated with the user.
    """
    logger.info("user has auth_tokens attributes? %s" %
        (hasattr(user, "auth_tokens")))

    return user.auth_tokens.filter(only_current_tokens()).exists()


def get_current_tokens(user):
    """
    Returns the non-expired authentication tokens.
    """
    logger.info("user has auth_tokens attributes? %s" %
        (hasattr(user, "auth_tokens")))

    return user.auth_tokens.filter(only_current_tokens())
