from apps.course.models import Participant def user_has_course_access(user, course): if not user or not getattr(user, 'is_authenticated', False): return False if user.is_staff or user.is_superuser: return True if course.professor_id == user.id: return True return Participant.objects.filter( student_id=user.id, course=course, is_active=True, ).exists()