def view_app(self, request, tl, one, two, module, extra, prog): scrmi = prog.getModuleExtension('StudentClassRegModuleInfo') reg_nodes = scrmi.reg_verbs() try: cls = ClassSubject.objects.get(id = extra) section = cls.default_section() except ClassSubject.DoesNotExist: raise ESPError(False), 'Cannot find class.' student = request.GET.get('student',None) if not student: student = request.POST.get('student','') try: student = ESPUser(User.objects.get(id = student)) except ESPUser.DoesNotExist: raise ESPError(False), 'Cannot find student, %s' % student if student.userbit_set.filter(qsc__parent=cls.anchor, verb__in=reg_nodes).count() == 0: raise ESPError(False), 'Student not a student of this class.' try: student.app = student.studentapplication_set.get(program = self.program) except: student.app = None assert False, student.studentapplication_set.all()[0].__dict__ raise ESPError(False), 'Error: Student did not apply. Student is automatically rejected.' return render_to_response(self.baseDir()+'app_popup.html', request, (prog, tl), {'class': cls, 'student': student})
def activate_account(request): if not 'username' in request.GET or not 'key' in request.GET: raise ESPError( "Invalid account activation information. Please try again. If this error persists, please contact us using the contact information on the top or bottom of this page.", log=False) try: u = ESPUser.objects.get(username=request.GET['username']) except: raise ESPError( "Invalid account username. Please try again. If this error persists, please contact us using the contact information on the top or bottom of this page.", log=False) if u.is_active: raise ESPError( 'The user account supplied has already been activated. If you have lost your password, visit the <a href="/myesp/passwdrecover/">password recovery form</a>. Otherwise, please <a href="/accounts/login/?next=/myesp/profile/">log in</a>.', log=False) if not u.password.endswith("_%s" % request.GET['key']): raise ESPError( "Incorrect key. Please try again to click the link in your email, or copy the url into your browser. If this error persists, please contact us using the contact information on the top or bottom of this page.", log=False) u.password = u.password[:-(len("_%s" % request.GET['key']))] u.is_active = True u.save() return HttpResponseRedirect('/myesp/profile/')
def review_students(self, request, tl, one, two, module, extra, prog): """ Show a roster of the students in the class, allowing the administrators to accept students into the program based on the teachers' reviews and the students' applications. """ try: cls = ClassSubject.objects.get(id=extra) except ClassSubject.DoesNotExist: raise ESPError(False), 'Cannot find class.' if not request.user.canEdit(cls): raise ESPError(False), 'You cannot edit class "%s"' % cls # Fetch any student even remotely related to the class. students_dict = cls.students_dict() students = [] for key in students_dict: students += students_dict[key] students = filter( lambda x: x.studentapplication_set.filter(program=self.program). count() > 0, students) for student in students: student.added_class = student.studentregistration_set.filter( section__parent_class=cls)[0].start_date try: student.app = student.studentapplication_set.get( program=self.program) except: student.app = None if student.app: reviews = student.app.reviews.all() else: reviews = [] if StudentRegistration.valid_objects().filter( user=student, section__parent_class=cls, relationship__name='Accepted').count() > 0: student.status = 'Accepted' else: student.status = 'Not accepted' students = list(students) students.sort(key=lambda x: x.last_name) return render_to_response(self.baseDir() + 'roster.html', request, { 'class': cls, 'students': students, 'program': prog })
def review_students(self, request, tl, one, two, module, extra, prog): """ Show a roster of the students in the class, allowing the administrators to accept students into the program based on the teachers' reviews and the students' applications. """ accept_node = GetNode('V/Flags/Registration/Accepted') try: cls = ClassSubject.objects.get(id = extra) except ClassSubject.DoesNotExist: raise ESPError(False), 'Cannot find class.' if not request.user.canEdit(cls): raise ESPError(False), 'You cannot edit class "%s"' % cls # Fetch any student even remotely related to the class. students_dict = cls.students_dict() students = [] for key in students_dict: students += students_dict[key] students = filter(lambda x: x.studentapplication_set.filter(program=self.program).count() > 0, students) for student in students: student.added_class = student.userbit_set.filter(QTree(qsc__below = cls.anchor))[0].startdate try: student.app = student.studentapplication_set.get(program = self.program) except: student.app = None if student.app: reviews = student.app.reviews.all() else: reviews = [] if UserBit.objects.filter(user=student, qsc=cls.anchor, verb=accept_node).count() > 0: student.status = 'Accepted' else: student.status = 'Not accepted' students = list(students) students.sort(key=lambda x: x.last_name) return render_to_response(self.baseDir()+'roster.html', request, (prog, tl), {'class': cls, 'students':students})
def accept_student(self, request, tl, one, two, module, extra, prog): """ Accept a student into a class. """ accept_node = GetNode('V/Flags/Registration/Accepted') try: cls = ClassSubject.objects.get(id = request.GET.get('cls','')) student = User.objects.get(id = request.GET.get('student','')) except: raise ESPError(False), 'Student or class not found.' UserBit.objects.get_or_create(user=student, qsc=cls.anchor, verb=accept_node, recursive=False) return self.review_students(request, tl, one, two, module, extra, prog)
def activate_account(request): if not 'username' in request.GET or not 'key' in request.GET: raise ESPError( False ), "Invalid account activation information. Please try again. If this error persists, please contact us using the contact information on the top or bottom of this page." try: u = ESPUser.objects.get(username=request.GET['username']) except: raise ESPError( False ), "Invalid account username. Please try again. If this error persists, please contact us using the contact information on the top or bottom of this page." if not u.password.endswith("_%s" % request.GET['key']): raise ESPError( False ), "Incorrect key. Please try again to click the link in your email, or copy the url into your browser. If this error persists, please contact us using the contact information on the top or bottom of this page." u.password = u.password[:-(len("_%s" % request.GET['key']))] u.is_active = True u.save() return HttpResponseRedirect('/myesp/profile/')
def reject_student(self, request, tl, one, two, module, extra, prog): """ Reject a student from a class (does not affect their registration). """ accept_node = GetNode('V/Flags/Registration/Accepted') try: cls = ClassSubject.objects.get(id = request.GET.get('cls','')) student = User.objects.get(id = request.GET.get('student','')) except: raise ESPError(False), 'Student or class not found.' UserBit.objects.filter(user=student, qsc=cls.anchor, verb=accept_node, recursive=False).delete() return self.review_students(request, tl, one, two, module, extra, prog)
def view_app(self, request, tl, one, two, module, extra, prog): scrmi = prog.studentclassregmoduleinfo reg_nodes = scrmi.reg_verbs() try: cls = ClassSubject.objects.get(id=extra) section = cls.default_section() except ClassSubject.DoesNotExist: raise ESPError('Cannot find class.', log=False) student = request.GET.get('student', None) if not student: student = request.POST.get('student', '') try: student = ESPUser.objects.get(id=student) except ESPUser.DoesNotExist: raise ESPError('Cannot find student, %s' % student, log=False) if student.studentregistration_set.filter( section__parent_class=cls).count() == 0: raise ESPError('Student not a student of this class.', log=False) try: student.app = student.studentapplication_set.get( program=self.program) except: student.app = None assert False, student.studentapplication_set.all()[0].__dict__ raise ESPError( 'Error: Student did not apply. Student is automatically rejected.', log=False) return render_to_response(self.baseDir() + 'app_popup.html', request, { 'class': cls, 'student': student })
def navBarNew(request, navbar, node, section): """ Create a new NavBarEntry. Put it at the bottom of the current sort_rank. """ child_node = request.POST.get('child_node', '') if node == '': raise ESPError(False), "Please specify a child node." try: child_node = DataTree.objects.get(id=child_node) except DataTree.DoesNotExist: raise ESPError(False), "Invalid child node specified." if not UserBit.UserHasPerms(request.user, node, GetNode(EDIT_VERB_STRING)): raise PermissionDenied, "You don't have permisssion to do that!" try: max_sort_rank = NavBarEntry.objects.filter( path=node).order_by('-sort_rank')[0].sort_rank except IndexError: max_sort_rank = -100 new_sort_rank = max_sort_rank + 100 try: url = request.POST['url'] entry = NavBarEntry() entry.path = child_node entry.sort_rank = new_sort_rank entry.link = url entry.text = request.POST['text'] entry.indent = request.POST['indent'] entry.section = section entry.save() except Exception: raise
def accept_student(self, request, tl, one, two, module, extra, prog): """ Accept a student into a class. """ try: cls = ClassSubject.objects.get(id=request.GET.get('cls', '')) student = ESPUser.objects.get(id=request.GET.get('student', '')) except: raise ESPError(False), 'Student or class not found.' # Note: no support for multi-section classes. sec = cls.get_sections()[0] (rtype, created) = RegistrationType.objects.get_or_create(name='Accepted') StudentRegistration.objects.get_or_create(user=student, section=sec, relationship=rtype) return self.review_students(request, tl, one, two, module, extra, prog)
def reject_student(self, request, tl, one, two, module, extra, prog): """ Reject a student from a class (does not affect their registration). """ try: cls = ClassSubject.objects.get(id=request.GET.get('cls', '')) student = ESPUser.objects.get(id=request.GET.get('student', '')) except: raise ESPError(False), 'Student or class not found.' # Note: no support for multi-section classes. sec = cls.get_sections()[0] (rtype, created) = RegistrationType.objects.get_or_create(name='Accepted') for reg in StudentRegistration.objects.filter(user=student, section=sec, relationship=rtype): reg.expire() return self.review_students(request, tl, one, two, module, extra, prog)
def review_students(self, request, tl, one, two, module, extra, prog): try: cls = ClassSubject.objects.get(id = extra) except ClassSubject.DoesNotExist: raise ESPError('Cannot find class.', log=False) if not request.user.canEdit(cls): raise ESPError('You cannot edit class "%s"' % cls, log=False) # Fetch any student even remotely related to the class. students_dict = cls.students_dict() students = [] for key in students_dict: students += students_dict[key] for student in students: now = datetime.now() student.added_class = StudentRegistration.valid_objects().filter(section__parent_class = cls, user = student)[0].start_date try: student.app = student.studentapplication_set.get(program = self.program) except: student.app = None if student.app: reviews = student.app.reviews.all().filter(reviewer=request.user, score__isnull=False) questions = student.app.questions.all().filter(subject=cls) else: reviews = [] questions = [] if len(reviews) > 0: student.app_reviewed = reviews[0] else: student.app_reviewed = None student.app_completed = False for i in questions: for j in i.studentappresponse_set.all(): if j.complete: student.app_completed = True students = list(students) students.sort(lambda x,y: cmp(x.added_class,y.added_class)) if 'prev' in request.GET: prev_id = int(request.GET.get('prev')) prev = students[0] current = None for current in students[1:]: if prev.id == prev_id and current.app_completed: from django.shortcuts import redirect url = "/%s/%s/%s/review_student/%s/?student=%s" % (tl, one, two, extra, current.id) return redirect(url) if prev.id != prev_id: prev = current return render_to_response(self.baseDir()+'roster.html', request, {'class': cls, 'students':students})
def review_student(self, request, tl, one, two, module, extra, prog): scrmi = prog.studentclassregmoduleinfo reg_nodes = scrmi.reg_verbs() try: cls = ClassSubject.objects.get(id = extra) except ClassSubject.DoesNotExist: raise ESPError('Cannot find class.', log=False) if not request.user.canEdit(cls): raise ESPError('You cannot edit class "%s"' % cls, log=False) student = request.GET.get('student',None) if not student: student = request.POST.get('student','') try: student = ESPUser.objects.get(id = int(student)) except ESPUser.DoesNotExist: raise ESPError('Cannot find student, %s' % student, log=False) not_registered = not StudentRegistration.valid_objects().filter(section__parent_class = cls, user = student).exists() if not_registered: raise ESPError('Student not a student of this class.', log=False) try: student.app = student.studentapplication_set.get(program = self.program) except: student.app = None raise ESPError('Error: Student did not start an application.', log=False) student.added_class = StudentRegistration.valid_objects().filter(section__parent_class = cls, user = student)[0].start_date teacher_reviews = student.app.reviews.all().filter(reviewer=request.user) if teacher_reviews.count() > 0: this_review = teacher_reviews.order_by('id')[0] else: this_review = StudentAppReview(reviewer=request.user) this_review.save() student.app.reviews.add(this_review) if request.method == 'POST': form = this_review.get_form(request.POST) if form.is_valid(): form.target.update(form) if 'submit_next' in request.POST or 'submit_return' in request.POST: url = '/%s/%s/%s/review_students/%s/' % (tl, one, two, extra) if 'submit_next' in request.POST: url += '?prev=%s' % student.id from django.shortcuts import redirect return redirect(url) # self.review_students(request, tl, one, two, module, extra, prog) else: form = this_review.get_form() return render_to_response(self.baseDir()+'review.html', request, {'class': cls, 'reviews': teacher_reviews, 'program': prog, 'student':student, 'form': form})