Commit 06dc217a authored by Matheus Miranda's avatar Matheus Miranda

Add done units info to course serializer

parent 1818a56e
......@@ -39,6 +39,7 @@ class CourseSerializer(serializers.ModelSerializer):
track = serializers.SerializerMethodField()
is_user_enrolled = serializers.SerializerMethodField()
enroll_course_url = serializers.SerializerMethodField()
user_done_units = serializers.SerializerMethodField()
class Meta:
model = Course
......@@ -48,7 +49,7 @@ class CourseSerializer(serializers.ModelSerializer):
'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')
'is_user_enrolled', 'enroll_course_url', 'user_done_units')
@staticmethod
def get_home_thumbnail_url(obj):
......@@ -71,9 +72,16 @@ class CourseSerializer(serializers.ModelSerializer):
if request and hasattr(request, "user"):
user = request.user
if user:
return CourseStudent.objects.filter(course=obj, user=user).exists()
return False
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
......
......@@ -81,9 +81,6 @@ router.register(r'event', EventViewSet, base_name='event')
# Stats
router.register(r'user-activities', UserActivitiesViewSet, base_name='user-activities'),
# I18n
url(r'^api/i18n/', include('django.conf.urls.i18n')),
app_name = 'courses'
urlpatterns = [
# Stats (Activity Stream related functionality)
......
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