def _get_user_statuses(user, course_key, checkpoint): """ Retrieve all the information we need to determine the user's group. This will retrieve the information as a multi-get from the cache. Args: user (User): User object course_key (CourseKey): Identifier for the course. checkpoint (unicode): Location of the checkpoint in the course (serialized usage key) Returns: tuple of booleans of the form (is_verified, has_skipped, has_completed) """ enrollment_cache_key = CourseEnrollment.cache_key_name(user.id, unicode(course_key)) has_skipped_cache_key = SkippedReverification.cache_key_name(user.id, unicode(course_key)) verification_status_cache_key = VerificationStatus.cache_key_name(user.id, unicode(course_key)) # Try a multi-get from the cache cache_values = cache.get_many([ enrollment_cache_key, has_skipped_cache_key, verification_status_cache_key ]) # Retrieve whether the user is enrolled in a verified mode. is_verified = cache_values.get(enrollment_cache_key) if is_verified is None: is_verified = CourseEnrollment.is_enrolled_as_verified(user, course_key) cache.set(enrollment_cache_key, is_verified) # Retrieve whether the user has skipped any checkpoints in this course has_skipped = cache_values.get(has_skipped_cache_key) if has_skipped is None: has_skipped = SkippedReverification.check_user_skipped_reverification_exists(user, course_key) cache.set(has_skipped_cache_key, has_skipped) # Retrieve the user's verification status for each checkpoint in the course. verification_statuses = cache_values.get(verification_status_cache_key) if verification_statuses is None: verification_statuses = VerificationStatus.get_all_checkpoints(user.id, course_key) cache.set(verification_status_cache_key, verification_statuses) # Check whether the user has completed this checkpoint # "Completion" here means *any* submission, regardless of its status # since we want to show the user the content if they've submitted # photos. checkpoint = verification_statuses.get(checkpoint) has_completed_check = bool(checkpoint) return (is_verified, has_skipped, has_completed_check)