Пример #1
0
    def get(self, request, format=None):
        """ Get list of enrolled courses for user """
        enrollments = exclude_vpc_and_selfpaced_enrollments(request.user)
        courses = []
        for ce in enrollments:
            try:
                course = Course.objects.get(course_id=ce.course_id)
                courses.append(course)
            except:
                # Missing course
                continue

        response = {}
        response['enrollments'] = fill_in_courses(courses, request.user)
        response['status'] = 'success'
        return Response(response)
Пример #2
0
    def get(self, request, format=None):
        """ Get all the updates(notifications) of the enrolled courses. """
        param = {
            'timestamp': int(request.GET.get('timestamp', 0)),
        }

        enrollments = exclude_vpc_and_selfpaced_enrollments(request.user)
        courses = [Course.objects.get(course_id=e.course_id)
                   for e in enrollments]

        result = {
            "updates": [],
        }

        for course in courses:
            updates = get_course_updates(course.course_id, param['timestamp'])
            result["updates"] += UpdateSerializer(updates, many=True).data

        return Response(result)
Пример #3
0
    def get(self, request, format=None):
        """ Get all course notification """
        user = request.user
        timestamp = request.REQUEST.get('timestamp', 0)

        courses = exclude_vpc_and_selfpaced_enrollments(user)
        updates_data = {'notifications': []}

        for c in courses:
            course_update = {}
            course_update['course_id'] = str(c.course_id)

            updates = get_course_updates(c.course_id, int(timestamp))
            for u in updates:
                u['id'] = "%s/N%06d" % (str(c.course_id), u['id'])
                u['date'] = u['date'].strftime("%B %d, %Y")
            course_update['updates'] = updates
            updates_data['notifications'].append(course_update)

        return Response(updates_data)
Пример #4
0
    def get(self, request, format=None):
        """ Get the courses that user has enrolled, sort by enroll time. """
        param = {
            'offset': int(request.GET.get('offset', 0)),
            'limit': int(request.GET.get('limit', 10)),
        }

        screen = get_screen_size(request)
        thumbnail_size = get_thumbnail_size(screen, position='detail')
        enrollments = exclude_vpc_and_selfpaced_enrollments(request.user)
        total = len(enrollments)
        courses = []
        for e in enrollments[param['offset']:param['offset'] + param['limit']]:
            try:
                courses.append(Course.objects.get(course_id=e.course_id))
            except:
                pass
        result = {
            "courses": CourseSerializer(thumbnail_size, courses, many=True).data,
            "total": total,
        }
        return Response(result)