Example #1
0
    def update_program_history(self, student_info, verbosity, dry_run):
        """
        Find/update GradProgramHistory object for this happening
        """
        programs = student_info['programs']

        key = self.import_key()
        if self.strm < student_info['real_admit_term']:
            # program change could happen before admit: we take those as effective the student's admit term
            strm = student_info['real_admit_term']
        else:
            strm = self.strm

        previous_history = [
            p for p in programs if p.start_semester.name <= strm
        ]
        need_ph = False
        if previous_history:
            # there is a previously-known program: make sure it matches
            ph = previous_history[-1]
            if ph.program != self.grad_program:
                # current program isn't what we found
                # ... but is there maybe two program changes in one semester?
                similar_history = [
                    p for p in programs if p.start_semester.name == strm
                    and p.program == self.grad_program
                ]
                if similar_history:
                    ph = similar_history[0]
                    #  We need to check if we have a different date for this action than the matching entry.
                    #  in some cases (like adding an active status afterwards), we need this date to be maximized
                    #  to show the correct current program.
                    if ph.starting != self.effdt:
                        if verbosity > 1:
                            print("Changing start of similar program %s/%s in %s from %s to %s" % \
                                  (self.emplid, self.unit.slug, self.grad_program.slug, ph.starting, self.effdt))
                        ph.starting = self.effdt
                        if not dry_run:
                            ph.save()

                else:
                    need_ph = True

        else:
            # maybe the next-known program change is to the same program? If so, move it back.
            next_history = [
                p for p in programs if p.start_semester.name > strm
            ]
            if next_history and next_history[0].program == self.grad_program:
                if verbosity > 1:
                    print(
                        "* Adjusting program change start: %s/%s in %s as of %s."
                        % (self.emplid, self.unit.slug, self.grad_program.slug,
                           strm))
                ph = next_history[0]
                ph.start_semester = STRM_MAP[strm]
                ph.starting = self.effdt
            else:
                # no history: create
                need_ph = True

        # make sure we don't duplicate: have a last look for an old import
        existing_history = [
            p for p in programs
            if SIMS_SOURCE in p.config and (p.config[SIMS_SOURCE] == key or p.
                                            config[SIMS_SOURCE] == self.oldkey)
        ]
        if existing_history:
            ph = existing_history[0]
            need_ph = False

        if need_ph:
            if (verbosity and previous_history) or verbosity > 1:
                # don't usually report first ever ProgramHistory because those are boring
                print("Adding program change: %s/%s in %s as of %s." %
                      (self.emplid, self.unit.slug, self.grad_program.slug,
                       strm))
            ph = GradProgramHistory(student=student_info['student'],
                                    program=self.grad_program,
                                    start_semester=STRM_MAP[strm],
                                    starting=self.effdt)
            ph.config[SIMS_SOURCE] = key
            student_info['programs'].append(ph)
            student_info['programs'].sort(
                key=lambda p: (p.start_semester.name, p.starting))
        else:
            if SIMS_SOURCE not in ph.config or ph.config[
                    SIMS_SOURCE] == self.oldkey:
                ph.config[SIMS_SOURCE] = key

        if not dry_run:
            ph.save_if_dirty()
Example #2
0
    def update_program_history(self, student_info, verbosity, dry_run):
        """
        Find/update GradProgramHistory object for this happening
        """
        programs = student_info['programs']

        if self.unit.slug == 'cmpt' and programs:
            # CMPT students get only their initial application gradprogramhistory filled in.
            return

        key = self.import_key()
        if self.strm < student_info['real_admit_term']:
            # program change could happen before admit: we take those as effective the student's admit term
            strm = student_info['real_admit_term']
        else:
            strm = self.strm

        previous_history = [p for p in programs if p.start_semester.name <= strm]
        need_ph = False
        if previous_history:
            # there is a previously-known program: make sure it matches
            ph = previous_history[-1]
            if ph.program != self.grad_program:
                # current program isn't what we found
                # ... but is there maybe two program changes in one semester?
                similar_history = [p for p in programs if p.start_semester == ph.start_semester
                        and p.program == self.grad_program]
                if similar_history:
                    ph = similar_history[0]
                else:
                    need_ph = True

        else:
            # maybe the next-known program change is to the same program? If so, move it back.
            next_history = [p for p in programs if p.start_semester.name > strm]
            if next_history and next_history[0].program == self.grad_program:
                if verbosity > 1:
                    print "* Adjusting program change start: %s/%s in %s as of %s." % (self.emplid, self.unit.slug, self.grad_program.slug, strm)
                ph = next_history[0]
                ph.start_semester = STRM_MAP[strm]
                ph.starting = self.effdt
            else:
                # no history: create
                need_ph = True

        # make sure we don't duplicate: have a last look for an old import
        existing_history = [p for p in programs if
                SIMS_SOURCE in p.config and (p.config[SIMS_SOURCE] == key or p.config[SIMS_SOURCE] == self.oldkey)]
        if existing_history:
            ph = existing_history[0]
            need_ph = False

        if need_ph:
            if (verbosity and previous_history) or verbosity > 1:
                # don't usually report first ever ProgramHistory because those are boring
                print "Adding program change: %s/%s in %s as of %s." % (self.emplid, self.unit.slug, self.grad_program.slug, strm)
            ph = GradProgramHistory(student=student_info['student'], program=self.grad_program,
                    start_semester=STRM_MAP[strm], starting=self.effdt)
            ph.config[SIMS_SOURCE] = key
            student_info['programs'].append(ph)
            student_info['programs'].sort(key=lambda p: (p.start_semester.name, p.starting))
        else:
            if SIMS_SOURCE not in ph.config or ph.config[SIMS_SOURCE] == self.oldkey:
                ph.config[SIMS_SOURCE] = key

        if not dry_run:
            ph.save_if_dirty()
Example #3
0
    def update_program_history(self, student_info, verbosity, dry_run):
        """
        Find/update GradProgramHistory object for this happening
        """
        programs = student_info['programs']

        if self.unit.slug == 'cmpt' and programs:
            # CMPT students get only their initial application gradprogramhistory filled in.
            return

        key = self.import_key()
        if self.strm < student_info['real_admit_term']:
            # program change could happen before admit: we take those as effective the student's admit term
            strm = student_info['real_admit_term']
        else:
            strm = self.strm

        previous_history = [
            p for p in programs if p.start_semester.name <= strm
        ]
        need_ph = False
        if previous_history:
            # there is a previously-known program: make sure it matches
            ph = previous_history[-1]
            if ph.program != self.grad_program:
                # current program isn't what we found
                # ... but is there maybe two program changes in one semester?
                similar_history = [
                    p for p in programs if p.start_semester.name == strm
                    and p.program == self.grad_program
                ]
                if similar_history:
                    ph = similar_history[0]
                else:
                    need_ph = True

        else:
            # maybe the next-known program change is to the same program? If so, move it back.
            next_history = [
                p for p in programs if p.start_semester.name > strm
            ]
            if next_history and next_history[0].program == self.grad_program:
                if verbosity > 1:
                    print "* Adjusting program change start: %s/%s in %s as of %s." % (
                        self.emplid, self.unit.slug, self.grad_program.slug,
                        strm)
                ph = next_history[0]
                ph.start_semester = STRM_MAP[strm]
                ph.starting = self.effdt
            else:
                # no history: create
                need_ph = True

        # make sure we don't duplicate: have a last look for an old import
        existing_history = [
            p for p in programs
            if SIMS_SOURCE in p.config and (p.config[SIMS_SOURCE] == key or p.
                                            config[SIMS_SOURCE] == self.oldkey)
        ]
        if existing_history:
            ph = existing_history[0]
            need_ph = False

        if need_ph:
            if (verbosity and previous_history) or verbosity > 1:
                # don't usually report first ever ProgramHistory because those are boring
                print "Adding program change: %s/%s in %s as of %s." % (
                    self.emplid, self.unit.slug, self.grad_program.slug, strm)
            ph = GradProgramHistory(student=student_info['student'],
                                    program=self.grad_program,
                                    start_semester=STRM_MAP[strm],
                                    starting=self.effdt)
            ph.config[SIMS_SOURCE] = key
            student_info['programs'].append(ph)
            student_info['programs'].sort(
                key=lambda p: (p.start_semester.name, p.starting))
        else:
            if SIMS_SOURCE not in ph.config or ph.config[
                    SIMS_SOURCE] == self.oldkey:
                ph.config[SIMS_SOURCE] = key

        if not dry_run:
            ph.save_if_dirty()
Example #4
0
    def update_program_history(self, student_info, verbosity, dry_run):
        """
        Find/update GradProgramHistory object for this happening
        """
        programs = student_info['programs']

        key = self.import_key()
        if self.strm < student_info['real_admit_term']:
            # program change could happen before admit: we take those as effective the student's admit term
            strm = student_info['real_admit_term']
        else:
            strm = self.strm

        previous_history = [p for p in programs if p.start_semester.name <= strm]
        need_ph = False
        if previous_history:
            # there is a previously-known program: make sure it matches
            ph = previous_history[-1]
            if ph.program != self.grad_program:
                # current program isn't what we found
                # ... but is there maybe two program changes in one semester?
                similar_history = [p for p in programs if p.start_semester.name == strm
                        and p.program == self.grad_program]
                if similar_history:
                    ph = similar_history[0]
                    #  We need to check if we have a different date for this action than the matching entry.
                    #  in some cases (like adding an active status afterwards), we need this date to be maximized
                    #  to show the correct current program.
                    if ph.starting != self.effdt:
                        if verbosity > 1:
                            print("Changing start of similar program %s/%s in %s from %s to %s" % \
                                  (self.emplid, self.unit.slug, self.grad_program.slug, ph.starting, self.effdt))
                        ph.starting = self.effdt
                        if not dry_run:
                            ph.save()

                else:
                    need_ph = True

        else:
            # maybe the next-known program change is to the same program? If so, move it back.
            next_history = [p for p in programs if p.start_semester.name > strm]
            if next_history and next_history[0].program == self.grad_program:
                if verbosity > 1:
                    print("* Adjusting program change start: %s/%s in %s as of %s." % (self.emplid, self.unit.slug, self.grad_program.slug, strm))
                ph = next_history[0]
                ph.start_semester = STRM_MAP[strm]
                ph.starting = self.effdt
            else:
                # no history: create
                need_ph = True

        # make sure we don't duplicate: have a last look for an old import
        existing_history = [p for p in programs if
                SIMS_SOURCE in p.config and (p.config[SIMS_SOURCE] == key or p.config[SIMS_SOURCE] == self.oldkey)]
        if existing_history:
            ph = existing_history[0]
            need_ph = False

        if need_ph:
            if (verbosity and previous_history) or verbosity > 1:
                # don't usually report first ever ProgramHistory because those are boring
                print("Adding program change: %s/%s in %s as of %s." % (self.emplid, self.unit.slug, self.grad_program.slug, strm))
            ph = GradProgramHistory(student=student_info['student'], program=self.grad_program,
                    start_semester=STRM_MAP[strm], starting=self.effdt)
            ph.config[SIMS_SOURCE] = key
            student_info['programs'].append(ph)
            student_info['programs'].sort(key=lambda p: (p.start_semester.name, p.starting))
        else:
            if SIMS_SOURCE not in ph.config or ph.config[SIMS_SOURCE] == self.oldkey:
                ph.config[SIMS_SOURCE] = key

        if not dry_run:
            ph.save_if_dirty()