def create_course(request): if request.method == 'POST': first_half = str(request.POST.get('first_half')) second_half = str(request.POST.get('second_half')) number=first_half+"."+second_half #number = request.POST.get('number') title = request.POST.get('title') section = request.POST.get('section') term = request.POST.get('term') y = request.POST.get('year') u = request.user try: Course.objects.get(course_number=number) return HttpResponseRedirect('/course/course_create_failure/') except Course.DoesNotExist: c = Course.objects.create(course_number=number, section_number=section, course_title=title, academic_period=term, year=y, status='2') r = Role.objects.create(user=u, course=c, role='F', status='2') request = enroll_approv(r) e_app = Enroll_Approv.objects.create(role = r, approval = request) admin = [] admin.append(User.objects.get(pk=1)) notification.send(admin, "pend_approv", {"first_name": u.first_name, "last_name": u.last_name, "course_name": c.course_title, "position": r.role, "email": u.email}) return HttpResponseRedirect('/course/course_create_success/') return render_to_response('course/create.html')
def enroll_TA(request): if request.method == 'POST': courses = request.POST.getlist('courses') u = request.user for c in courses: # Role.objects.create(user=User.objects.get(pk=14), course=c, role='S') cours = Course.objects.get(course_number=c) temp = Role.objects.filter(user=u, course=cours) if len(temp) == 0: r = Role.objects.create(user=u, course=cours, role='T', status='2') request = enroll_approv(r) e_app = Enroll_Approv.objects.create(role = r, approval = request) facs_for_course = [] roles = Role.objects.all() for role in roles: if role.getFaculty(cours) != None: facs_for_course.append(role.user) notification.send(facs_for_course, "pend_approv", {"first_name": u.first_name, "last_name": u.last_name, "course_name": cours.course_title, "position": r.role, "email": u.email}) return HttpResponseRedirect('/course/enroll_TA_success/') else: return HttpResponseRedirect('/course/enroll_TA_failure/') course_list = Course.objects.filter(status='5'); return render_to_response('course/enroll_TA.html', {'course_list': course_list})
def profile_page(request): course_list = [] teach_list = [] ta_list = [] u = request.user roles = Role.objects.all() for role in roles: if role.getCoursesForStu(u) != None: course_list.append(role.course) elif role.getCoursesForFac(u) != None: teach_list.append(role.course) elif role.getCoursesForTA(u) != None: ta_list.append(role.course) course_list = sorted(course_list, key=lambda course:course.year) teach_list= sorted(teach_list, key=lambda course:course.year) ta_list= sorted(ta_list, key=lambda course:course.year) if request.method == 'POST': try: drop_course_list = request.POST.getlist('stu_courses') for c in drop_course_list: c2 = Course.objects.get(course_number=c) role = Role.objects.get(user=u,course=c2,role='S') if role != None: role.delete() return HttpResponseRedirect('/profile/course_drop_success') else: return HttpResponseRedirect('/profile/course_drop_failure') #Send Notification to faculty that a student has dropped the course facs_for_course = [] roles = Role.objects.all() for role in roles: if role.getFaculty(c2) != None: facs_for_course.append(role.user) notification.send(facs_for_course, "stud_dropped", {"first_name": u.first_name, "last_name": u.last_name, "course_name": c2.course_title, "email": u.email}) except Role.DoesNotExist: return HttpResponseRedirect('/profile/course_drop_failure') drop_course_list = request.POST.getlist('ta_courses') try: for c in drop_course_list: c2 = Course.objects.get(course_number=c) role = Role.objects.get(user=u,course=c2,role='T') if role != None: role.delete() return HttpResponseRedirect('/profile/course_TA_success') else: return HttpResponseRedirect('/profile/course_TA_failure') except Role.DoesNotExist: return HttpResponseRedirect('/profile/course_TA_failure') drop_course_list = request.POST.getlist('teach_courses') try: for c in drop_course_list: c3 = Course.objects.get(course_number=c) if c3 != None: assignments = Assignment.objects.all() for a in assignments: if a.course == c3: a.delete() else: return HttpResponseRedirect('/profile/delete_drop_failure') except Course.DoesNotExist: return HttpResponseRedirect('/profile/delete_drop_failure') for c in drop_course_list: c2 = Course.objects.get(course_number=c) role = Role.objects.filter(course=c2) if len(role)!= 0: role.delete() c2.delete() return HttpResponseRedirect('/profile/delete_drop_success') else: return HttpResponseRedirect('/profile/delete_drop_failure') #Course.objects.get(course_number=c) #return HttpResponseRedirect('/profile/success') return render_to_response('profile/index.html', {'course_list': course_list, 'teach_list': teach_list, 'ta_list': ta_list, 'user': u},)