Esempio n. 1
0
 def create_iip_evaluations(self, request, object_id):
     redirect_url = urlresolvers.reverse('admin:courseevaluations_evaluationset_change', args=(object_id, ))
     
     if not request.user.has_perm('courseevaluations.add_iipevaluation'):
         messages.error(request, "You do not have the appropriate permissions to add IIP evaluations")
         return redirect(redirect_url)
     
     if request.method != 'POST':
         messages.error(request, "Invalid request, please try again. No evaluations created.")
         return redirect(redirect_url)
     
     question_set_id = request.POST.get("question_set_id")
     
     if not question_set_id:
         messages.error(request, "Question set is required. No evaluations created.")
         return redirect(redirect_url)
     
     iip_evaluation_file = request.FILES.get('iip_evaluation_file')
     
     if not iip_evaluation_file:
         messages.error(request, "IIP evaluation file is required. No evaluations created.")
         return redirect(redirect_url)
         
     data = fmpxmlparser.parse_from_file(iip_evaluation_file)
     results = data['results']
     
     creation_count = 0
     
     with transaction.atomic():
         question_set = get_object_or_404(QuestionSet, pk=question_set_id)
         evaluation_set = get_object_or_404(EvaluationSet, pk=object_id)
         academic_year = AcademicYear.objects.current()
         
         for row in results:
             fields = row['parsed_fields']
             
             student_id = fields['IDStudent']
             teacher_id = fields['SectionTeacher::IDTEACHER']
             
             student = Student.objects.get(student_id=student_id)
             teacher = Teacher.objects.get(teacher_id=teacher_id)
             enrollment = Enrollment.objects.get(student=student, academic_year=academic_year)
             
             evaluable = IIPEvaluation()
             evaluable.student = student
             evaluable.teacher = teacher
             evaluable.evaluation_set = evaluation_set
             evaluable.question_set = question_set
             evaluable.enrollment = enrollment
             
             evaluable.save()
             
             creation_count += 1
     
     messages.add_message(request, messages.SUCCESS, "Successfully created {count:} IIP evaluations".format(count=creation_count))
     return redirect(redirect_url)
Esempio n. 2
0
 def create_course_evaluations(self, request, object_id):
     redirect_url = urlresolvers.reverse('admin:courseevaluations_evaluationset_change', args=(object_id, ))
     
     if not request.user.has_perm('courseevaluations.add_courseevaluation'):
         messages.error(request, "You do not have the appropriate permissions to add course evaluations")
         return redirect(redirect_url)
     
     if request.method != 'POST':
         messages.error(request, "Invalid request, please try again. No evaluations created.")
         return redirect(redirect_url)
     
     question_set_id = request.POST.get("question_set_id")
     
     if not question_set_id:
         messages.error(request, "Question set is required. No evaluations created.")
         return redirect(redirect_url)
     
     course_evaluation_file = request.FILES.get('course_evaluation_file')
     
     if not course_evaluation_file:
         messages.error(request, "Course evaluation file is required. No evaluations created.")
         return redirect(redirect_url)
         
     data = fmpxmlparser.parse_from_file(course_evaluation_file)
     results = data['results']
     
     creation_count = 0
     
     with transaction.atomic():
         question_set = get_object_or_404(QuestionSet, pk=question_set_id)
         evaluation_set = get_object_or_404(EvaluationSet, pk=object_id)
         
         for row in results:
             fields = row['parsed_fields']
             
             csn = fields['CourseSectionNumber']
             academic_year = fields['AcademicYear']
             
             section = Section.objects.get(csn=csn, academic_year__year=academic_year)
             
             for student in section.students.all():
                 enrollment = Enrollment.objects.get(student=student, academic_year__year=academic_year)
                 
                 evaluable = CourseEvaluation()
                 evaluable.student = student
                 evaluable.enrollment = enrollment
                 evaluable.section = section
                 evaluable.question_set = question_set
                 evaluable.evaluation_set = evaluation_set
                 evaluable.save()
                 
                 creation_count += 1
     
     messages.add_message(request, messages.SUCCESS, "Successfully created {count:} course evaluations".format(count=creation_count))
     return redirect(redirect_url)
Esempio n. 3
0
    def handle(self, *args, **kwargs):
        logger.info("Beginning course import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        seen_ids = set()
        
        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']
                
                course_number = fields['CourseNumber']
                course_name = fields['CourseName'] or ""
                course_name_short = fields["CourseNameShort"] or ""
                course_name_transcript = fields["CourseNameTranscript"] or ""
                division = fields["Division"] or ""
                grade_level = fields["GradeLevel"] or ""
                department = fields["DepartmentName"] or ""
                course_type = fields["CourseType"] or ""
                
                if not course_number:
                    continue
                
                seen_ids.add(course_number)
                
                try:
                    course = Course.objects.get(number=course_number)
                    logger.info("Found course {number:}".format(number=course_number))
                    forceSave = False
                    
                except Course.DoesNotExist:
                    course = Course(number=course_number)
                    logger.info("Creating course {number:}".format(number=course_number))
                    forceSave = True
                    
                attrMap = {
                    'course_name': course_name,
                    'course_name_short': course_name_short,
                    'course_name_transcript': course_name_transcript,
                    'division': division,
                    'grade_level': grade_level,
                    'department': department,
                    'course_type': course_type,
                }
                
                for attr in attrMap:
                    dbValue = getattr(course, attr)
                    
                    if dbValue != attrMap[attr]:
                        setattr(course, attr, attrMap[attr])
                        logger.info("Updating {attr:} on {course:} from {oldValue:} to {newValue:}".format(attr=attr, course=course_number, oldValue=dbValue, newValue=attrMap[attr]))
                        forceSave = True
                    
                if forceSave:
                    course.save()
                    
            extra_courses = Course.objects.exclude(number__in=seen_ids)
            for extra_course in extra_courses:
                logger.warn("Deleting extra course {}".format(extra_course.id))
                extra_course.delete()
    def handle(self, *args, **kwargs):
        logger.info("Beginning section import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        seen_ids = set()
        
        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']
                
                course_number = fields['CourseNumber']
                csn = fields['CourseSectionNumber']
                academic_year = fields["AcademicYear"]
                teacher_id = fields["IDTeacher"]
                course_name = fields["CourseName"]
                
                if not course_number or not csn or not academic_year:
                    continue
                
                try:
                    course = Course.objects.get(number=course_number)
                    logger.info("Found course {number:}".format(number=course_number))
                    forceSave = False
                    
                except Course.DoesNotExist:
                    logger.error("Course {course:} is in sections but not courses".format(course=course_number))
                    continue
                
                try:
                    academic_year = AcademicYear.objects.get(year=academic_year)
                except AcademicYear.DoesNotExist:
                    academic_year = AcademicYear(year=academic_year)
                    academic_year.save()
                
                try:
                    section = Section.objects.get(course=course, academic_year=academic_year, csn=csn)
                    logger.info("Found section {csn:} for {academic_year:}".format(csn=csn, academic_year=academic_year))

                except Section.DoesNotExist:
                    logger.info("Creating section {csn:} for {academic_year:}".format(csn=csn, academic_year=academic_year))
                    section = Section(course=course, academic_year=academic_year, csn=csn)
                    section.save()
                
                teacher = None
                
                if teacher_id:
                    try:
                        teacher = Teacher.objects.get(teacher_id=teacher_id)
                    except Teacher.DoesNotExist:
                        logger.error("Teacher {id:} is in sections but not in teachers".format(id=teacher_id))
                    
                attrMap = {
                    'teacher': teacher,
                    'course_name': course_name,
                }
                
                for attr in attrMap:
                    dbValue = getattr(section, attr)
                    
                    if dbValue != attrMap[attr]:
                        setattr(section, attr, attrMap[attr])
                        logger.info("Updating {attr:} on {course:} from {oldValue:} to {newValue:}".format(attr=attr, course=course_number, oldValue=dbValue, newValue=attrMap[attr]))
                        forceSave = True
                    
                if forceSave:
                    section.save()
            
            #TODO: Delete extra sessions
    def handle(self, *args, **kwargs):
        logger.info("Beginning detention import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        seen_ids = set()
        
        with transaction.atomic():
            detention_mailer = DetentionMailer.objects.get()
            skip_processing_before = detention_mailer.skip_processing_before
            
            for row in results:
                fields = row['parsed_fields']
                
                incident_id = fields['IDINCIDENT']
                detention_date = fields['Det Date']
                raw_code = fields['Code'] or ""
                raw_offense = fields['Offense']
                comments = fields['Comments'] or ""
                student_id = fields['IDSTUDENT']
                teacher_id = fields['KSTeachers::IDTEACHER']
                raw_academic_year = fields['AcademicYear']
                raw_term = fields['Term']
                
                if skip_processing_before and detention_date < skip_processing_before:
                    continue
                
                try:
                    code = Code.objects.get(code=raw_code)
                except Code.DoesNotExist:
                    code = Code(code=raw_code)
                    code.save()
                
                if not code.process:
                    continue
                
                try:
                    academic_year = AcademicYear.objects.get(year=raw_academic_year)
                except AcademicYear.DoesNotExist:
                    academic_year = AcademicYear(year=raw_academic_year)
                    academic_year.save()
                
                try:
                    term = Term.objects.get(academic_year=academic_year, term=raw_term)
                except Term.DoesNotExist:
                    term = Term(academic_year=academic_year, term=raw_term)
                    term.save()
                
                if raw_offense:
                    try:
                        offense = Offense.objects.get(offense__iexact=raw_offense)
                    except Offense.DoesNotExist:
                        error_recipients = [o.address for o in DetentionErrorNotification.objects.filter(mailer=detention_mailer)]
                    
                        if not error_recipients:
                            raise ValueError("No error recipients are defined")
                    
                        send_mail("Error importing detention", "Error importing detention {id:}: offense '{offense:}' does not exist".format(
                            id=incident_id, offense=raw_offense), '*****@*****.**', error_recipients)
                    
                        continue
                else:
                    offense = None
                
                if teacher_id:
                    teacher = Teacher.objects.get(teacher_id=teacher_id)
                else:
                    teacher = None
                    
                
                if student_id:
                    student = Student.objects.get(student_id=student_id)
                else:
                    student = None
                
                if not incident_id:
                    logger.error("Blank incident ID")
                    continue
                
                seen_ids.add(incident_id)
                
                try:
                    incident = Detention.objects.get(incident_id=incident_id)
                    logger.info("Found detention {id:}".format(id=incident_id))
                    force_save = False
                    
                except Detention.DoesNotExist:
                    logger.info("Creating detention {id:}".format(id=incident_id))
                    incident = Detention(
                                        incident_id=incident_id,
                                        code=code,
                                        student=student,
                                        teacher=teacher
                                        )
                    force_save = True
                    
                attr_map = {
                    'detention_date': detention_date,
                    'code': code,
                    'offense': offense,
                    'comments': comments,
                    'term': term,
                    'student': student,
                    'teacher': teacher,
                }
                
                for attr in attr_map:
                    db_value = getattr(incident, attr)
                    
                    if db_value != attr_map[attr]:
                        setattr(incident, attr, attr_map[attr])
                        logger.info("Updating {attr:} on {incident_id:} from {old_value:} to {new_value:}".format(
                            attr=attr, incident_id=incident_id, old_value=db_value, new_value=attr_map[attr]))
                        force_save = True
                    
                if force_save:
                    incident.save()
                
            
            extra_detentions = Detention.objects.exclude(incident_id__in=seen_ids)
            if extra_detentions:
                logger.warn("Deleting {} detentions".format(extra_detentions.count()))
                extra_detentions.delete()
    def handle(self, *args, **kwargs):
        logger.info("Beginning enrollment import routine")

        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']

        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']

                studentID = fields['IDStudent']
                academicYear = fields['AcademicYear']
                boarderDay = fields['BoarderDay']
                dormName = fields['DormName'] or ""
                grade_code = fields['Grade']
                division = fields['Division'] or ""
                section = fields["Section Letter"] or ""
                advisorID = fields["IDAdvisor"]
                statusEnrollment = fields["StatusEnrollment"] or ""
                statusAttending = fields["StatusAttending"] or ""
                enrolledDate = fields["EnrollmentDate"]

                if not studentID or not academicYear:
                    continue

                try:
                    academicYear = AcademicYear.objects.get(year=academicYear)
                except AcademicYear.DoesNotExist:
                    academicYear = AcademicYear(year=academicYear)
                    academicYear.save()

                try:
                    student = Student.objects.get(student_id=studentID)
                except Student.DoesNotExist:
                    logger.error(
                        "Student {studentID:} is in enrollments but not in permrecs"
                        .format(studentID=studentID))
                    continue

                if boarderDay and boarderDay.upper() == "B":
                    boarder = True
                else:
                    boarder = False

                if dormName:
                    try:
                        dorm = Dorm.objects.get(dorm_name=dormName)
                    except Dorm.DoesNotExist:
                        logger.error("Dorm {dorm:} does not exist".format(
                            dorm=dormName))
                        dorm = None
                else:
                    dorm = None

                if advisorID:
                    try:
                        advisor = Teacher.objects.get(teacher_id=advisorID)
                    except Teacher.DoesNotExist:
                        logger.error(
                            "Advisor {advisorID:} does not exist".format(
                                advisorID=advisorID))
                        advisor = None
                else:
                    advisor = None

                if grade_code:
                    try:
                        grade = Grade.objects.get(grade=grade_code)
                    except Grade.DoesNotExist:
                        grade = Grade()
                        grade.grade = grade_code
                        grade.description = "Grade {grade:}".format(
                            grade=grade_code)
                        grade.save()

                try:
                    enrollment = Enrollment.objects.get(
                        student=student, academic_year=academicYear)
                    logger.info(
                        "Found enrollment {studentID:}/{academicYear:}".format(
                            studentID=studentID, academicYear=academicYear))
                    forceSave = False

                except Enrollment.DoesNotExist:
                    logger.info(
                        "Creating enrollment {studentID:}/{academicYear:}".
                        format(studentID=studentID, academicYear=academicYear))
                    enrollment = Enrollment()
                    enrollment.student = student
                    enrollment.academic_year = academicYear
                    forceSave = True

                attrMap = {
                    'boarder': boarder,
                    'dorm': dorm,
                    'grade': grade,
                    'division': division,
                    'section': section,
                    'advisor': advisor,
                    'status_enrollment': statusEnrollment,
                    'status_attending': statusAttending,
                    'enrolled_date': enrolledDate
                }

                for attr in attrMap:
                    dbValue = getattr(enrollment, attr)

                    if dbValue != attrMap[attr]:
                        setattr(enrollment, attr, attrMap[attr])
                        logger.info(
                            "Updating {attr:} on {studentID:}/{academicYear:} from {oldValue:} to {newValue:}"
                            .format(attr=attr,
                                    studentID=studentID,
                                    academicYear=academicYear,
                                    oldValue=dbValue,
                                    newValue=attrMap[attr]))
                        forceSave = True

                if forceSave:
                    enrollment.save()
    def handle(self, *args, **kwargs):
        logger.info("Beginning student import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        seen_ids = set()
        
        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']
                
                nameFirst = fields['NameFirst'] or ""
                nameLast = fields['NameLast'] or ""
                nameNickname = fields['NameNickname'] or ""
                email = fields['EMailSchool'] or ""
                studentID = fields['IDSTUDENT']
                password = fields["PasswordActiveDirctory"] or ""
                username = fields["Network_User_Name"] or ""
                gender = fields["Sex"] or ""
                
                if not studentID:
                    continue
                
                seen_ids.add(studentID)
                
                if username:
                    if len(username) > 20:
                        username = username[0:20]
                        logger.warn("Username {username:} was truncated to 20 characters".format(username=username))
                
                if email:
                    validEmail = validate_email(email)
                
                    if not validEmail:
                        email = ""
                        logger.warn("E-mail address {email:} for {id:} ({first:} {last:}) is invalid; address blanked".format(email=email, id=studentID, first=nameFirst, last=nameLast))
                
                try:
                    student = Student.objects.get(student_id=studentID)
                    logger.info("Found student {studentID:}".format(studentID=studentID))
                    forceSave = False
                    
                except Student.DoesNotExist:
                    student = Student(student_id=studentID)
                    logger.info("Creating student {studentID:}".format(studentID=studentID))
                    forceSave = True
                    
                attrMap = {
                    'first_name': nameFirst,
                    'last_name': nameLast,
                    'nickname': nameNickname,
                    'email': email,
                    'rectory_password': password,
                    'username': username,
                    'gender': gender,
                }
                
                for attr in attrMap:
                    dbValue = getattr(student, attr)
                    
                    if dbValue != attrMap[attr]:
                        setattr(student, attr, attrMap[attr])
                        logger.info("Updating {attr:} on {studentID:} from {oldValue:} to {newValue:}".format(attr=attr, studentID=studentID, oldValue=dbValue, newValue=attrMap[attr]))
                        forceSave = True
                    
                if forceSave:
                    student.save()
                
                self.sync_relations(student, fields)
                    
            extra_students = Student.objects.exclude(student_id__in=seen_ids)
            for extra_student in extra_students:
                logger.warn("Deleting extra student {}".format(extra_student.id))
                extra_student.delete()
Esempio n. 8
0
    def handle(self, *args, **kwargs):
        logger.info("Beginning family import routine")

        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']

        seen_ids = set()

        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']

                family_id = fields["IDFAMILY"]

                parents = {}

                address = fields['P_address_full'] or ""
                address_lines = address.splitlines()
                address = "\n".join([line.strip() for line in address_lines])

                parent_attr_map = {
                    'Pa': {
                        'first_name': (fields['Pa_first'] or "").strip(),
                        'last_name': (fields['Pa_last'] or "").strip(),
                        'email': (fields['Pa_email'] or "").strip(),
                        'phone_home': (fields['P_phone_H'] or "").strip(),
                        'phone_work': (fields['Pa_phone_W'] or "").strip(),
                        'phone_cell': (fields['Pa_phone_cell'] or "").strip(),
                        'address': address,
                        'family_id': family_id,
                        'parent_id': 'Pa',
                    },
                    'Pb': {
                        'first_name': (fields['Pb_first'] or "").strip(),
                        'last_name': (fields['Pb_last'] or "").strip(),
                        'email': (fields['Pb_email'] or "").strip(),
                        'phone_home': (fields['P_phone_H'] or "").strip(),
                        'phone_work': (fields['Pb_phone_W'] or "").strip(),
                        'phone_cell': (fields['Pb_phone_cell'] or "").strip(),
                        'address': address,
                        'family_id': family_id,
                        'parent_id': 'Pa',
                    }
                }

                for parent_code, parent_attrs in parent_attr_map.items():
                    full_id = family_id + parent_code
                    seen_ids.add(full_id)

                    do_save = False

                    if not (parent_attrs['first_name']
                            and parent_attrs['last_name']):
                        #First and last name is the criteria for me to import
                        continue

                    try:
                        parent = Parent.objects.get(full_id=full_id)
                    except Parent.DoesNotExist:
                        logger.info("Creating parent {parent_id:}".format(
                            parent_id=full_id))

                        do_save = True
                        parent = Parent()
                        parent.full_id = full_id

                    for attr, desired_value in parent_attrs.items():
                        db_value = getattr(parent, attr)
                        if db_value != desired_value:
                            logger.info(
                                "Updating {attr:} on {parent_id:} from {db_value} to {desired_value:}"
                                .format(attr=attr,
                                        parent_id=full_id,
                                        db_value=db_value,
                                        desired_value=desired_value))
                            do_save = True
                            setattr(parent, attr, desired_value)

                    if do_save:
                        parent.save()

            extra_parents = Parent.objects.exclude(full_id__in=seen_ids)
            for extra_parent in extra_parents:
                logger.warn("Deleting extra parent {}".format(extra_parent.id))
                extra_parent.delete()
    def handle(self, *args, **kwargs):
        logger.info("Beginning student registration import routine")

        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']

        seen_ids = set()

        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']

                csn = fields['CSN']
                academic_year = fields["AcademicYear"]
                student_id = fields["IDStudent"]
                student_reg_id = fields["IDSTUDENTREG"]

                if not csn or not academic_year or not student_id or not student_reg_id:
                    continue

                try:
                    academic_year = AcademicYear.objects.get(
                        year=academic_year)
                except AcademicYear.DoesNotExist:
                    academic_year = AcademicYear(year=academic_year)
                    academic_year.save()

                try:
                    section = Section.objects.get(csn=csn,
                                                  academic_year=academic_year)
                except Section.DoesNotExist:
                    logger.error(
                        "Section {csn:}/{year:} is in studentreg but not in sections"
                        .format(csn=csn, year=academic_year))
                    continue

                try:
                    student = Student.objects.get(student_id=student_id)
                except Student.DoesNotExist:
                    logger.error(
                        "Student {id:} is in studentreg but not in students".
                        format(id=student_id))
                    continue

                try:
                    student_registration = StudentRegistration.objects.get(
                        student_reg_id=student_reg_id)
                    logger.info("Found student registration {id:}".format(
                        id=student_reg_id))
                    forceSave = False

                except StudentRegistration.DoesNotExist:
                    student_registration = StudentRegistration(
                        student_reg_id=student_reg_id,
                        section=section,
                        student=student)
                    forceSave = True

                attrMap = {'student': student, 'section': section}

                for attr in attrMap:
                    dbValue = getattr(student_registration, attr)

                    if dbValue != attrMap[attr]:
                        setattr(student_registration, attr, attrMap[attr])
                        logger.info(
                            "Updating {attr:} on {student_registration:} from {oldValue:} to {newValue:}"
                            .format(attr=attr,
                                    student_registration=student_registration.
                                    student_reg_id,
                                    oldValue=dbValue,
                                    newValue=attrMap[attr]))
                        forceSave = True

                seen_ids.add(student_reg_id)

                if forceSave:
                    student_registration.save()

            extra_student_registrations = StudentRegistration.objects.exclude(
                student_reg_id__in=seen_ids)
            for extra_student_registration in extra_student_registrations:
                logger.warn("Deleting extra student registration {}".format(
                    extra_student_registration.student_reg_id))
                extra_student_registration.delete()
Esempio n. 10
0
    def create_course_evaluations(self, request, object_id):
        redirect_url = urlresolvers.reverse(
            'admin:courseevaluations_evaluationset_change', args=(object_id, ))

        if not request.user.has_perm('courseevaluations.add_courseevaluation'):
            messages.error(
                request,
                "You do not have the appropriate permissions to add course evaluations"
            )
            return redirect(redirect_url)

        if request.method != 'POST':
            messages.error(
                request,
                "Invalid request, please try again. No evaluations created.")
            return redirect(redirect_url)

        question_set_id = request.POST.get("question_set_id")

        if not question_set_id:
            messages.error(
                request, "Question set is required. No evaluations created.")
            return redirect(redirect_url)

        course_evaluation_file = request.FILES.get('course_evaluation_file')

        if not course_evaluation_file:
            messages.error(
                request,
                "Course evaluation file is required. No evaluations created.")
            return redirect(redirect_url)

        data = fmpxmlparser.parse_from_file(course_evaluation_file)
        results = data['results']

        creation_count = 0

        with transaction.atomic():
            question_set = get_object_or_404(QuestionSet, pk=question_set_id)
            evaluation_set = get_object_or_404(EvaluationSet, pk=object_id)

            for row in results:
                fields = row['parsed_fields']

                csn = fields['CourseSectionNumber']
                academic_year = fields['AcademicYear']

                section = Section.objects.get(
                    csn=csn, academic_year__year=academic_year)

                for student in section.students.all():
                    enrollment = Enrollment.objects.get(
                        student=student, academic_year__year=academic_year)

                    evaluable = CourseEvaluation()
                    evaluable.student = student
                    evaluable.enrollment = enrollment
                    evaluable.section = section
                    evaluable.question_set = question_set
                    evaluable.evaluation_set = evaluation_set
                    evaluable.save()

                    creation_count += 1

        messages.add_message(
            request, messages.SUCCESS,
            "Successfully created {count:} course evaluations".format(
                count=creation_count))
        return redirect(redirect_url)
    def handle(self, *args, **kwargs):
        logger.info("Beginning teacher import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results'] 
           
        seen_ids = set()
        
        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']
                
                nameFirst = fields['NameFirst'] or ""
                nameLast = fields['NameLast'] or ""
                namePrefix = fields['NamePrefix'] or ""
                email = fields['EmailSchool'] or ""
                activeEmployee = fields['Active Employee'] or ""
                uniqueName = fields['NameUnique'] or ""
                teacherID = fields['IDTEACHER']
                
                defaultEnrichmentRoom = fields["Enrichment Meeting Room"] or ""
                defaultEnrichmentDescription = fields["Enrichment_Description"] or ""
                
                # Preprocess the default enrichment room to be empty
                # if the employee no longer works here
                if not activeEmployee:
                    defaultEnrichmentRoom = ""
                
                if not teacherID:
                    continue
                
                seen_ids.add(teacherID)
                
                if activeEmployee in ("1", 1):
                    activeEmployee = True
                else:
                    activeEmployee = False
                
                if email:
                    validEmail = validate_email(email)
                
                    if not validEmail:
                        email = ""
                        logger.warn("E-mail address {email:} for {id:} ({first:} {last:}) is invalid; address blanked".format(email=email, id=teacherID, first=firstName, last=lastName))
                
                try:
                    teacher = Teacher.objects.get(teacher_id=teacherID)
                    logger.info("Found teacher {teacherID:}".format(teacherID=teacherID))
                    forceSave = False
                    
                except Teacher.DoesNotExist:
                    teacher = Teacher(teacher_id=teacherID)
                    logger.info("Creating teacher {teacherID:}".format(teacherID=teacherID))
                    forceSave = True
                    
                attrMap = {
                    'first_name': nameFirst,
                    'last_name': nameLast,
                    'prefix': namePrefix,
                    'email': email,
                    'active': activeEmployee,
                    'unique_name': uniqueName,
                    'default_enrichment_room': defaultEnrichmentRoom,
                    'default_enrichment_description': defaultEnrichmentDescription,
                }
                
                for attr in attrMap:
                    dbValue = getattr(teacher, attr)
                    
                    if dbValue != attrMap[attr]:
                        setattr(teacher, attr, attrMap[attr])
                        logger.info("Updating {attr:} on {teacherID:} from {oldValue:} to {newValue:}".format(attr=attr, teacherID=teacherID, oldValue=dbValue, newValue=attrMap[attr]))
                        forceSave = True
                    
                if forceSave:
                    teacher.save()
            
            extra_teachers = Teacher.objects.exclude(teacher_id__in=seen_ids)
            for extra_teacher in extra_teachers:
                logger.warn("Deleting extra teacher {}".format(extra_teacher.id))
                extra_teacher.delete()
Esempio n. 12
0
    def create_iip_evaluations(self, request, object_id):
        redirect_url = urlresolvers.reverse(
            'admin:courseevaluations_evaluationset_change', args=(object_id, ))

        if not request.user.has_perm('courseevaluations.add_iipevaluation'):
            messages.error(
                request,
                "You do not have the appropriate permissions to add IIP evaluations"
            )
            return redirect(redirect_url)

        if request.method != 'POST':
            messages.error(
                request,
                "Invalid request, please try again. No evaluations created.")
            return redirect(redirect_url)

        question_set_id = request.POST.get("question_set_id")

        if not question_set_id:
            messages.error(
                request, "Question set is required. No evaluations created.")
            return redirect(redirect_url)

        iip_evaluation_file = request.FILES.get('iip_evaluation_file')

        if not iip_evaluation_file:
            messages.error(
                request,
                "IIP evaluation file is required. No evaluations created.")
            return redirect(redirect_url)

        data = fmpxmlparser.parse_from_file(iip_evaluation_file)
        results = data['results']

        creation_count = 0

        with transaction.atomic():
            question_set = get_object_or_404(QuestionSet, pk=question_set_id)
            evaluation_set = get_object_or_404(EvaluationSet, pk=object_id)
            academic_year = AcademicYear.objects.current()

            for row in results:
                fields = row['parsed_fields']

                student_id = fields['IDStudent']
                teacher_id = fields['SectionTeacher::IDTEACHER']

                student = Student.objects.get(student_id=student_id)
                teacher = Teacher.objects.get(teacher_id=teacher_id)
                enrollment = Enrollment.objects.get(
                    student=student, academic_year=academic_year)

                evaluable = IIPEvaluation()
                evaluable.student = student
                evaluable.teacher = teacher
                evaluable.evaluation_set = evaluation_set
                evaluable.question_set = question_set
                evaluable.enrollment = enrollment

                evaluable.save()

                creation_count += 1

        messages.add_message(
            request, messages.SUCCESS,
            "Successfully created {count:} IIP evaluations".format(
                count=creation_count))
        return redirect(redirect_url)
Esempio n. 13
0
    def handle(self, *args, **kwargs):
        logger.info("Beginning teacher import routine")

        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']

        seen_ids = set()

        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']

                nameFirst = fields['NameFirst'] or ""
                nameLast = fields['NameLast'] or ""
                namePrefix = fields['NamePrefix'] or ""
                email = fields['EmailSchool'] or ""
                activeEmployee = fields['Active Employee'] or ""
                uniqueName = fields['NameUnique'] or ""
                teacherID = fields['IDTEACHER']

                if not teacherID:
                    continue

                seen_ids.add(teacherID)

                if activeEmployee in ("1", 1):
                    activeEmployee = True
                else:
                    activeEmployee = False

                if email:
                    validEmail = validate_email(email)

                    if not validEmail:
                        email = ""
                        logger.warn(
                            "E-mail address {email:} for {id:} ({first:} {last:}) is invalid; address blanked"
                            .format(email=email,
                                    id=teacherID,
                                    first=firstName,
                                    last=lastName))

                try:
                    teacher = Teacher.objects.get(teacher_id=teacherID)
                    logger.info("Found teacher {teacherID:}".format(
                        teacherID=teacherID))
                    forceSave = False

                except Teacher.DoesNotExist:
                    teacher = Teacher(teacher_id=teacherID)
                    logger.info("Creating teacher {teacherID:}".format(
                        teacherID=teacherID))
                    forceSave = True

                attrMap = {
                    'first_name': nameFirst,
                    'last_name': nameLast,
                    'prefix': namePrefix,
                    'email': email,
                    'active': activeEmployee,
                    'unique_name': uniqueName
                }

                for attr in attrMap:
                    dbValue = getattr(teacher, attr)

                    if dbValue != attrMap[attr]:
                        setattr(teacher, attr, attrMap[attr])
                        logger.info(
                            "Updating {attr:} on {teacherID:} from {oldValue:} to {newValue:}"
                            .format(attr=attr,
                                    teacherID=teacherID,
                                    oldValue=dbValue,
                                    newValue=attrMap[attr]))
                        forceSave = True

                if forceSave:
                    teacher.save()

            extra_teachers = Teacher.objects.exclude(teacher_id__in=seen_ids)
            for extra_teacher in extra_teachers:
                logger.warn("Deleting extra teacher {}".format(
                    extra_teacher.id))
                extra_teacher.delete()
Esempio n. 14
0
    def handle(self, *args, **kwargs):
        logger.info("Beginning student import routine")

        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']

        seen_ids = set()

        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']

                nameFirst = fields['NameFirst'] or ""
                nameLast = fields['NameLast'] or ""
                nameNickname = fields['NameNickname'] or ""
                email = fields['EMailSchool'] or ""
                studentID = fields['IDSTUDENT']
                password = fields["PasswordActiveDirctory"] or ""
                username = fields["Network_User_Name"] or ""
                gender = fields["Sex"] or ""

                if not studentID:
                    continue

                seen_ids.add(studentID)

                if username:
                    if len(username) > 20:
                        username = username[0:20]
                        logger.warn(
                            "Username {username:} was truncated to 20 characters"
                            .format(username=username))

                if email:
                    validEmail = validate_email(email)

                    if not validEmail:
                        email = ""
                        logger.warn(
                            "E-mail address {email:} for {id:} ({first:} {last:}) is invalid; address blanked"
                            .format(email=email,
                                    id=studentID,
                                    first=nameFirst,
                                    last=nameLast))

                try:
                    student = Student.objects.get(student_id=studentID)
                    logger.info("Found student {studentID:}".format(
                        studentID=studentID))
                    forceSave = False

                except Student.DoesNotExist:
                    student = Student(student_id=studentID)
                    logger.info("Creating student {studentID:}".format(
                        studentID=studentID))
                    forceSave = True

                attrMap = {
                    'first_name': nameFirst,
                    'last_name': nameLast,
                    'nickname': nameNickname,
                    'email': email,
                    'rectory_password': password,
                    'username': username,
                    'gender': gender,
                }

                for attr in attrMap:
                    dbValue = getattr(student, attr)

                    if dbValue != attrMap[attr]:
                        setattr(student, attr, attrMap[attr])
                        logger.info(
                            "Updating {attr:} on {studentID:} from {oldValue:} to {newValue:}"
                            .format(attr=attr,
                                    studentID=studentID,
                                    oldValue=dbValue,
                                    newValue=attrMap[attr]))
                        forceSave = True

                if forceSave:
                    student.save()

                self.sync_relations(student, fields)

            extra_students = Student.objects.exclude(student_id__in=seen_ids)
            for extra_student in extra_students:
                logger.warn("Deleting extra student {}".format(
                    extra_student.id))
                extra_student.delete()
    def handle(self, *args, **kwargs):
        logger.info("Beginning enrollment import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']
                
                studentID = fields['IDStudent']
                academicYear = fields['AcademicYear']
                boarderDay = fields['BoarderDay']
                dormName = fields['DormName'] or ""
                grade_code = fields['Grade']
                division = fields['Division'] or ""
                section = fields["Section Letter"] or ""
                advisorID = fields["IDAdvisor"]
                statusEnrollment = fields["StatusEnrollment"] or ""
                statusAttending = fields["StatusAttending"] or ""
                enrolledDate = fields["EnrollmentDate"]
                
                if not studentID or not academicYear:
                    continue
                
                try:
                    academicYear = AcademicYear.objects.get(year=academicYear)
                except AcademicYear.DoesNotExist:
                    academicYear = AcademicYear(year=academicYear)
                    academicYear.save()
                
                
                try:
                    student = Student.objects.get(student_id=studentID)
                except Student.DoesNotExist:
                    logger.error("Student {studentID:} is in enrollments but not in permrecs".format(studentID=studentID))
                    continue
                
                if boarderDay and boarderDay.upper() == "B":
                    boarder = True
                else:
                    boarder = False
                
                if dormName:
                    try:
                        dorm = Dorm.objects.get(dorm_name=dormName)
                    except Dorm.DoesNotExist:
                        logger.error("Dorm {dorm:} does not exist".format(dorm=dormName))
                        dorm = None
                else:
                    dorm = None
                
                
                if advisorID:
                    try:
                        advisor = Teacher.objects.get(teacher_id = advisorID)
                    except Teacher.DoesNotExist:
                        logger.error("Advisor {advisorID:} does not exist".format(advisorID=advisorID))
                        advisor = None
                else:
                    advisor = None
                
                if grade_code:
                  try:
                    grade = Grade.objects.get(grade=grade_code)
                  except Grade.DoesNotExist:
                    grade = Grade()
                    grade.grade = grade_code
                    grade.description = "Grade {grade:}".format(grade=grade_code)
                    grade.save()
                
                try:
                    enrollment = Enrollment.objects.get(student = student, academic_year = academicYear)
                    logger.info("Found enrollment {studentID:}/{academicYear:}".format(studentID=studentID, academicYear=academicYear))
                    forceSave = False
                    
                except Enrollment.DoesNotExist:
                    logger.info("Creating enrollment {studentID:}/{academicYear:}".format(studentID=studentID, academicYear=academicYear))
                    enrollment = Enrollment()
                    enrollment.student = student
                    enrollment.academic_year = academicYear
                    forceSave = True
                                        
                attrMap = {
                    'boarder': boarder,
                    'dorm': dorm,
                    'grade': grade,
                    'division': division,
                    'section': section,
                    'advisor': advisor,
                    'status_enrollment': statusEnrollment,
                    'status_attending': statusAttending,
                    'enrolled_date': enrolledDate
                }
                
                for attr in attrMap:
                    dbValue = getattr(enrollment, attr)
                    
                    if dbValue != attrMap[attr]:
                        setattr(enrollment, attr, attrMap[attr])
                        logger.info("Updating {attr:} on {studentID:}/{academicYear:} from {oldValue:} to {newValue:}".format(attr=attr, studentID=studentID, academicYear=academicYear, oldValue=dbValue, newValue=attrMap[attr]))
                        forceSave = True
                    
                if forceSave:
                    enrollment.save()
Esempio n. 16
0
    def handle(self, *args, **kwargs):
        logger.info("Beginning section import routine")

        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']

        seen_ids = set()

        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']

                course_number = fields['CourseNumber']
                csn = fields['CourseSectionNumber']
                academic_year = fields["AcademicYear"]
                teacher_id = fields["IDTeacher"]

                if not course_number or not csn or not academic_year:
                    continue

                try:
                    course = Course.objects.get(number=course_number)
                    logger.info(
                        "Found course {number:}".format(number=course_number))
                    forceSave = False

                except Course.DoesNotExist:
                    logger.error(
                        "Course {course:} is in sections but not courses".
                        format(course=course_number))
                    continue

                try:
                    academic_year = AcademicYear.objects.get(
                        year=academic_year)
                except AcademicYear.DoesNotExist:
                    academic_year = AcademicYear(year=academic_year)
                    academic_year.save()

                try:
                    section = Section.objects.get(course=course,
                                                  academic_year=academic_year,
                                                  csn=csn)
                    logger.info(
                        "Found section {csn:} for {academic_year:}".format(
                            csn=csn, academic_year=academic_year))

                except Section.DoesNotExist:
                    logger.info(
                        "Creating section {csn:} for {academic_year:}".format(
                            csn=csn, academic_year=academic_year))
                    section = Section(course=course,
                                      academic_year=academic_year,
                                      csn=csn)
                    section.save()

                teacher = None

                if teacher_id:
                    try:
                        teacher = Teacher.objects.get(teacher_id=teacher_id)
                    except Teacher.DoesNotExist:
                        logger.error(
                            "Teacher {id:} is in sections but not in teachers".
                            format(id=teacher_id))

                attrMap = {
                    'teacher': teacher,
                }

                for attr in attrMap:
                    dbValue = getattr(section, attr)

                    if dbValue != attrMap[attr]:
                        setattr(section, attr, attrMap[attr])
                        logger.info(
                            "Updating {attr:} on {course:} from {oldValue:} to {newValue:}"
                            .format(attr=attr,
                                    course=course_number,
                                    oldValue=dbValue,
                                    newValue=attrMap[attr]))
                        forceSave = True

                if forceSave:
                    section.save()
    def handle(self, *args, **kwargs):
        logger.info("Beginning family import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        seen_ids = set()
        
        with transaction.atomic():
          for row in results:
            fields = row['parsed_fields']
            
            family_id = fields["IDFAMILY"]
            
            parents = {}
            
            address = fields['P_address_full'] or ""
            address_lines = address.splitlines()
            address = "\n".join([line.strip() for line in address_lines])
            
            parent_attr_map = {              
              'Pa': {
                'first_name': (fields['Pa_first'] or "").strip(),
                'last_name': (fields['Pa_last'] or "").strip(),
                'email': (fields['Pa_email'] or "").strip(),
                'phone_home': (fields['P_phone_H'] or "").strip(),
                'phone_work': (fields['Pa_phone_W'] or "").strip(),
                'phone_cell': (fields['Pa_phone_cell'] or "").strip(),
                'address': address,
                'family_id': family_id,
                'parent_id': 'Pa',
              },
              'Pb': {
                'first_name': (fields['Pb_first'] or "").strip(),
                'last_name': (fields['Pb_last'] or "").strip(),
                'email': (fields['Pb_email'] or "").strip(),
                'phone_home': (fields['P_phone_H'] or "").strip(),
                'phone_work': (fields['Pb_phone_W'] or "").strip(),
                'phone_cell': (fields['Pb_phone_cell'] or "").strip(),
                'address': address,
                'family_id': family_id,
                'parent_id': 'Pa',
              }
            }
            
            for parent_code, parent_attrs in parent_attr_map.items():
              full_id = family_id + parent_code
              seen_ids.add(full_id)
              
              do_save = False
              
              if not (parent_attrs['first_name'] and parent_attrs['last_name']):
                #First and last name is the criteria for me to import
                continue
              
              try:
                parent = Parent.objects.get(full_id=full_id)
              except Parent.DoesNotExist:
                logger.info("Creating parent {parent_id:}".format(parent_id=full_id))
                
                do_save = True
                parent = Parent()
                parent.full_id = full_id
            
              for attr, desired_value in parent_attrs.items():
                db_value = getattr(parent, attr)
                if db_value != desired_value:
                  logger.info("Updating {attr:} on {parent_id:} from {db_value} to {desired_value:}".format(attr=attr, parent_id=full_id, db_value=db_value, desired_value=desired_value))
                  do_save = True
                  setattr(parent, attr, desired_value)
              
              if do_save:
                parent.save()
          
          extra_parents = Parent.objects.exclude(full_id__in=seen_ids)
          for extra_parent in extra_parents:
              logger.warn("Deleting extra parent {}".format(extra_parent.id))
              extra_parent.delete()
Esempio n. 18
0
    def handle(self, *args, **kwargs):
        logger.info("Beginning student registration import routine")
        
        data = fmpxmlparser.parse_from_file(kwargs['filename'])

        results = data['results']    
        
        seen_ids = set()
        
        with transaction.atomic():
            for row in results:
                fields = row['parsed_fields']
                
                csn = fields['CSN']
                academic_year = fields["AcademicYear"]
                student_id = fields["IDStudent"]
                student_reg_id = fields["IDSTUDENTREG"]
                
                if not csn or not academic_year or not student_id or not student_reg_id:
                    continue
                
                try:
                    academic_year = AcademicYear.objects.get(year=academic_year)
                except AcademicYear.DoesNotExist:
                    academic_year = AcademicYear(year=academic_year)
                    academic_year.save()
                
                try:
                    section = Section.objects.get(csn=csn, academic_year=academic_year)
                except Section.DoesNotExist:
                    logger.error("Section {csn:}/{year:} is in studentreg but not in sections".format(csn=csn, year=academic_year))
                    continue
                
                try:
                    student = Student.objects.get(student_id=student_id)
                except Student.DoesNotExist:
                    logger.error("Student {id:} is in studentreg but not in students".format(id=student_id))
                    continue
                
                try:
                    student_registration = StudentRegistration.objects.get(student_reg_id=student_reg_id)
                    logger.info("Found student registration {id:}".format(id=student_reg_id))
                    forceSave = False
                    
                except StudentRegistration.DoesNotExist:
                    student_registration = StudentRegistration(student_reg_id=student_reg_id, section=section, student=student)    
                    forceSave = True
                
                attrMap = {
                    'student': student,
                    'section': section
                }
                
                for attr in attrMap:
                    dbValue = getattr(student_registration, attr)
                    
                    if dbValue != attrMap[attr]:
                        setattr(student_registration, attr, attrMap[attr])
                        logger.info("Updating {attr:} on {student_registration:} from {oldValue:} to {newValue:}".format(attr=attr, student_registration=student_registration.student_reg_id, oldValue=dbValue, newValue=attrMap[attr]))
                        forceSave = True
                
                seen_ids.add(student_reg_id)
                    
                if forceSave:
                    student_registration.save()
            
            extra_student_registrations = StudentRegistration.objects.exclude(student_reg_id__in=seen_ids)
            for extra_student_registration in extra_student_registrations:
                logger.warn("Deleting extra student registration {}".format(extra_student_registration.student_reg_id))
                extra_student_registration.delete()