Exemplo n.º 1
0
 def get(self, request, course_id, format=None):
     """ Get enrollment number of the current course. """
     result = {
         "enrollments": course_stat.enrollment_total_count(
             SlashSeparatedCourseKey.from_deprecated_string(course_id)),
     }
     return Response(result)
Exemplo n.º 2
0
    def get(self, request, course_id, format=None):
        """ Get some frequency update data of the current course. """
        try:
            course = Course.objects.get(course_id=course_id)
        except:
            return Response(status=status.HTTP_404_NOT_FOUND)

        course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)

        result = {
            "enrollments": course_stat.enrollment_total_count(course_key),
            "comments": course_stat.comment_total_count(course_key),
            "serialized": course.serialized,
        }
        return Response(result)
Exemplo n.º 3
0
 def get_enrollments(self, obj):
     return course_stat.enrollment_total_count(
         SlashSeparatedCourseKey.from_deprecated_string(obj.course_id))
Exemplo n.º 4
0
def fill_in_course(course, user=None):
    detail = {}
    detail['course_id'] = course.course_id
    detail['display_name'] = course.name
    detail['display_org'] = course.org
    detail['display_coursenum'] = course.course_num
    # detail['subtitle'] = course.subtitle
    # detail['video'] = course.intro_video
    # detail['thumbnail'] = course.thumbnail
    if course.start:
        detail['start'] = course.start.strftime("%Y-%m-%d %H:%M:%S")
        detail['naturalStart'] = naturalFormatDate(course.start)
    else:
        detail['start'] = ""
        detail['naturalStart'] = ""

    if course.end:
        detail['finish'] = course.end.strftime("%Y-%m-%d %H:%M:%S")
    else:
        detail['finish'] = ""

    if course.enrollment_start:
        detail['advertised_start'] = course.enrollment_start.strftime(
            "%Y-%m-%d %H:%M:%S")
    else:
        detail['advertised_start'] = ""

    if course.enrollment_end:
        detail['advertised_finish'] = course.enrollment_end.strftime(
            "%Y-%m-%d %H:%M:%S")
    else:
        detail['advertised_finish'] = ""

    if cmp(course.owner.lower(), 'edx') == 0:
        detail['course_status'] = '由edX联盟高校提供'
        # If this course is edx, give a later enrollment start time
        detail['advertised_start'] = '2030-01-01 00:00:00'
    elif course.serialized < 0:
        detail['course_status'] = '即将开课'
    elif course.serialized == 0:
        detail['course_status'] = '已上线'
    else:
        detail['course_status'] = '更新至第%d章' % course.serialized

    detail['student_num'] = course_stat.enrollment_total_count(
        SlashSeparatedCourseKey.from_deprecated_string(course.course_id))
    detail['course_image_url'] = _transform_thumbnail(course.thumbnail)
    detail['share_content'] = ""

    # lookup Course_staff table with course_id
    # problem: cannot get separate info of org, postion
    try:
        staff = Staff.objects.filter(course__course_id=course.course_id,
                                     coursestaffrelationship__role=0)[0]
        staff_dict = {}
        staff_dict['name'] = staff.name
        staff_dict['image_url'] = _normalizeImageUrl(staff.avartar)
        staff_dict['person_url'] = ""
    except:
        staff_dict = {}
        staff_dict['name'] = ""
        staff_dict['image_url'] = ""
        staff_dict['person_url'] = ""

    detail['master_teacher'] = staff_dict

    is_enrolled = user and not isinstance(user, AnonymousUser) and CourseEnrollment.is_enrolled(user, course.course_id)
    detail['enroll'] = is_enrolled

    return detail