示例#1
0
def course(request, offset):
    course_id = int(offset)

    try:
        course = Course.objects.get(pk=course_id)
    except Course.DoesNotExist:
        return {'error_code': 'CourseNotFound'}, 404

    response = {
        'id': course_id,
        'orig_id': course.original_id,
        'name': unify_brackets(course.name),
        'credit': float_nullable(course.credit),
        'teacher': listify_str(course.teacher),
        'ta': listify_str(course.ta),
        'semester_id': course.semester_id,
        'lessons': [{
            'day': lesson.day,
            'start': lesson.start,
            'end': lesson.end,
            'location': lesson.location,
            'weekset_id': lesson.weekset_id,
            'weeks': lesson.weeks,
            'weeks_display': lesson.weeks_display,
        } for lesson in course.lesson_set.all()]
    }

    return response
示例#2
0
def course_list(request):
    after = request.GET.get('after', None)
    user_profile = request.user.get_profile()

    course_statuses = (user_profile.coursestatus_set.all().
      select_related('course').prefetch_related('course__lesson_set'))

    if after:
        try:
            course_statuses = course_statuses.filter(time__gte=after)
        except ValidationError:
            return {'error_code': 'SyntaxError'}, 400

    response = [{
        'id': course_status.course_id,
        'status': CourseStatus.STATUS_CHOICES_DICT[course_status.status],
        'orig_id': course_status.course.original_id,
        'name': unify_brackets(course_status.course.name),
        'credit': float_nullable(course_status.course.credit),
        'teacher': listify_str(course_status.course.teacher),
        'ta': listify_str(course_status.course.ta),
        'semester_id': course_status.course.semester_id,
        'lessons': [{
            'day': lesson.day,
            'start': lesson.start,
            'end': lesson.end,
            'location': lesson.location,
            'weekset_id': lesson.weekset_id,
            'weeks': lesson.weeks,
            'weeks_display': lesson.weeks_display,
        } for lesson in course_status.course.lesson_set.all()]
    } for course_status in course_statuses]

    return response
示例#3
0
def course(request, offset):
    course_id = int(offset)

    try:
        course = Course.objects.get(pk=course_id)
    except Course.DoesNotExist:
        return {'error_code': 'CourseNotFound'}, 404

    response = {
        'id':
        course_id,
        'orig_id':
        course.original_id,
        'name':
        unify_brackets(course.name),
        'credit':
        float_nullable(course.credit),
        'teacher':
        listify_str(course.teacher),
        'ta':
        listify_str(course.ta),
        'semester_id':
        course.semester_id,
        'lessons': [{
            'day': lesson.day,
            'start': lesson.start,
            'end': lesson.end,
            'location': lesson.location,
            'weekset_id': lesson.weekset_id,
            'weeks': lesson.weeks,
            'weeks_display': lesson.weeks_display,
        } for lesson in course.lesson_set.all()]
    }

    return response
示例#4
0
def all(request):
    semester_id = request.GET.get('semester_id', None)

    if not semester_id:
        return {'error_code': 'SyntaxError'}, 400
    try:
        semester = Semester.objects.get(pk=semester_id)
    except Semester.DoesNotExist:
        return {'error_code': 'SemesterNotFound'}, 404

    cache_name = 'semester_{0}_courses'.format(semester.pk)
    response = cache.get(cache_name)
    if not response:
        response = [{
            'id':
            course.id,
            'orig_id':
            course.original_id,
            'name':
            unify_brackets(course.name),
            'credit':
            float_nullable(course.credit),
            'teacher':
            listify_str(course.teacher),
            'ta':
            listify_str(course.ta),
            'semester_id':
            course.semester_id,
            'lessons': [{
                'day': lesson.day,
                'start': lesson.start,
                'end': lesson.end,
                'location': lesson.location,
                'weekset_id': lesson.weekset_id,
                'weeks': lesson.weeks,
                'weeks_display': lesson.weeks_display,
            } for lesson in course.lesson_set.all()],
        } for course in semester.course_set.all().prefetch_related(
            'lesson_set')]
        # timeout: 6 months
        cache.set(cache_name, bz2.compress(cPickle.dumps(response), 9),
                  15552000)
    else:
        response = cPickle.loads(bz2.decompress(response))
    return response
示例#5
0
def course_list(request):
    after = request.GET.get('after', None)
    user_profile = request.user.get_profile()

    course_statuses = (user_profile.coursestatus_set.all().select_related(
        'course').prefetch_related('course__lesson_set'))

    if after:
        try:
            course_statuses = course_statuses.filter(time__gte=after)
        except ValidationError:
            return {'error_code': 'SyntaxError'}, 400

    response = [{
        'id':
        course_status.course_id,
        'status':
        CourseStatus.STATUS_CHOICES_DICT[course_status.status],
        'orig_id':
        course_status.course.original_id,
        'name':
        unify_brackets(course_status.course.name),
        'credit':
        float_nullable(course_status.course.credit),
        'teacher':
        listify_str(course_status.course.teacher),
        'ta':
        listify_str(course_status.course.ta),
        'semester_id':
        course_status.course.semester_id,
        'lessons': [{
            'day': lesson.day,
            'start': lesson.start,
            'end': lesson.end,
            'location': lesson.location,
            'weekset_id': lesson.weekset_id,
            'weeks': lesson.weeks,
            'weeks_display': lesson.weeks_display,
        } for lesson in course_status.course.lesson_set.all()]
    } for course_status in course_statuses]

    return response
示例#6
0
def all(request):
    semester_id = request.GET.get('semester_id', None)

    if not semester_id:
        return {'error_code': 'SyntaxError'}, 400
    try:
        semester = Semester.objects.get(pk=semester_id)
    except Semester.DoesNotExist:
        return {'error_code': 'SemesterNotFound'}, 404

    cache_name = 'semester_{0}_courses'.format(semester.pk)
    response = cache.get(cache_name)
    if not response:
        response = [{
            'id': course.id,
            'orig_id': course.original_id,
            'name': unify_brackets(course.name),
            'credit': float_nullable(course.credit),
            'teacher': listify_str(course.teacher),
            'ta': listify_str(course.ta),
            'semester_id': course.semester_id,
            'lessons': [{
                'day': lesson.day,
                'start': lesson.start,
                'end': lesson.end,
                'location': lesson.location,
                'weekset_id': lesson.weekset_id,
                'weeks': lesson.weeks,
                'weeks_display': lesson.weeks_display,
            } for lesson in course.lesson_set.all()],
        } for course in semester.course_set.all().prefetch_related('lesson_set')]
        # timeout: 6 months
        cache.set(cache_name, bz2.compress(cPickle.dumps(response), 9), 15552000)
    else:
        response = cPickle.loads(bz2.decompress(response))
    return response