def academic_form_single(request, student_id=0,test_id=None): form_error_message= {} if request.method == 'POST': if test_id == None: form = AcademicForm(request.POST) instance,created = Academic.objects.get_or_create(student_id=IntakeSurvey.objects.get(pk=form.data['student_id']), test_date=form.data['test_date'], test_level=form.data['test_level']) form = AcademicForm(request.POST,instance=instance) else: created =None instance = Academic.objects.get(id=test_id) form = AcademicForm(request.POST,instance=instance) if form.is_valid(): #process instance = form.save() action = 'Recorded ' if created else 'Updated ' message = (action+'semester test for '+instance.student_id.name) log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-calculator') log.save() # then return return HttpResponseRedirect( reverse('student_detail', kwargs={'student_id':instance.student_id.student_id})) else: action = 'Adding ' if created else 'Editing ' form_error_message= form.errors.as_text() else: if student_id and test_id: instance = Academic.objects.get(id=test_id) form = AcademicForm(instance=instance) action ="Editing" else: form = AcademicForm() if student_id >0: try: action = 'Editing' instance = Academic.objects.get(student_id=IntakeSurvey.objects.get(pk=student_id), test_date=date.today().isoformat(), test_level=getStudentGradebyID(student_id)) form = AcademicForm(instance=instance) except ObjectDoesNotExist: action = 'Adding' form = AcademicForm({'student_id':student_id, 'test_date':date.today().isoformat(), 'test_level':getStudentGradebyID(student_id)}) else: action = 'Adding' form = AcademicForm() context = {'form': form,'student_id':student_id,'test_id':test_id,'action':action,'form_error_message':form_error_message} return render(request, 'mande/academicformsingle.html',context)
def academic_form_single(request, student_id=0): if request.method == 'POST': form = AcademicForm(request.POST) if form.is_valid(): #process instance = form.save() message = 'Recorded semester test for '+instance.student_id.name log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-calculator') log.save() #then return return HttpResponseRedirect( reverse('student_detail', kwargs={'student_id':instance.student_id.student_id})) else: if student_id > 0: form = AcademicForm({ 'student_id':student_id, 'test_date':TODAY, 'test_level':getStudentGradebyID(student_id)}) else: form = AcademicForm() context = {'form': form,'student_id':student_id} return render(request, 'mande/academicformsingle.html',context)
def academic_form_single(request, student_id=0): if request.method == 'POST': form = AcademicForm(request.POST) if form.is_valid(): #process instance = form.save() message = 'Recorded semester test for ' + instance.student_id.name log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-calculator') log.save() #then return return HttpResponseRedirect( reverse('student_detail', kwargs={'student_id': instance.student_id.student_id})) else: if student_id > 0: form = AcademicForm({ 'student_id': student_id, 'test_date': TODAY, 'test_level': getStudentGradebyID(student_id) }) else: form = AcademicForm() context = {'form': form, 'student_id': student_id} return render(request, 'mande/academicformsingle.html', context)
def academic_form_single(request, student_id=0, test_id=None): #get current method name method_name = inspect.currentframe().f_code.co_name if user_permissions(method_name, request.user): form_error_message = {} locked = True today = date.today().isoformat() making_period = AcademicMarkingPeriod.objects.all().filter( Q(marking_period_start__lte=today) & Q(marking_period_end__gte=today)) if len(making_period) >= 1: locked = False if request.method == 'POST': if test_id == None: form = AcademicForm(request.POST) instance, created = Academic.objects.get_or_create( student_id=IntakeSurvey.objects.get( pk=form.data['student_id']), test_date=form.data['test_date'], test_level=form.data['test_level']) form = AcademicForm(request.POST, instance=instance) else: created = None instance = Academic.objects.get(id=test_id) form = AcademicForm(request.POST, instance=instance) if form.is_valid(): #process test_date = request.POST['test_date'] period = AcademicMarkingPeriod.objects.all().filter( test_date=test_date) if len(period) >= 1: instance = form.save() action = 'Recorded ' if created else 'Updated ' message = (action + 'semester test for ' + instance.student_id.name) log = NotificationLog(user=request.user, text=message, font_awesome_icon='fa-calculator') log.save() # update cache table student = IntakeSurvey.objects.get( student_id=instance.student_id.student_id) update_student = CurrentStudentInfo.objects.get( student_id=student.student_id) update_student.at_grade_level = studentAtAgeAppropriateGradeLevel( student.student_id) update_student.vdp_grade = student.current_vdp_grade() update_student.refresh = date.today().isoformat() update_student.save() # then return return HttpResponseRedirect( reverse('student_detail', kwargs={ 'student_id': instance.student_id.student_id })) else: action = 'Adding ' if created else 'Editing ' form.add_error(None, "") form_error_message = "Test date doesn't match with AcademicMarkingPeriod date." else: action = 'Adding ' if created else 'Editing ' form_error_message = form.errors.as_text() else: if student_id and test_id: instance = Academic.objects.get(id=test_id) form = AcademicForm(instance=instance) action = "Editing" else: form = AcademicForm() if student_id > 0: try: action = 'Editing' instance = Academic.objects.get( student_id=IntakeSurvey.objects.get(pk=student_id), test_date=date.today().isoformat(), test_level=getStudentGradebyID(student_id)) form = AcademicForm(instance=instance) except ObjectDoesNotExist: action = 'Adding' form = AcademicForm({ 'student_id': student_id, 'test_date': date.today().isoformat(), 'test_level': getStudentGradebyID(student_id) }) else: action = 'Adding' form = AcademicForm() context = { 'form': form, 'student_id': student_id, 'test_id': test_id, 'action': action, 'form_error_message': form_error_message, 'locked': locked } return render(request, 'mande/academicformsingle.html', context) else: raise PermissionDenied
def student_detail(request, student_id): #get current method name method_name = inspect.currentframe().f_code.co_name if user_permissions(method_name, request.user): # -----------------attendances by school year---------------------- attendances = Attendance.objects.filter(student_id=student_id) attendance_years = [] years = datetime.now().year - 2012 list_of_years = [] # generate list of year for i in range(years): list_of_years.append(2013 + i) for list_of_year in list_of_years: attendance_years.extend([{ 'year': list_of_year, 'present': [], 'unapproved': [], 'approved': [] }]) for attendance in attendances: for attendance_year in attendance_years: if attendance_year['year'] == attendance.date.year or int( attendance_year['year']) + 1 == attendance.date.year: beginning = str(attendance_year['year']) + "-08-01" end = str(attendance_year['year'] + 1) + "-07-31" beginning_of_school_year = datetime.strptime( beginning, "%Y-%m-%d").date() end_of_school_year = datetime.strptime(end, "%Y-%m-%d").date() if attendance.date >= beginning_of_school_year and attendance.date <= end_of_school_year: if attendance.attendance == 'P': attendance_year['present'].append(attendance) elif attendance.attendance == 'UA': attendance_year['unapproved'].append(attendance) elif attendance.attendance == 'AA': attendance_year['approved'].append(attendance) #------------------------------end------------------------------------ try: survey = IntakeSurvey.objects.get(pk=student_id) except IntakeSurvey.DoesNotExist as e: context = {'error_sms': e} return render(request, 'mande/errors/intakesurveynotexist.html', context) intake = survey.intakeinternal_set.all().filter().order_by( '-enrollment_date') try: exit_survey = survey.exitsurvey_set.all()[0] except IndexError: exit_survey = None try: post_exit_survey = survey.postexitsurvey_set.all()[0] except IndexError: post_exit_survey = None #select only semester tests which have grades in them academics = survey.academic_set.all().filter( Q(test_grade_khmer__isnull=False) & Q(test_grade_math__isnull=False)).order_by('-test_level') evaluations = survey.studentevaluation_set.all().order_by( '-date').exclude( Q(academic_score=None) & Q(study_score=None) & Q(personal_score=None) & Q(hygiene_score=None) & Q(faith_score=None)) notes = survey.getNotes() discipline = survey.discipline_set.all().filter().order_by( '-incident_date') dental = survey.health_set.all().filter( appointment_type='DENTAL').order_by('-appointment_date') checkups = survey.health_set.all().filter( appointment_type='CHECKUP').order_by('-appointment_date') classroomenrollment = survey.classroomenrollment_set.all().filter( ).order_by('drop_date') attendance_present = survey.attendance_set.all().filter( attendance='P').count() attendance_approved_absence = survey.attendance_set.all().filter( attendance='AA').count() attendance_unapproved_absence = survey.attendance_set.all().filter( attendance='UA').count() if len(intake) > 0: recent_intake = intake[0] else: recent_intake = 'Not enrolled' current_grade = getStudentGradebyID(student_id) graduation = survey.dob + timedelta( days=365 * 12) if survey.dob is not None else "No birthday entered" publich_school_historys = survey.publicschoolhistory_set.all() spiritual_activities = survey.spiritualactivitiessurvey_set.all() pschool = survey.get_pschool() context = { 'survey': survey.getRecentFields(), 'recent_intake': recent_intake, 'academics': academics, 'evaluations': evaluations, 'current_grade': current_grade, 'discipline': discipline, 'dental': dental, 'checkups': checkups, 'cur_year': date.today().year, 'graduation': graduation, 'classroomenrollment': classroomenrollment, 'attendance_present': attendance_present, 'attendance_approved_absence': attendance_approved_absence, 'attendance_unapproved_absence': attendance_unapproved_absence, 'exit_survey': exit_survey, 'post_exit_survey': post_exit_survey, 'notes': notes, 'TODAY': date.today().isoformat(), 'attendance_years': attendance_years, 'publich_school_historys': publich_school_historys, 'spiritual_activities': spiritual_activities, 'pschool': pschool } return render(request, 'mande/detail.html', context) else: raise PermissionDenied
def student_detail(request, student_id): survey = IntakeSurvey.objects.get(pk=student_id) intake = survey.intakeinternal_set.all().filter().order_by( '-enrollment_date' ) try: exit_survey = survey.exitsurvey_set.all()[0] except IndexError: exit_survey = None try: post_exit_survey = survey.postexitsurvey_set.all()[0] except IndexError: post_exit_survey = None #select only semester tests which have grades in them academics = survey.academic_set.all().filter( Q(test_grade_khmer__isnull=False) & Q(test_grade_math__isnull=False)).order_by('-test_level') evaluations = survey.studentevaluation_set.all().order_by('-date').exclude( Q(academic_score=None)& Q(study_score=None)& Q(personal_score=None)& Q(hygiene_score=None)& Q(faith_score=None) ) notes = survey.getNotes() discipline = survey.discipline_set.all().filter().order_by('-incident_date') dental = survey.health_set.all().filter( appointment_type='DENTAL' ).order_by('-appointment_date') checkups = survey.health_set.all().filter( appointment_type='CHECKUP' ).order_by('-appointment_date') classroomenrollment = survey.classroomenrollment_set.all().filter().order_by('drop_date') attendance_present = survey.attendance_set.all().filter(attendance='P').count() attendance_approved_absence = survey.attendance_set.all().filter(attendance='AA').count() attendance_unapproved_absence = survey.attendance_set.all().filter(attendance='UA').count() if len(intake) > 0: recent_intake = intake[0] else: recent_intake = 'Not enrolled' current_grade = getStudentGradebyID(student_id) graduation = survey.dob +timedelta(days=365*12) if survey.dob is not None else "No birthday entered" context = { 'survey': survey.getRecentFields(), 'recent_intake':recent_intake, 'academics':academics, 'evaluations':evaluations, 'current_grade':current_grade, 'discipline':discipline, 'dental':dental, 'checkups':checkups, 'cur_year':date.today().year, 'graduation': graduation, 'classroomenrollment':classroomenrollment, 'attendance_present':attendance_present, 'attendance_approved_absence':attendance_approved_absence, 'attendance_unapproved_absence':attendance_unapproved_absence, 'exit_survey':exit_survey, 'post_exit_survey':post_exit_survey, 'notes':notes, 'TODAY':TODAY} return render(request, 'mande/detail.html', context)
def academic_form(request, school_id, test_date=TODAY, grade_id=None): school = School.objects.get(pk=school_id) warning = '' message = '' students = IntakeSurvey.objects.all().filter(site=school_id) #find out if any student acadmics have been recorded student_academics = Academic.objects.filter(student_id=students, test_date=test_date) #pre instantiate data for this form so that we can update the whole queryset later if grade_id is None: for student in students: Academic.objects.get_or_create( student_id=student, test_date=test_date, test_level=getStudentGradebyID(student.student_id)) student_academics = Academic.objects.filter(student_id=students, test_date=test_date) else: for student in students: if getStudentGradebyID(student.student_id) == int(grade_id): Academic.objects.get_or_create( student_id=student, test_date=test_date, test_level=grade_id) student_academics = Academic.objects.filter(student_id=students, test_date=test_date, test_level=grade_id) AcademicFormSet = modelformset_factory(Academic, form=AcademicForm, extra=0) if request.method == 'POST': formset = AcademicFormSet(request.POST) if formset.is_valid(): formset.save() message = "Saved." #clean up the mess we created making blank rows to update. Academic.objects.filter( Q(test_grade_khmer=None)& Q(test_grade_math=None) ).delete() if grade_id is None: message = 'Recorded semester tests for '+str(school) else: message = ('Recorded semester tests 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 = AcademicFormSet(queryset = student_academics) context= { 'school':school, 'grade_id': grade_id, 'students':students, 'test_date':test_date, 'formset':formset, 'warning': mark_safe(warning), 'message': message, 'grades': dict(GRADES) } return render(request, 'mande/academicform.html', context)
def dashboard(request): notifications = NotificationLog.objects.order_by('-date')[:10] ''' enrolled students are those who have: - completed an intake survey - have completed an internal intake AND - do not have an exit survey OR - have an exit survey with an exit date after today ''' #get a flat list of student_ids to exclude exit_surveys = ExitSurvey.objects.all().filter( exit_date__lte=TODAY).values_list('student_id', flat=True) #filter out students who have exit surveys surveys = IntakeSurvey.objects.order_by('student_id').exclude( student_id__in=exit_surveys) #figure out students who have internal intakes with enrollment dates before today enrolled_students = IntakeInternal.objects.all().values_list('student_id', flat=True) #figure out which students don't have internal intakes unenrolled_students = surveys.exclude( student_id__in=enrolled_students) #pass this queryset on not_enrolled = unenrolled_students.values_list('student_id', flat=True) #filter out students who aren't enrolled, as detailed above surveys = surveys.exclude(student_id__in=not_enrolled) tot_females = surveys.filter(gender='F').count() #set up for collecting school breakdowns schools = School.objects.all() breakdown = {} students_by_grade = dict(GRADES) students_at_gl_by_grade = dict(GRADES) students_by_grade_by_site = dict(GRADES) students_at_gl_by_grade_by_site = dict(GRADES) #zero things out for accurate counts for key, grade in students_by_grade.iteritems(): students_by_grade[key] = 0 students_at_gl_by_grade[key] = 0 students_by_grade_by_site[key] = {} students_at_gl_by_grade_by_site[key] = {} for school in schools: name = school.school_name students_by_grade_by_site[key][unicode(name)] = 0 students_at_gl_by_grade_by_site[key][unicode(name)] = 0 #get information for morris donut charts for school in schools: name = school.school_name total = surveys.filter(site=school) females = total.filter(gender='F').count() males = total.filter(gender='M').count() breakdown[name] = {'F': females, 'M': males} #loop through students and figure out what grades they're currently in for student in surveys: grade = getStudentGradebyID(student.student_id) students_by_grade[grade] += 1 students_by_grade_by_site[grade][unicode(student.site)] += 1 if studentAtAgeAppropriateGradeLevel(student.student_id): students_at_gl_by_grade[grade] += 1 students_at_gl_by_grade_by_site[grade][unicode(student.site)] += 1 #clean up students_by_grade_by_site so we're not displaying a bunch of blank data clean_students_by_grade_by_site = dict(students_by_grade_by_site) for key, grade in students_by_grade_by_site.iteritems(): if students_by_grade[key] == 0: del clean_students_by_grade_by_site[key] context = { 'surveys': surveys, 'females': tot_females, 'breakdown': breakdown, 'students_by_grade': students_by_grade, 'students_at_gl_by_grade': students_at_gl_by_grade, 'students_by_grade_by_site': clean_students_by_grade_by_site, 'students_at_gl_by_grade_by_site': students_at_gl_by_grade_by_site, 'schools': schools, 'notifications': notifications, 'unenrolled_students': unenrolled_students } return render(request, 'mande/index.html', context)
def student_detail(request, student_id): survey = IntakeSurvey.objects.get(pk=student_id) intake = survey.intakeinternal_set.all().filter().order_by( '-enrollment_date') try: exit_survey = survey.exitsurvey_set.all()[0] except IndexError: exit_survey = None try: post_exit_survey = survey.postexitsurvey_set.all()[0] except IndexError: post_exit_survey = None #select only semester tests which have grades in them academics = survey.academic_set.all().filter( Q(test_grade_khmer__isnull=False) & Q(test_grade_math__isnull=False)).order_by('-test_level') evaluations = survey.studentevaluation_set.all().order_by('-date').exclude( Q(academic_score=None) & Q(study_score=None) & Q(personal_score=None) & Q(hygiene_score=None) & Q(faith_score=None)) notes = survey.getNotes() discipline = survey.discipline_set.all().filter().order_by( '-incident_date') dental = survey.health_set.all().filter( appointment_type='DENTAL').order_by('-appointment_date') checkups = survey.health_set.all().filter( appointment_type='CHECKUP').order_by('-appointment_date') classroomenrollment = survey.classroomenrollment_set.all().filter( ).order_by('drop_date') attendance_present = survey.attendance_set.all().filter( attendance='P').count() attendance_approved_absence = survey.attendance_set.all().filter( attendance='AA').count() attendance_unapproved_absence = survey.attendance_set.all().filter( attendance='UA').count() if len(intake) > 0: recent_intake = intake[0] else: recent_intake = 'Not enrolled' current_grade = getStudentGradebyID(student_id) graduation = survey.dob + timedelta( days=365 * 12) if survey.dob is not None else "No birthday entered" context = { 'survey': survey.getRecentFields(), 'recent_intake': recent_intake, 'academics': academics, 'evaluations': evaluations, 'current_grade': current_grade, 'discipline': discipline, 'dental': dental, 'checkups': checkups, 'cur_year': date.today().year, 'graduation': graduation, 'classroomenrollment': classroomenrollment, 'attendance_present': attendance_present, 'attendance_approved_absence': attendance_approved_absence, 'attendance_unapproved_absence': attendance_unapproved_absence, 'exit_survey': exit_survey, 'post_exit_survey': post_exit_survey, 'notes': notes, 'TODAY': TODAY } return render(request, 'mande/detail.html', context)
def academic_form(request, school_id, test_date=TODAY, grade_id=None): school = School.objects.get(pk=school_id) warning = '' message = '' students = IntakeSurvey.objects.all().filter(site=school_id) #find out if any student acadmics have been recorded student_academics = Academic.objects.filter(student_id=students, test_date=test_date) #pre instantiate data for this form so that we can update the whole queryset later if grade_id is None: for student in students: Academic.objects.get_or_create(student_id=student, test_date=test_date, test_level=getStudentGradebyID( student.student_id)) student_academics = Academic.objects.filter(student_id=students, test_date=test_date) else: for student in students: if getStudentGradebyID(student.student_id) == int(grade_id): Academic.objects.get_or_create(student_id=student, test_date=test_date, test_level=grade_id) student_academics = Academic.objects.filter(student_id=students, test_date=test_date, test_level=grade_id) AcademicFormSet = modelformset_factory(Academic, form=AcademicForm, extra=0) if request.method == 'POST': formset = AcademicFormSet(request.POST) if formset.is_valid(): formset.save() message = "Saved." #clean up the mess we created making blank rows to update. Academic.objects.filter( Q(test_grade_khmer=None) & Q(test_grade_math=None)).delete() if grade_id is None: message = 'Recorded semester tests for ' + str(school) else: message = ('Recorded semester tests 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 = AcademicFormSet(queryset=student_academics) context = { 'school': school, 'grade_id': grade_id, 'students': students, 'test_date': test_date, 'formset': formset, 'warning': mark_safe(warning), 'message': message, 'grades': dict(GRADES) } return render(request, 'mande/academicform.html', context)
def dashboard(request): notifications = NotificationLog.objects.order_by('-date')[:10] ''' enrolled students are those who have: - completed an intake survey - have completed an internal intake AND - do not have an exit survey OR - have an exit survey with an exit date after today ''' #get a flat list of student_ids to exclude exit_surveys = ExitSurvey.objects.all().filter( exit_date__lte=date.today().isoformat() ).values_list('student_id',flat=True) #filter out students who have exit surveys surveys = IntakeSurvey.objects.order_by('student_id' ).exclude(student_id__in=exit_surveys) #figure out students who have internal intakes with enrollment dates before today enrolled_students = IntakeInternal.objects.all( ).values_list('student_id',flat=True) #figure out which students don't have internal intakes unenrolled_students = surveys.exclude(student_id__in=enrolled_students) #pass this queryset on not_enrolled = unenrolled_students.values_list('student_id',flat=True) #filter out students who aren't enrolled, as detailed above surveys = surveys.exclude(student_id__in=not_enrolled) tot_females = surveys.filter(gender='F').count() #set up for collecting school breakdowns schools = School.objects.all() breakdown = {} students_by_grade = dict(GRADES) students_at_gl_by_grade = dict(GRADES) students_by_grade_by_site = dict(GRADES) students_at_gl_by_grade_by_site = dict(GRADES) program_breakdown = {} total_skills = 0 #zero things out for accurate counts for key,grade in students_by_grade.iteritems(): students_by_grade[key] = 0 students_at_gl_by_grade[key] = 0 students_by_grade_by_site[key] = {} students_at_gl_by_grade_by_site[key] = {} for school in schools: name = school.school_name students_by_grade_by_site[key][unicode(name)] = 0 students_at_gl_by_grade_by_site[key][unicode(name)] = 0 #get information for morris donut charts for school in schools: name = school.school_name total = surveys.filter(site=school) females = total.filter(gender='F').count() males = total.filter(gender='M').count() breakdown[name] = {'F':females, 'M':males} program_breakdown[name] = {'Grades': 0, 'Skills': 0} #loop through students and figure out what grades they're currently in for student in surveys: grade = getStudentGradebyID(student.student_id) students_by_grade[grade] += 1 students_by_grade_by_site[grade][unicode(student.site)] +=1 if studentAtAgeAppropriateGradeLevel(student.student_id): students_at_gl_by_grade[grade] +=1 students_at_gl_by_grade_by_site[grade][unicode(student.site)] +=1 if grade >= 1 and grade <= 12: program_breakdown[unicode(student.site)]['Grades'] +=1 if grade > 12 and grade < 999: program_breakdown[unicode(student.site)]['Skills'] +=1 total_skills +=1 #clean up students_by_grade_by_site so we're not displaying a bunch of blank data clean_students_by_grade_by_site = dict(students_by_grade_by_site) for key,grade in students_by_grade_by_site.iteritems(): if students_by_grade[key] == 0: del clean_students_by_grade_by_site[key] #find students with unapproved absences and no notes unapproved_absence_no_comment = Attendance.objects.all().filter(attendance__exact="UA").filter(Q(notes=u"") |Q(notes=None)).order_by('-date') context = { 'surveys': surveys, 'females': tot_females, 'breakdown':breakdown, 'program_breakdown':program_breakdown, 'total_skills':total_skills, 'students_by_grade':students_by_grade, 'students_at_gl_by_grade': students_at_gl_by_grade, 'students_by_grade_by_site':clean_students_by_grade_by_site, 'students_at_gl_by_grade_by_site': students_at_gl_by_grade_by_site, 'schools':schools, 'notifications':notifications, 'unenrolled_students':unenrolled_students, 'unapproved_absence_no_comment':unapproved_absence_no_comment} return render(request, 'mande/index.html', context)