Exemple #1
0
def my_scheduled_job():
    print datetime.now()
    try:
        cur_student = CurrentStudentInfo.objects.all()
        cur_student.delete()
        exit_surveys = ExitSurvey.objects.all().filter(
            exit_date__lte=date.today().isoformat()).values_list('student_id',
                                                                 flat=True)
        active_surveys = IntakeSurvey.objects.filter(
            date__lte=date.today().isoformat()).order_by('student_id').exclude(
                student_id__in=exit_surveys)
        for survey in active_surveys:
            recent_survey = survey.getRecentFields()
            student = CurrentStudentInfo(
                student_id=recent_survey['student_id'],
                name=recent_survey['name'],
                site=recent_survey['site'],
                date=recent_survey['date'],
                dob=recent_survey['dob'],
                gender=recent_survey['gender'],
                age_appropriate_grade=survey.age_appropriate_grade(),
                in_public_school=True
                if survey.get_pschool().status == 'Y' else False,
                at_grade_level=studentAtAgeAppropriateGradeLevel(
                    recent_survey['student_id']),
                vdp_grade=survey.current_vdp_grade())
            student.save()
        print 'Success: Deleted: ' + str(
            cur_student.count()) + '. Added: ' + str(
                CurrentStudentInfo.objects.all().count())
    except Exception as e:
        print 'Error:' + str(e)
Exemple #2
0
def student_list(request):
    #get enrolled and accepted students
    exit_surveys = ExitSurvey.objects.all().filter(
        exit_date__lte=TODAY).values_list('student_id', flat=True)
    surveys = IntakeSurvey.objects.order_by('student_id').exclude(
        student_id__in=exit_surveys)
    at_grade_level = {}
    for student in surveys:
        at_grade_level[student.student_id] = (
            studentAtAgeAppropriateGradeLevel(student.student_id))
    context = {'surveys': surveys, 'at_grade_level': at_grade_level}
    return render(request, 'mande/studentlist.html', context)
Exemple #3
0
def student_list(request):
    #get enrolled and accepted students
    exit_surveys = ExitSurvey.objects.all().filter(
                        exit_date__lte=TODAY
                        ).values_list('student_id',flat=True)
    surveys = IntakeSurvey.objects.order_by('student_id'
                                 ).exclude(student_id__in=exit_surveys)
    at_grade_level = {}
    for student in surveys:
            at_grade_level[student.student_id] = (
                            studentAtAgeAppropriateGradeLevel(student.student_id))
    context = {'surveys': surveys, 'at_grade_level':at_grade_level}
    return render(request, 'mande/studentlist.html', context)
Exemple #4
0
def student_list(request):
    #get enrolled and accepted students
    exit_surveys = ExitSurvey.objects.all().filter(
                        exit_date__lte=date.today().isoformat()
                        ).values_list('student_id',flat=True)
    active_surveys = IntakeSurvey.objects.order_by('student_id'
                                 ).exclude(student_id__in=exit_surveys)
    surveys = []
    for active_survey in active_surveys:
        surveys.append(active_survey.getRecentFields())
    at_grade_level = {}
    for student in surveys:
            at_grade_level[student['student_id']] = (
                            studentAtAgeAppropriateGradeLevel(student['student_id']))
    context = {'surveys': surveys, 'at_grade_level':at_grade_level}
    return render(request, 'mande/studentlist.html', context)
Exemple #5
0
def intake_survey(request, student_id=None):
    #get current method name
    method_name = inspect.currentframe().f_code.co_name
    if user_permissions(method_name, request.user):
        next_url = request.GET.get('next')  #where we're going next
        limit = request.GET.get('limit')  #limit to a single field
        intake_surveys = IntakeSurvey.objects.all()
        intake_update = IntakeUpdate.objects.all()
        data_guardian_profession = []
        intake_surveys_guardian1 = list(
            intake_surveys.values_list('guardian1_profession', flat=True))
        intake_surveys_guardian2 = list(
            intake_surveys.values_list('guardian2_profession', flat=True))
        intake_update_guardian1 = list(
            intake_update.values_list('guardian1_profession', flat=True))
        intake_update_guardian2 = list(
            intake_update.values_list('guardian2_profession', flat=True))
        data_guardian_profession.extend(intake_surveys_guardian1)
        data_guardian_profession.extend(intake_surveys_guardian2)
        data_guardian_profession.extend(intake_update_guardian1)
        data_guardian_profession.extend(intake_update_guardian2)
        # sort khmer
        data_guardian_profession = [
            x.encode('utf-8').strip() for x in set(data_guardian_profession)
            if x is not None
        ]
        data_guardian_profession = sorted(set(data_guardian_profession),
                                          key=collator.getSortKey)

        instance = IntakeSurvey.objects.get(
            pk=student_id) if student_id else None
        form = IntakeSurveyForm(request.POST or None, instance=instance)

        if request.method == 'POST':
            enrollment_date = request.POST['enrollment_date']
            starting_grade = request.POST['starting_grade']

            if form.is_valid():
                instance = form.save()
                intake_internal = IntakeInternal(
                    student_id=instance,
                    enrollment_date=enrollment_date,
                    starting_grade=starting_grade)
                intake_internal.save()
                icon = 'fa-female' if instance.gender == 'F' else 'fa-male'
                if student_id:
                    action = 'Updated'
                    if limit:
                        action = action + ' ' + limit + 'on'  #Updated dob on intake...
                else:
                    action = 'Performed'
                message = action + ' intake survey and intake internal for ' + unicode(
                    instance.name)
                log = NotificationLog(user=request.user,
                                      text=message,
                                      font_awesome_icon=icon)
                log.save()
                # update CurrentStudentInfo
                try:
                    obj = CurrentStudentInfo.objects.get(
                        student_id=instance.student_id)
                    obj.name = instance.name
                    obj.site = instance.site
                    obj.date = instance.date
                    obj.dob = instance.dob
                    obj.gender = instance.gender
                    obj.age_appropriate_grade = instance.age_appropriate_grade(
                    )
                    obj.in_public_school = True if instance.get_pschool(
                    ).status == 'Y' else False
                    obj.at_grade_level = studentAtAgeAppropriateGradeLevel(
                        instance.student_id)
                    obj.vdp_grade = instance.current_vdp_grade()
                    obj.save()
                except CurrentStudentInfo.DoesNotExist:
                    obj = CurrentStudentInfo(
                        student_id=instance.student_id,
                        name=instance.name,
                        site=instance.site,
                        date=instance.date,
                        dob=instance.dob,
                        gender=instance.gender,
                        age_appropriate_grade=instance.age_appropriate_grade(),
                        in_public_school=True
                        if instance.get_pschool().status == 'Y' else False,
                        at_grade_level=studentAtAgeAppropriateGradeLevel(
                            instance.student_id),
                        vdp_grade=instance.current_vdp_grade())
                    obj.save()
                #then return, defaulting to an intake internal
                # if next_url is None:
                #     next_url = reverse('intake_internal',kwargs={'student_id':instance.student_id})
                next_url = reverse('student_detail',
                                   kwargs={'student_id': instance.student_id})
                return HttpResponseRedirect(next_url)

        context = {
            'form': form,
            'student': instance,
            'next_url': next_url,
            'limit': limit,
            'data_guardian_profession': json.dumps(data_guardian_profession)
        }
        return render(request, 'mande/intakesurvey.html', context)
    else:
        raise PermissionDenied
Exemple #6
0
def intake_update(request, student_id=0):
    #get current method name
    method_name = inspect.currentframe().f_code.co_name
    if user_permissions(method_name, request.user):
        next_url = request.GET.get('next')
        next_tab = request.GET.get('tab')

        intake_surveys = IntakeSurvey.objects.all()
        intake_update = IntakeUpdate.objects.all()
        data_guardian_profession = []
        intake_surveys_guardian1 = list(
            intake_surveys.values_list('guardian1_profession', flat=True))
        intake_surveys_guardian2 = list(
            intake_surveys.values_list('guardian2_profession', flat=True))
        intake_update_guardian1 = list(
            intake_update.values_list('guardian1_profession', flat=True))
        intake_update_guardian2 = list(
            intake_update.values_list('guardian2_profession', flat=True))
        data_guardian_profession.extend(intake_surveys_guardian1)
        data_guardian_profession.extend(intake_surveys_guardian2)
        data_guardian_profession.extend(intake_update_guardian1)
        data_guardian_profession.extend(intake_update_guardian2)
        # sort khmer
        data_guardian_profession = [
            x.encode('utf-8').strip() for x in set(data_guardian_profession)
            if x is not None
        ]
        data_guardian_profession = sorted(set(data_guardian_profession),
                                          key=collator.getSortKey)

        try:
            survey = IntakeSurvey.objects.get(pk=student_id)
            most_recent = survey.getRecentFields()
        except ObjectDoesNotExist:
            survey = None
            most_recent = {}

        if request.method == 'POST':
            initial_grade_current = request.POST.get('initial_grade_current')
            initial_public_school_name = request.POST.get(
                'initial_school_name')

            form = IntakeUpdateForm(request.POST)
            if form.is_valid():
                instance = form.save()
                message = 'Updated ' + unicode(
                    instance.student_id.name) + '\'s record'
                log = NotificationLog(user=request.user,
                                      text=message,
                                      font_awesome_icon='fa-upload')
                log.save()
                # update cache table
                student = IntakeSurvey.objects.get(
                    student_id=instance.student_id.student_id)
                current = student.getRecentFields()
                try:
                    update_student = CurrentStudentInfo.objects.get(
                        student_id=student.student_id)
                    update_student.name = current['name']
                    update_student.site = current['site']
                    update_student.date = current['date']
                    update_student.dob = current['dob']
                    update_student.gender = current['gender']
                    update_student.age_appropriate_grade = student.age_appropriate_grade(
                    )
                    update_student.in_public_school = True if student.get_pschool(
                    ).status == 'Y' else False
                    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()
                except:
                    pass
                #then return
                return HttpResponseRedirect(next_url + '#' + next_tab)
        else:
            #change the date today, for convenience
            most_recent['date'] = date.today().isoformat()
            form = IntakeUpdateForm(most_recent)

        context = {
            'form': form,
            'survey': survey,
            'student_id': student_id,
            'next': next_url,
            'tab': next_tab,
            'data_guardian_profession': json.dumps(data_guardian_profession)
        }
        return render(request, 'mande/intakeupdate.html', context)
    else:
        raise PermissionDenied
Exemple #7
0
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
Exemple #8
0
def academic_form(request,
                  school_id,
                  test_date=date.today().isoformat(),
                  classroom_id=None):
    #get current method name
    method_name = inspect.currentframe().f_code.co_name
    if user_permissions(method_name, request.user):
        classroom = Classroom.objects.get(pk=classroom_id)
        warning = ''
        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
        #find only currently enrolled students
        exit_surveys = ExitSurvey.objects.all().filter(
            exit_date__lte=date.today().isoformat()).values_list('student_id',
                                                                 flat=True)
        students = ClassroomEnrollment.objects.exclude(
            student_id__in=exit_surveys).exclude(
                drop_date__lt=date.today().isoformat()).filter(
                    classroom_id=classroom_id,
                    student_id__date__lte=date.today().isoformat())

        # find out if any student acadmics have been recorded
        student_academics = Academic.objects.filter(
            student_id__in=students.values_list('student_id'),
            test_date=test_date)
        #pre instantiate data for this form so that we can update the whole queryset later
        for student in students:
            Academic.objects.get_or_create(
                student_id=student.student_id,
                test_date=test_date,
                test_level=student.classroom_id.cohort)

        try:
            student_academics = Academic.objects.filter(
                student_id__in=students.values_list('student_id'),
                test_date=test_date,
                test_level=student.classroom_id.cohort)
        except Exception as e:
            student_academics = Academic.objects.filter(
                student_id__in=students.values_list('student_id'),
                test_date=test_date,
                test_level=classroom.cohort)
        AcademicFormSet = modelformset_factory(Academic,
                                               form=AcademicForm,
                                               extra=0)

        if request.method == 'POST':
            formset = AcademicFormSet(request.POST)

            if formset.is_valid():
                period = AcademicMarkingPeriod.objects.all().filter(
                    test_date=test_date)
                if len(period) >= 1:
                    instances = formset.save()
                    message = "Saved."
                    message = ('Recorded semester tests for ' +
                               str(classroom.get_cohort_display()) + ' - ' +
                               str(classroom.classroom_number) + ' at ' +
                               str(classroom.school_id))
                    log = NotificationLog(user=request.user,
                                          text=message,
                                          font_awesome_icon='fa-calculator')
                    log.save()
                    for academic in instances:
                        # update cache table
                        student = IntakeSurvey.objects.get(
                            student_id=academic.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()
                else:
                    warning = "Test date doesn't match with AcademicMarkingPeriod date."
        else:
            formset = AcademicFormSet(queryset=student_academics)
        context = {
            'classroom':
            classroom,
            'classrooms_by_school':
            Classroom.objects.filter(school_id=school_id, cohort__lt=50),
            'students':
            students,
            'test_date':
            test_date,
            'formset':
            formset,
            'warning':
            mark_safe(warning),
            'message':
            message,
            'locked':
            locked,
        }

        return render(request, 'mande/academicform.html', context)
    else:
        raise PermissionDenied
Exemple #9
0
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)
Exemple #10
0
    def test_context_post_create(self):
        enrollment_date = "2017-01-01"
        starting_grade = 1
        today = date.today().isoformat()
        data = {
            "date": today,
            "site": 1,
            "dob": "2000-01-01",
            "name": "abc",
            "gender": "F",
            "guardian1_name": "abc",
            "guardian1_relationship": "FATHER",
            "guardian1_phone": "00000",
            "guardian1_profession": "test",
            "guardian1_employment": 1,
            "minors": 0,
            "minors_in_public_school": 0,
            "minors_in_other_school": 0,
            "address": "test",
            "notes": "test",
            "enrollment_date": enrollment_date,
            "starting_grade": starting_grade
        }
        url = reverse('intake_survey', kwargs={})
        resp = self.client.post(url, data)
        instance = IntakeSurvey.objects.get(date=date.today().isoformat())
        self.assertRedirects(resp,
                             expected_url=reverse(
                                 'student_detail',
                                 kwargs={'student_id': instance.student_id}),
                             status_code=302,
                             target_status_code=200)
        self.assertEqual(IntakeSurvey.objects.all().count(), 12)
        self.assertEqual(NotificationLog.objects.all().count(), 2)
        self.assertEqual(IntakeInternal.objects.all().count(), 9)
        self.assertEqual(CurrentStudentInfo.objects.all().count(), 10)
        self.assertTrue(
            IntakeInternal.objects.filter(
                student_id=instance,
                enrollment_date=enrollment_date,
                starting_grade=starting_grade).exists())

        message = 'Performed intake survey and intake internal for ' + unicode(
            instance.name)
        self.assertTrue(
            NotificationLog.objects.filter(
                text=message,
                font_awesome_icon='fa-female',
                user=self.client.session['_auth_user_id']).exists())
        self.assertTrue(
            CurrentStudentInfo.objects.filter(
                student_id=instance.student_id,
                name=instance.name,
                site=instance.site,
                date=instance.date,
                dob=instance.dob,
                gender=instance.gender,
                age_appropriate_grade=instance.age_appropriate_grade(),
                in_public_school=True
                if instance.get_pschool().status == 'Y' else False,
                at_grade_level=studentAtAgeAppropriateGradeLevel(
                    instance.student_id),
                vdp_grade=instance.current_vdp_grade(),
                refresh=date.today().isoformat(),
            ).exists())
Exemple #11
0
 def setUp(self):
     self.client = Client()
     self.client.login(username='******', password='******')
     #generate a student who is at grade level no matter what grade they're in
     glstudent = IntakeSurvey.objects.create(
         minors_training="NA",
         minors=0,
         minors_in_public_school=0,
         site=School.objects.get(pk=1),
         grade_appropriate=1,
         guardian2_relationship="MOTHER",
         minors_in_other_school=0,
         guardian1_phone="123",
         guardian2_phone="",
         guardian1_relationship="FATHER",
         guardian1_profession="123",
         minors_working=0,
         guardian2_profession="NA",
         address="123",
         date="2005-07-01",
         guardian2_name="",
         minors_encouraged="NA",
         name="GeneratedStudent",
         guardian2_employment="1",
         dob=str(date.today().year) + "-07-01",
         gender="M",
         minors_profession="",
         guardian1_name="123",
         minors_training_type="",
         guardian1_employment="1",
         notes="")
     IntakeInternal.objects.create(student_id=glstudent,
                                   enrollment_date=date.today(),
                                   starting_grade='6')
     recent_survey = glstudent.getRecentFields()
     intake = IntakeSurvey.objects.get(student_id=glstudent.student_id)
     CurrentStudentInfo.objects.create(
         student_id=recent_survey['student_id'],
         name=recent_survey['name'],
         site=recent_survey['site'],
         date=recent_survey['date'],
         dob=recent_survey['dob'],
         gender=recent_survey['gender'],
         age_appropriate_grade=intake.age_appropriate_grade(),
         in_public_school=True
         if intake.get_pschool().status == 'Y' else False,
         at_grade_level=studentAtAgeAppropriateGradeLevel(
             recent_survey['student_id']),
         vdp_grade=intake.current_vdp_grade())
     # unapproved_absence_no_comment
     today = date.today()
     if (today < datetime.strptime(str(today.year) + "-08-01",
                                   "%Y-%m-%d").date()):
         school_year = today.year - 1
     else:
         school_year = today.year
     school_year_start_date = str(school_year) + "-08-01"
     school_year_end_date = str(school_year + 1) + "-07-31"
     Attendance.objects.create(
         student_id=IntakeSurvey.objects.get(pk=1),
         classroom=Classroom.objects.get(pk=1),
         date=str(school_year) + "-08-01",
         attendance="UA",
     )
Exemple #12
0
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)