Esempio n. 1
0
 def delete(self, request):
     courses = request.DATA.get('courses', '')
     course_ids = courses.split(',')
     user = request.user
     try:
         for course_id in course_ids:
             if course_id:
                 Follow.unfollow(user, 'course_meta.models.Course', course_id)
     except:
         transaction.rollback()
         raise error.Error(error.COURSES_FOLLOW_FAILED, u"课程取消关注失败")
     else:
         transaction.commit()
     return Response(status=status.HTTP_204_NO_CONTENT)
Esempio n. 2
0
    def get(self, request):
        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='list')
        user = request.user
        _followed_course = Follow.targets(user, 'course_meta.models.Course')
        followed_course = _followed_course.filter(course_type=0)
        total = followed_course.count()
        courses = followed_course[param['offset']:param['offset'] + param['limit']]
        result = {
            "courses": CourseSerializer(thumbnail_size, courses, many=True).data,
            "total": total,
        }
        return Response(result)
Esempio n. 3
0
 def delete(self, request, course_id):
     user = request.user
     Follow.unfollow(user, 'course_meta.models.Course', course_id)
     return Response(status=status.HTTP_204_NO_CONTENT)