def student_absence_report(request): attendances = Attendance.objects.all() # set up dict of attendance codes with zero values default_attendance = {} attendancecodes = dict(ATTENDANCE_CODES) for key, code in attendancecodes.iteritems(): default_attendance[key] = 0 # default out all current students attendance_by_sid = {} currently_enrolled_students = getEnrolledStudents() for student in currently_enrolled_students: attendance_by_sid[student] = dict(default_attendance) for attendance in attendances: try: attendance_by_sid[attendance.student_id][attendance.attendance] += 1 except KeyError: pass # students no longer in attendance that have attendance return render( request, "mande/student_absence_report.html", {"attendance_by_sid": attendance_by_sid, "attendancecodes": attendancecodes}, )
def students_lag_summary(request): enrolled_students = getEnrolledStudents() schools = School.objects.all() students_lag_by_site = [] students_all_site = {"students_age_not_appropriate_grade_level": [], "total": []} for school in schools: students_lag_by_site.extend( [{"school": school, "students_age_not_appropriate_grade_level": [], "all_students": []}] ) for student in enrolled_students: if student.current_vdp_grade() != 70: if student.current_vdp_grade() != 50: # for each site for student_lag_by_site in students_lag_by_site: if student.site == student_lag_by_site["school"]: if (student.age_appropriate_grade() - student.current_vdp_grade()) > 0: student_lag_by_site["students_age_not_appropriate_grade_level"].append(student) student_lag_by_site["all_students"].append(student) # for all site if (student.age_appropriate_grade() - student.current_vdp_grade()) > 0: students_all_site["students_age_not_appropriate_grade_level"].append(student) students_all_site["total"].append(student) return render( request, "mande/students_lag_summary.html", {"students_lag_by_site": students_lag_by_site, "students_all_site": students_all_site}, )
def student_absence_report(request): attendances = Attendance.objects.all() #set up dict of attendance codes with zero values default_attendance = {} attendancecodes = dict(ATTENDANCE_CODES) for key, code in attendancecodes.iteritems(): default_attendance[key] = 0 #default out all current students attendance_by_sid = {} currently_enrolled_students = getEnrolledStudents() for student in currently_enrolled_students: attendance_by_sid[student] = dict(default_attendance) for attendance in attendances: try: attendance_by_sid[attendance.student_id][ attendance.attendance] += 1 except KeyError: pass #students no longer in attendance that have attendance return render(request, 'mande/student_absence_report.html', { 'attendance_by_sid': attendance_by_sid, 'attendancecodes': attendancecodes })
def studentevaluation_form(request, school_id, date=TODAY, grade_id=None): school = School.objects.get(pk=school_id) warning = '' message = '' students = getEnrolledStudents(int(grade_id)) #pre instantiate data for this form so that we can update the whole queryset later students_at_school_id = [] for student in students: if student.site == school: StudentEvaluation.objects.get_or_create( student_id=student,date=date) students_at_school_id.append(student.student_id) #lets only work with the students at the specified school_id students = students_at_school_id student_evaluations = StudentEvaluation.objects.filter(student_id__in=students, date=date) StudentEvaluationFormSet = modelformset_factory(StudentEvaluation, form=StudentEvaluationForm, extra=0) if request.method == 'POST': formset = StudentEvaluationFormSet(request.POST) print "Is formset valid?" if formset.is_valid(): print "yes!s" formset.save() message = "Saved." #clean up the mess we created making blank rows to update. StudentEvaluation.objects.filter( Q(academic_score=None)& Q(study_score=None)& Q(personal_score=None)& Q(hygiene_score=None)& Q(faith_score=None) ).delete() if grade_id is None: message = 'Recorded student evaluations for '+str(school) else: message = ('Recorded student evaluations for '+ str(dict(GRADES)[int(grade_id)])+ ' at '+str(school)) log = NotificationLog( user=request.user, text=message, font_awesome_icon='fa-calculator') log.save() else: formset = StudentEvaluationFormSet(queryset = student_evaluations) context= { 'school':school, 'grade_id': grade_id, 'students':students, 'date':date, 'formset':formset, 'warning': mark_safe(warning), 'message': message, 'grades': dict(GRADES) } return render(request, 'mande/studentevaluationform.html', context)
def studentevaluation_form(request, school_id, date=TODAY, grade_id=None): school = School.objects.get(pk=school_id) warning = '' message = '' students = getEnrolledStudents(int(grade_id)) #pre instantiate data for this form so that we can update the whole queryset later students_at_school_id = [] for student in students: if student.site == school: StudentEvaluation.objects.get_or_create(student_id=student, date=date) students_at_school_id.append(student.student_id) #lets only work with the students at the specified school_id students = students_at_school_id student_evaluations = StudentEvaluation.objects.filter( student_id__in=students, date=date) StudentEvaluationFormSet = modelformset_factory(StudentEvaluation, form=StudentEvaluationForm, extra=0) if request.method == 'POST': formset = StudentEvaluationFormSet(request.POST) print "Is formset valid?" if formset.is_valid(): print "yes!s" formset.save() message = "Saved." #clean up the mess we created making blank rows to update. StudentEvaluation.objects.filter( Q(academic_score=None) & Q(study_score=None) & Q(personal_score=None) & Q(hygiene_score=None) & Q(faith_score=None)).delete() if grade_id is None: message = 'Recorded student evaluations for ' + str(school) else: message = ('Recorded student evaluations for ' + str(dict(GRADES)[int(grade_id)]) + ' at ' + str(school)) log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-calculator') log.save() else: formset = StudentEvaluationFormSet(queryset=student_evaluations) context = { 'school': school, 'grade_id': grade_id, 'students': students, 'date': date, 'formset': formset, 'warning': mark_safe(warning), 'message': message, 'grades': dict(GRADES) } return render(request, 'mande/studentevaluationform.html', context)
def student_medical_report(request): enrolled_students = getEnrolledStudents() visits = {} for student in enrolled_students: try: visits[student] = len(Health.objects.all().filter(student_id=student)) except ObjectDoesNotExist: pass return render(request, "mande/studentmedicalreport.html", {"visits": visits})
class ClassroomEnrollmentForm(forms.ModelForm): enrolled_students = getEnrolledStudents() student_id = forms.ModelMultipleChoiceField(widget=CheckboxSelectMultipleP,queryset=enrolled_students) enrollment_date = forms.DateField(label=_('Enrollment Date'),widget=Html5DateInput,initial=date.today().isoformat()) def __init__(self, *args, **kwargs): super(ClassroomEnrollmentForm, self).__init__(*args, **kwargs) self.fields['classroom_id'].queryset = Classroom.objects.filter(active=True).order_by('school_id') class Meta: model = ClassroomEnrollment exclude=[]
def student_lag_report(request): enrolled_students = getEnrolledStudents() students_lag = {} for student in enrolled_students: #only students in the scope of grade levels if student.current_vdp_grade() < 12: students_lag[student] = student.age_appropriate_grade() - student.current_vdp_grade() print student.current_vdp_grade() return render(request, 'mande/student_lag_report.html', {'students_lag':students_lag})
def student_lag_report(request): enrolled_students = getEnrolledStudents() students_lag = {} for student in enrolled_students: #only students in the scope of grade levels if student.current_vdp_grade() < 12: students_lag[student] = student.age_appropriate_grade( ) - student.current_vdp_grade() print student.current_vdp_grade() return render(request, 'mande/student_lag_report.html', {'students_lag': students_lag})
def student_lag_report(request): enrolled_students = getEnrolledStudents() students_lag = {} if request.method == "POST": view_date = request.POST["view_date"] else: # convert to correct format with html input type date view_date = date.today().strftime("%Y-%m-%d") for student in enrolled_students: # only students in the scope of grade levels if student.current_vdp_grade(view_date) < 12: students_lag[student] = { "lag": student.age_appropriate_grade(view_date) - student.current_vdp_grade(view_date), "appropriate_grade": student.age_appropriate_grade(view_date), "vdp_grade": student.current_vdp_grade(view_date), } return render(request, "mande/student_lag_report.html", {"students_lag": students_lag, "view_date": view_date})
def data_audit(request, audit_type='ALL'): #modelfields = model_to_dict(IntakeSurvey.objects.all()[0]) students = getEnrolledStudents() filters = [] #a anomalies = {} for student in students: '''students with missing information''' text = 'Missing ' resolution = reverse('intake_update', kwargs={'student_id': student.student_id}) student_data = student.getRecentFields() temp = IntakeSurveyForm(data=student_data) for field in temp: #blank fields if ((field.data is None or len(unicode(field.data)) == 0) and field.label != "Notes" and (field.name == 'reasons' and student_data['enrolled'] == 'N')): #students who aren't enrolled and have no reason addAnomaly(anomalies, student, text + field.label, resolution) filters.append(text + field.label) '''students who have grade and enrollment status mismatched''' if ((student_data['grade_last'] < 0 and student_data['enrolled'] == 'N') or #students who aren't enrolled and have no last grade (student_data['grade_current'] < 0 and student_data['enrolled'] == 'Y') ): #students who are enrolled but don't have a current grade text = 'Enrollment status and grade data mismatch' resolution = reverse('intake_survey', kwargs={'student_id': student.student_id}) addAnomaly(anomalies, student, text, resolution) filters.append(text) '''students who are quite young or quite old''' if (student.dob.year > (datetime.now().year - TOO_YOUNG)) or ( student.dob.year < datetime.now().year - TOO_OLD): text = 'Incorrect DOB ' age = '(~' + unicode(datetime.now().year - student.dob.year) + ' years old)' resolution = reverse('intake_survey', kwargs={'student_id': student.student_id}) limit = 'dob' addAnomaly(anomalies, student, text + age, resolution, limit) filters.append(text) '''students who have never been present''' if Attendance.objects.filter(student_id=student, attendance='P').count() == 0: '''are either not enrolled''' if len(ClassroomEnrollment.objects.filter( student_id=student)) == 0: text = 'Not enrolled in any classes' resolution = reverse('classroomenrollment_form') addAnomaly(anomalies, student, text, resolution) filters.append(text) '''... or just not good at showing up!''' if Attendance.objects.filter(student_id=student).count() > 0: text = 'Has never attended class' resolution = reverse('student_detail', kwargs={'student_id': student.student_id}) addAnomaly(anomalies, student, text, resolution) filters.append(text) #remove duplicates in a now long array filters = set(filters) filters = sorted(filters) return render(request, 'mande/data_audit.html', { 'students': anomalies, 'filters': filters })