def exam_calendar(request): if request.method == 'GET': query = ScheduleEntry.objects.filter(identifier=request.GET['identifier']) events = [] for entry in query: course = schedule_get_course(entry) exam = exam_for_course(course) if exam: start = datetime.datetime.combine(exam.exam_date, exam.exam_start_time).isoformat() end = datetime.datetime.combine(exam.exam_date, exam.exam_end_time).isoformat() events.append({ 'id': str(course.crn), 'title': course.course, 'start': start, 'end': end, 'url': 'https://opencourseproject.com/course/' + str(course.term.value) + '/' + str(course.crn) + '/', }) exams = SafeString(json.dumps(events)) return HttpResponse(exams, 201) else: return HttpResponse('Method not allowed', 405)
def exam_schedule(request, termid): term = Term.objects.get(value=termid) query = ScheduleEntry.objects.filter(user=request.user, term=term) courses = schedule_get_courses(query) exams = [] first_exam = None for course in courses: if course is None: courses.remove(course) else: exam = exam_for_course(course) if exam: start = exam.exam_start_time end = exam.exam_end_time exams.append({ 'course': course.course, 'crn': course.crn, 'title': course.title, 'date': exam.exam_date, 'start_time': start, 'end_time': end }) if not first_exam or exam.exam_date < first_exam: first_exam = exam.exam_date hash = hashlib.md5(b'%s:%s' % (str(request.user.username), str(term.name))).hexdigest()[:15] table = ExamTable(exams) RequestConfig(request).configure(table) context = { 'source': ExamSource.objects.get(term=term), 'term': term, 'table': table, 'first_exam': first_exam.strftime('%Y-%m-%d'), 'identifier': hash, 'authenticated': True, } return render(request, 'schedule/exam_schedule.html', context)
def course(request, term, crn): try: term = Term.objects.get(value=term) course = Course.objects.get(term=term, crn=crn) except Course.DoesNotExist: raise Http404("Course does not exist") materials = Material.objects.filter(term=term, course_crn=course.crn) user = request.user authenticated = user.is_authenticated() context = { 'course': course, 'term': term, 'authenticated': authenticated, 'user': user, 'materials': materials, 'suggestion_form': InstructorSuggestionForm(), } version_list = CourseVersion.objects.find(course) if len(version_list) > 1: versions = OrderedDict() for i in range(0, len(version_list)-1): new_version = version_list[i] old_version = version_list[i+1] changelog = create_changelog(old_version, new_version) if changelog: versions[new_version] = changelog context['changes'] = versions if request.method == 'POST': if authenticated: form = InstructorSuggestionForm(request.POST) if form.is_valid(): email_address = form.cleaned_data['email_address'] rmp_link = form.cleaned_data['rmp_link'] if email_address or rmp_link: suggestion = InstructorSuggestion(instructor=course.instructor, user=user, email_address=email_address, rmp_link=rmp_link) suggestion.save() # Send mail subject = "Instructor suggestion created" message = "{} created a new suggestion for {}: {}, {}".format(request.user.username, course.instructor, email_address, rmp_link) mail_admins(subject, message) context['suggestion_message'] = "Thanks! Your suggestion has been submitted and is awaiting approval." else: return HttpResponse('Unauthorized', 401) primary = course.primary_meeting_time secondary = course.secondary_meeting_times if primary: context['primary_meeting_time'] = primary if secondary: context['secondary_meeting_times'] = secondary exam = exam_for_course(course) exam_sources = ExamSource.objects.filter(term=term) if exam: context['exam'] = exam if len(exam_sources) == 1: context['exam_source'] = exam_sources[0] return render(request, 'course/course.html', context)