示例#1
0
 def test_IntakeSurveyForm_invalid(self):
     data = {
         "date": "2017-01-01",
         "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",
     }
     form = IntakeSurveyForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors, {
             'enrollment_date': [u'This field is required.'],
             'starting_grade': [u'This field is required.']
         })
示例#2
0
文件: surveys.py 项目: rice1got/vdpme
def intake_survey(request,student_id=None):
    next_url = request.GET.get('next') #where we're going next
    limit = request.GET.get('limit') #limit to a single field
    instance = IntakeSurvey.objects.get(pk=student_id) if student_id else None
    form = IntakeSurveyForm(request.POST or None,
                            instance=instance)
    if request.method == 'POST':
        if form.is_valid():
            instance = form.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 for '+unicode(instance.name)
            log = NotificationLog(  user=request.user,
                                    text=message,
                                    font_awesome_icon=icon)
            log.save()
            #then return, defaulting to an intake internal
            if next_url is None:
                next_url = reverse('intake_internal',kwargs={'student_id':instance.student_id})

            return HttpResponseRedirect(next_url)

    context = {'form': form, 'student':instance, 'next_url':next_url, 'limit':limit}
    return render(request, 'mande/intakesurvey.html', context)
示例#3
0
文件: surveys.py 项目: suin-kim/vdpme
def intake_survey(request, student_id=None):
    next_url = request.GET.get("next")  # where we're going next
    limit = request.GET.get("limit")  # limit to a single field
    instance = IntakeSurvey.objects.get(pk=student_id) if student_id else None
    form = IntakeSurveyForm(request.POST or None, instance=instance)
    if request.method == "POST":
        if form.is_valid():
            instance = form.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 for " + unicode(instance.name)
            log = NotificationLog(user=request.user, text=message, font_awesome_icon=icon)
            log.save()
            # then return, defaulting to an intake internal
            if next_url is None:
                next_url = reverse("intake_internal", kwargs={"student_id": instance.student_id})

            return HttpResponseRedirect(next_url)

    context = {"form": form, "student": instance, "next_url": next_url, "limit": limit}
    return render(request, "mande/intakesurvey.html", context)
示例#4
0
def intake_survey(request, student_id=None):
    next_url = request.GET.get('next')  #where we're going next
    limit = request.GET.get('limit')  #limit to a single field
    instance = IntakeSurvey.objects.get(pk=student_id) if student_id else None
    form = IntakeSurveyForm(request.POST or None, instance=instance)
    if request.method == 'POST':
        if form.is_valid():
            instance = form.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 for ' + unicode(instance.name)
            log = NotificationLog(user=request.user,
                                  text=message,
                                  font_awesome_icon=icon)
            log.save()
            #then return, defaulting to an intake internal
            if next_url is None:
                next_url = reverse('intake_internal',
                                   kwargs={'student_id': instance.student_id})

            return HttpResponseRedirect(next_url)

    context = {
        'form': form,
        'student': instance,
        'next_url': next_url,
        'limit': limit
    }
    return render(request, 'mande/intakesurvey.html', context)
示例#5
0
 def test_IntakeSurveyForm_valid(self):
     data = {
         "date": "2017-01-01",
         "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": "2017-01-01",
         "starting_grade": 1
     }
     form = IntakeSurveyForm(data)
     self.assertTrue(form.is_valid())
示例#6
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
示例#7
0
文件: reports.py 项目: rice1got/vdpme
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
    })