Ejemplo n.º 1
0
def student_score(request, sid):
  student = Student.objects.get(id=id_decode(sid))
  semester = current_record_semester(request)
  student.enrolledClasses = student.enroll.filter(semester=semester)

  for aclass in student.enrolledClasses:
    aclass.sessions = aclass.classsession_set.order_by('date')
    aclass.show_attendance = aclass.recordAttendance and aclass.sessions
    for cs in aclass.sessions:
      cs.att, create = Attendance.objects.get_or_create(student=student,
                                                        session=cs)
      aclass.categories = aclass.gradingcategory_set.order_by('order')
      for cat in aclass.categories:
        cat.gds = cat.gradingitem_set.order_by('date')
        for gd in cat.gds:
          try:
            gd.score = Score.objects.get(gradingItem=gd, student=student)
          except:
            gd.score = '_'
  return my_render_to_response(request, 'student_score.html', locals())
Ejemplo n.º 2
0
def edit_student(request, sid=0):
  if sid:
    student = Student.objects.get(id=id_decode(sid))
  else:
    student = Student()
  # if sid and not student_access(request.user, student):
  #    messages.error(request, 'You are not authorized to access information of this student.')
  #    print 'You are not authorized to access information of this student.'
  #    return HttpResponseRedirect('/')
  if request.method == 'GET':
    form = StudentForm(instance=student)
  else:  # POST
    if not sid:
      student = Student(studentID=next_student_id(),
                        family=request.user.profile)
    form = StudentForm(request.POST, instance=student)
    if form.is_valid():
      form.save()
      messages.info(request, 'Student information for %s saved. ' % (
      student.firstName + ' ' + student.lastName,))
      return HttpResponseRedirect('/')
  return my_render_to_response(request, 'edit_student.html', locals())
Ejemplo n.º 3
0
def enroll(request):
  semester = current_reg_semester(request)
  students = get_children(request)
  print request.POST
  mclasses = Class.objects.filter(semester=semester, elective=False)
  eclasses = Class.objects.filter(semester=semester, elective=True)
  for s in students:
    s.eclass = s.mclass = None
    for c in list(mclasses) + list(eclasses):
      # c.student_set.remove(s)
      EnrollDetail.objects.filter(student=s, classPtr=c).delete()

  for k in request.POST:
    v = request.POST[k]
    print k, v
    k = str(k)
    if 'class' not in k or v == '---':
      continue
    cid = id_decode(v)
    theClass = Class.objects.get(id=cid)
    sid = id_decode(k.split('-')[1])
    student = lookup(sid, students)
    if k.startswith('classm'):
      if s.mclass:
        oldm = Class.objects.get(id=s.mclass.id)
        # oldm.student_set.remove(student)
        EnrollDetail.objects.filter(classPtr=oldm, student=student).delete()
      # theClass.student_set.add(student)
      ed = EnrollDetail(student=student, classPtr=theClass)
      ed.save()
      student.mclass = theClass
      theClass.save()

    elif k.startswith('classe'):
      if s.eclass:
        oldm = Class.objects.get(id=s.eclass.id)
        # oldm.student_set.remove(student)
        EnrollDetail.objects.filter(classPtr=oldm, student=student).delete()
      # theClass.student_set.add(student)
      ed = EnrollDetail(student=student, classPtr=theClass)
      ed.save()
      student.eclass = theClass
      # print 'add class', student, theClass
      theClass.save()
  errors = []
  for s in students:
    print s, s.mclass, s.eclass
    if s.mclass:
      if s.mclass.mandate and (
        ('eclass' not in s.__dict__) or s.mclass.mandate != s.eclass):
        errors.append("%s is required to take %s when taking %s" % (
        s, s.mclass.mandate, s.mclass))
      elif s.mclass and s.mclass.elective_required and not s.eclass:
        errors.append(
          "%s is required to take an elective class when taking %s." % (
          s, s.mclass))

  if errors:
    return enroll_form(request, errors)

  if 'enroll_paypal' in request.POST:
    return review_tuition_paypal(request)
  return review_tuition_check(request)