Commit b78278c9 authored by Matheus Miranda's avatar Matheus Miranda

Remove wrong field from serializers

parent 908f1e05
......@@ -37,9 +37,6 @@ class CourseSerializer(serializers.ModelSerializer):
is_user_coordinator = serializers.SerializerMethodField()
is_assistant_or_coordinator = serializers.SerializerMethodField()
track = serializers.SerializerMethodField()
is_user_enrolled = serializers.SerializerMethodField()
enroll_course_url = serializers.SerializerMethodField()
user_done_units = serializers.SerializerMethodField()
class Meta:
model = Course
......@@ -48,8 +45,7 @@ class CourseSerializer(serializers.ModelSerializer):
'thumbnail_url', 'home_thumbnail_url', 'home_position',
'start_date', 'home_published', 'authors_names', 'has_started',
'min_percent_to_complete', 'is_user_assistant', 'is_user_coordinator',
'is_assistant_or_coordinator', 'professors', 'track', 'forum_id',
'is_user_enrolled', 'enroll_course_url', 'user_done_units')
'is_assistant_or_coordinator', 'professors', 'track', 'forum_id')
@staticmethod
def get_home_thumbnail_url(obj):
......@@ -66,45 +62,6 @@ class CourseSerializer(serializers.ModelSerializer):
def get_is_assistant_or_coordinator(self, obj):
return obj.is_assistant_or_coordinator(self.context['request'].user)
def get_is_user_enrolled(self, obj):
user = None
request = self.context.get("request")
if request and hasattr(request, "user"):
user = request.user
return CourseStudent.objects.filter(course=obj, user=user).exists()
def get_user_done_units(self, obj):
user = None
request = self.context.get("request")
if request and hasattr(request, "user"):
user = request.user
if CourseStudent.objects.filter(course=obj, user=user).exists():
return CourseStudent.objects.filter(course=obj, user=user).first().units_done
def get_enroll_course_url(self, obj):
user = None
request = self.context.get("request")
if request and hasattr(request, "user"):
user = request.user
else:
return ''
course = obj
if course.is_enrolled(user):
return 'resume_course'
if course.status == 'draft':
return 'courses'
if user.accepted_terms or not settings.TERMS_ACCEPTANCE_REQUIRED:
course.enroll_student(user)
if course.has_started and course.first_lesson():
return 'lesson'
else:
return 'course_home'
else:
'accept_terms'
def get_track(self, obj):
course_track = CourseTrack.objects.filter(courses=obj)
if course_track:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment