Example #1
0
def room_list(request, offset):
    # TODO: need optimizaiton
    building_id = int(offset)
    date = request.GET.get('date', datetime_date.today())

    try:
        building = Building.objects.get(pk=building_id)
    except Building.DoesNotExist:
        return {'error_code': 'BuildingNotFound'}, 404

    room_objs = building.room_set.all()
    response = []
    for room in room_objs:
        try:
            availability = listify_int(room.roomavailability_set.get(date=date).availability)
        except RoomAvailability.DoesNotExist:
            availability = []

        item = {
            'id': room.id,
            'name': room.name,
            'availability': availability,
        }
        response.append(item)
    return response
def detail(request, offset):
    university_id = int(offset)
    try:
        university = University.objects.get(pk=university_id)
    except University.DoesNotExist:
        return {'error_code': 'UniversityNotFound'}, 404

    schedule_unit = university.scheduleunit_set.all()

    response = {
        'name': university.name,
        'support': {
            'import_course': university.support_import_course,
            'list_course': university.support_list_course,
            'ta': university.support_ta,
        },
        'lessons': {
            'detail': [{
                'number': item.number,
                'start': time.strftime(item.start, "%H:%M"),
                'end': time.strftime(item.end, "%H:%M"),
            } for item in schedule_unit],
            'separators':
            listify_int(university.lessons_separator)
        }
    }
    return response
Example #3
0
def room_list(request, offset):
    # TODO: need optimizaiton
    building_id = int(offset)
    date = request.GET.get('date', datetime_date.today())

    try:
        building = Building.objects.get(pk=building_id)
    except Building.DoesNotExist:
        return {'error_code': 'BuildingNotFound'}, 404

    room_objs = building.room_set.all()
    response = []
    for room in room_objs:
        try:
            availability = listify_int(
                room.roomavailability_set.get(date=date).availability)
        except RoomAvailability.DoesNotExist:
            availability = []

        item = {
            'id': room.id,
            'name': room.name,
            'availability': availability,
        }
        response.append(item)
    return response
def detail(request, offset):
    university_id = int(offset)
    try:
        university = University.objects.get(pk=university_id)
    except University.DoesNotExist:
        return {'error_code': 'UniversityNotFound'}, 404

    schedule_unit = university.scheduleunit_set.all()

    response = {
        'name': university.name,
        'support': {
            'import_course': university.support_import_course,
            'list_course': university.support_list_course,
            'ta': university.support_ta,
        },
        'lessons': {
            'detail': [{
                'number': item.number,
                'start': time.strftime(item.start, "%H:%M"),
                'end': time.strftime(item.end, "%H:%M"),
            } for item in schedule_unit],
            'separators': listify_int(university.lessons_separator)
        }
    }
    return response
Example #5
0
def gen_ical(request):
    cal = Calendar()
    cal['version'] = '2.0'
    cal['prodid'] = '-//Prototype//Nanbeige//ZH'  # *mandatory elements* where the prodid can be changed, see RFC 5445

    user_profile = request.user.get_profile()

    # get current semester
    semesters = user_profile.campus.university.semester_set.all()
    today = date.today()
    for s in semesters:
        if today > s.week_start and today < s.week_end:
            semester = s
            break
    course_statuses = user_profile.coursestatus_set.filter(
        course__semester=semester).exclude(status=CourseStatus.CANCEL)
    university = user_profile.campus.university
    for course_status in course_statuses:
        for lesson in course_status.course.lesson_set.all():
            if lesson.weekset == None:
                weekgroup = listify_int(lesson.weeks)
            else:
                weekgroup = listify_int(lesson.weekset.weeks)
            for recur in weekgroup:
                event = Event()
                event.add('summary', unify_brackets(course_status.course.name))
                offset = timedelta(days=lesson.day - 1 + 7 * (int(recur) - 1))
                classdate = semester.week_start + offset
                start = university.scheduleunit_set.get(
                    number=lesson.start).start
                end = university.scheduleunit_set.get(number=lesson.end).end
                event.add('dtstart', datetime.combine(classdate, start))
                event.add('dtend', datetime.combine(classdate, end))
                event.add('location', lesson.location)
                event.add('description', u'教师:' + course_status.course.teacher)
                event['uid'] = str(
                    uuid1()) + '@Nanbeige'  # change after formal name...?
                cal.add_component(event)
    return HttpResponse(cal.to_ical(), mimetype="text/calendar")
def weekset(request, offset):
    semester_id = int(offset)
    try:
        semester = Semester.objects.get(pk=semester_id)
    except Semester.DoesNotExist:
        return {'error_code': "SemesterNotFound"}, 404

    weeksets = semester.weekset_set.all()

    response = [{
        'id': weekset.pk,
        'name': weekset.name,
        'weeks': listify_int(weekset.weeks),
    } for weekset in weeksets]
    return response
Example #7
0
def gen_ical(request):
    cal = Calendar()
    cal['version'] = '2.0'
    cal['prodid'] = '-//Prototype//Nanbeige//ZH' # *mandatory elements* where the prodid can be changed, see RFC 5445

    user_profile = request.user.get_profile()

    # get current semester
    semesters = user_profile.campus.university.semester_set.all()
    today = date.today()
    for s in semesters:
        if today > s.week_start and today < s.week_end:
            semester = s
            break
    course_statuses = user_profile.coursestatus_set.filter(course__semester=semester).exclude(status=CourseStatus.CANCEL)
    university = user_profile.campus.university
    for course_status in course_statuses:
        for lesson in course_status.course.lesson_set.all():
            if lesson.weekset == None:
                weekgroup = listify_int(lesson.weeks)
            else:
                weekgroup = listify_int(lesson.weekset.weeks)
            for recur in weekgroup:
                event = Event()
                event.add('summary', unify_brackets(course_status.course.name))
                offset = timedelta(days = lesson.day - 1 + 7 * (int(recur) - 1))
                classdate = semester.week_start + offset
                start = university.scheduleunit_set.get(number=lesson.start).start
                end = university.scheduleunit_set.get(number=lesson.end).end
                event.add('dtstart', datetime.combine(classdate, start))
                event.add('dtend', datetime.combine(classdate, end))
                event.add('location', lesson.location)
                event.add('description', u'教师:' + course_status.course.teacher)
                event['uid'] = str(uuid1()) + '@Nanbeige' # change after formal name...?
                cal.add_component(event)
    return HttpResponse(cal.to_ical(), mimetype="text/calendar")
def weekset(request, offset):
    semester_id = int(offset)
    try:
        semester = Semester.objects.get(pk=semester_id)
    except Semester.DoesNotExist:
        return {'error_code': "SemesterNotFound"}, 404

    weeksets = semester.weekset_set.all()

    response = [{
        'id': weekset.pk,
        'name': weekset.name,
        'weeks': listify_int(weekset.weeks),
    } for weekset in weeksets]
    return response