from django.shortcuts import redirect, get_object_or_404
from django.contrib import messages

from .models import Course, Enrollment


def enrollment_required(view_func):
    def _wrapper(request, *args, **kwargs):
        slug = kwargs['slug']
        course = get_object_or_404(Course, slug=slug)
        has_permission = request.user.is_staff
        if not has_permission:
            try:
                enrollment = Enrollment.objects.get(
                    course=course, user=request.user
                )
            except Enrollment.DoesNotExist:
                message = 'Desculpe, mas você não tem permissão de acesso'
            else:
                if enrollment.is_approved():
                    has_permission = True
                else:
                    message = 'Sua inscrição do curso ainda está pendente'
        if not has_permission:
            messages.error(request, message)
            return redirect('accounts:dashboard')
        request.course = course
        return view_func(request, *args, **kwargs)
    return _wrapper

@@ -34,27 +34,8 @@
 rect
-, get_object_or_404
 %0Afro
@@ -71,47 +71,159 @@
 ges%0A
-%0Afrom .models import Course, Enrollment
+from django.contrib.contenttypes.models import ContentType%0A%0Afrom .models import Course, CourseTRB, Enrollment%0Afrom .utils import get_course_by_instance
 %0A%0A%0Ad
@@ -356,39 +356,115 @@
 get_
-object_or_404(Course, slug=slug
+course_by_instance(slug, Course, CourseTRB)%0A        content_type = ContentType.objects.get_for_model(course
 )%0A  
@@ -635,20 +635,93 @@
   co
-urse=course,
+ntent_type=content_type,%0A                    object_id=course.id,%0A                   
  use

Update decorator to work with content_type relation