コード例 #1
0
    def person_to_fs_info(self, row, person):
        """Converts a person db-row to a SimplePerson object."""
        person_id = int(row['person_id'])
        person.clear()
        person.find(person_id)

        fnr = self.find_fnr(person)
        if fnr is None:
            return None

        try:
            date6, pnr = fodselsnr.del_fnr(fnr)
        except fodselsnr.InvalidFnrError:
            logger.warn('Skipping person_id=%r, invalid fnr', person_id)
            return None

        date = person.birth_date
        result = SimplePerson(
            **{
                'fnr11':
                fnr,
                'fnr6':
                date6,
                'pnr':
                pnr,
                'birth_date':
                date.strftime('%Y-%m-%d'),
                'gender':
                person.gender == self.co.gender_male and 'M' or 'K',
                'email':
                self.find_primary_mail_address(person),
                'phone':
                self.find_contact_info(person, self.co.contact_phone),
                ''
                'fax':
                self.find_contact_info(person, self.co.contact_fax),
                'ansattnr':
                self.find_ansattnr(person),
                'mobile':
                self.find_contact_info(person, self.co.contact_mobile_phone)
            })

        for name_type, attr_name in (
            (self.co.name_first, 'name_first'),
            (self.co.name_last, 'name_last'),
        ):
            result[attr_name] = self.find_name(person, name_type)

        if self.fagperson_fields['work_title']:
            # ... and work title
            result['work_title'] = self.find_title(person)
            if None in (result['name_first'], result['name_last']):
                logger.warn('Missing name for person_id=%r, skipping',
                            person_id)
                return None

        return result
コード例 #2
0
ファイル: bofhd_nmh_cmds.py プロジェクト: unioslo/cerebrum
 def person_student_info(self, operator, person_id):
     person = self._get_person(*self._map_person_id(person_id))
     self.ba.can_get_student_info(operator.get_entity_id(), person)
     fnr = person.get_external_id(id_type=self.const.externalid_fodselsnr,
                                  source_system=self.const.system_fs)
     if not fnr:
         raise CerebrumError("No matching fnr from FS")
     fodselsdato, pnum = fodselsnr.del_fnr(fnr[0]['external_id'])
     ret = []
     try:
         fs_db = make_fs()
     except database.DatabaseError, e:
         self.logger.warn("Can't connect to FS (%s)" % e)
         raise CerebrumError("Can't connect to FS, try later")
コード例 #3
0
 def person_student_info(self, operator, person_id):
     person = self._get_person(*self._map_person_id(person_id))
     self.ba.can_get_student_info(operator.get_entity_id(), person)
     fnr = person.get_external_id(id_type=self.const.externalid_fodselsnr,
                                  source_system=self.const.system_fs)
     if not fnr:
         raise CerebrumError("No matching fnr from FS")
     fodselsdato, pnum = fodselsnr.del_fnr(fnr[0]['external_id'])
     har_opptak = {}
     ret = []
     try:
         fs_db = make_fs()
     except Database.DatabaseError, e:
         self.logger.warn("Can't connect to FS (%s)" % e)
         raise CerebrumError("Can't connect to FS, try later")
コード例 #4
0
    def _process_unprocessed_students():
        """Unprocessed students didn't match a profile, or didn't get a
        callback at all"""
        # TBD: trenger vi skille på de?
        logger.info("process_unprocessed_students")

        for fnr, pinfo in persons.items():
            if not pinfo.has_student_ac():
                continue
            if fnr not in processed_students:
                d, p = fodselsnr.del_fnr(fnr)
                BuildAccounts._process_students_callback({
                    'fodselsdato': d,
                    'personnr': p
                })
コード例 #5
0
ファイル: hr2fs-person.py プロジェクト: unioslo/cerebrum
    def person_to_fs_info(self, row, person):
        """Converts a person db-row to a SimplePerson object."""
        person_id = int(row['person_id'])
        person.clear()
        person.find(person_id)

        fnr = self.find_fnr(person)
        if fnr is None:
            return None

        try:
            date6, pnr = fodselsnr.del_fnr(fnr)
        except fodselsnr.InvalidFnrError:
            logger.warn(
                'Invalid fnr (person_id=%s). Person will be ignored',
                person_id)
            return None

        date = person.birth_date
        result = SimplePerson(
            **{'fnr11': fnr,
               'fnr6': date6,
               'pnr': pnr,
               'birth_date': date.strftime('%Y-%m-%d'),
               'gender': person.gender == self.co.gender_male and 'M' or 'K',
               'email': self.find_primary_mail_address(person),
               'phone': self.find_contact_info(person, self.co.contact_phone),
               ''
               'fax': self.find_contact_info(person, self.co.contact_fax),
               'ansattnr': self.find_ansattnr(person),
               'mobile': self.find_contact_info(person,
                                                self.co.contact_mobile_phone)
               })

        for name_type, attr_name in ((self.co.name_first, 'name_first'),
                                     (self.co.name_last, 'name_last'),):
            result[attr_name] = self.find_name(person, name_type)

        if self.fagperson_fields['work_title']:
            # ... and work title
            result['work_title'] = self.find_title(person)
            if None in (result['name_first'], result['name_last']):
                logger.warn('Missing name for fnr=%s', fnr)
                return None

        return result
コード例 #6
0
    def person_student_info(self, operator, person_id):
        person = self._get_person(*self._map_person_id(person_id))
        self.ba.can_get_student_info(operator.get_entity_id(), person)
        fnr = person.get_external_id(id_type=self.const.externalid_fodselsnr,
                                     source_system=self.const.system_fs)
        if not fnr:
            raise CerebrumError("No matching fnr from FS")
        fodselsdato, pnum = fodselsnr.del_fnr(fnr[0]['external_id'])
        ret = []
        try:
            fs_db = make_fs()
        except database.DatabaseError as e:
            self.logger.warn("Can't connect to FS (%s)" % e)
            raise CerebrumError("Can't connect to FS, try later")

        har_opptak = set()
        for row in fs_db.student.get_studierett(fodselsdato, pnum):
            har_opptak.add(row['studieprogramkode'])
            ret.append({
                'studprogkode':
                row['studieprogramkode'],
                'studierettstatkode':
                row['studierettstatkode'],
                'studentstatkode':
                row['studentstatkode'],
                'studieretningkode':
                row['studieretningkode'],
                'dato_tildelt':
                self._ticks_to_date(row['dato_studierett_tildelt']),
                'dato_gyldig_til':
                self._ticks_to_date(row['dato_studierett_gyldig_til']),
                'privatist':
                row['status_privatist'],
            })

        for row in fs_db.student.get_eksamensmeldinger(fodselsdato, pnum):
            programmer = []
            for row2 in fs_db.info.get_emne_i_studieprogram(row['emnekode']):
                if row2['studieprogramkode'] in har_opptak:
                    programmer.append(row2['studieprogramkode'])
            ret.append({
                'ekskode': row['emnekode'],
                'programmer': ",".join(programmer),
                'dato': self._ticks_to_date(row['dato_opprettet']),
            })

        for row in fs_db.student.get_utdanningsplan(fodselsdato, pnum):
            ret.append({
                'studieprogramkode':
                row['studieprogramkode'],
                'terminkode_bekreft':
                row['terminkode_bekreft'],
                'arstall_bekreft':
                row['arstall_bekreft'],
                'dato_bekreftet':
                self._ticks_to_date(row['dato_bekreftet']),
            })

        for row in fs_db.student.get_semreg(fodselsdato, pnum):
            ret.append({
                'regformkode':
                row['regformkode'],
                'betformkode':
                row['betformkode'],
                'dato_endring':
                self._ticks_to_date(row['dato_endring']),
                'dato_regform_endret':
                self._ticks_to_date(row['dato_regform_endret']),
            })
        return ret
コード例 #7
0
    def person_student_info(self, operator, person_id):
        person_exists = False
        person = None
        try:
            person = self._get_person(*self._map_person_id(person_id))
            person_exists = True
        except CerebrumError as e:
            # Check if person exists in FS, but is not imported yet, e.g.
            # emnestudents. These should only be listed with limited
            # information.
            if person_id and len(person_id) == 11 and person_id.isdigit():
                try:
                    person_id = fodselsnr.personnr_ok(person_id)
                except Exception:
                    raise e
                self.logger.debug('Unknown person %r, asking FS directly',
                                  person_id)
                self.ba.can_get_student_info(operator.get_entity_id(), None)
                fodselsdato, pnum = person_id[:6], person_id[6:]
            else:
                raise e
        else:
            self.ba.can_get_student_info(operator.get_entity_id(), person)
            fnr = person.get_external_id(
                id_type=self.const.externalid_fodselsnr,
                source_system=self.const.system_fs)
            if not fnr:
                raise CerebrumError("No matching fnr from FS")
            fodselsdato, pnum = fodselsnr.del_fnr(fnr[0]['external_id'])
        ret = []
        try:
            db = database.connect(user=cereconf.FS_USER,
                                  service=cereconf.FS_DATABASE_NAME,
                                  DB_driver=cereconf.DB_DRIVER_ORACLE)
        except database.DatabaseError as e:
            self.logger.warn("Can't connect to FS (%s)", text_type(e))
            raise CerebrumError("Can't connect to FS, try later")
        fs = FS(db)
        for row in fs.student.get_undervisningsmelding(fodselsdato, pnum):
            ret.append({
                'undvkode': row['emnekode'],
                'dato': row['dato_endring'],
            })

        har_opptak = set()
        if person_exists:
            for row in fs.student.get_studierett(fodselsdato, pnum):
                har_opptak.add(row['studieprogramkode'])
                ret.append({
                    'studprogkode': row['studieprogramkode'],
                    'studierettstatkode': row['studierettstatkode'],
                    'studentstatkode': row['studentstatkode'],
                    'studieretningkode': row['studieretningkode'],
                    'dato_tildelt': row['dato_studierett_tildelt'],
                    'dato_gyldig_til': row['dato_studierett_gyldig_til'],
                    'privatist': row['status_privatist'],
                })

            for row in fs.student.get_eksamensmeldinger(fodselsdato, pnum):
                programmer = []
                for row2 in fs.info.get_emne_i_studieprogram(row['emnekode']):
                    if row2['studieprogramkode'] in har_opptak:
                        programmer.append(row2['studieprogramkode'])
                ret.append({
                    'ekskode': row['emnekode'],
                    'programmer': ",".join(programmer),
                    'dato': row['dato_opprettet'],
                })

            for row in fs.student.get_utdanningsplan(fodselsdato, pnum):
                ret.append({
                    'studieprogramkode': row['studieprogramkode'],
                    'terminkode_bekreft': row['terminkode_bekreft'],
                    'arstall_bekreft': row['arstall_bekreft'],
                    'dato_bekreftet': row['dato_bekreftet'],
                })

            def _ok_or_not(input):
                """Helper function for proper feedback of status."""
                if not input or input == 'N':
                    return 'Nei'
                if input == 'J':
                    return 'Ja'
                return input

            semregs = tuple(fs.student.get_semreg(fodselsdato, pnum,
                                                  only_valid=False))
            for row in semregs:
                ret.append({
                    'regstatus': _ok_or_not(row['status_reg_ok']),
                    'regformkode': row['regformkode'],
                    'dato_endring': row['dato_endring'],
                    'dato_regform_endret': row['dato_regform_endret'],
                })
                ret.append({
                    'betstatus': _ok_or_not(row['status_bet_ok']),
                    'betformkode': row['betformkode'],
                    'dato_betaling': row['dato_betaling'],
                })
            # The semreg and sembet lines should always be sent, to make it
            # easier for the IT staff to see if a student have paid or not.
            if not semregs:
                ret.append({
                    'regstatus': 'Nei',
                    'regformkode': None,
                    'dato_endring': None,
                    'dato_regform_endret': None,
                })
                ret.append({
                    'betstatus': 'Nei',
                    'betformkode': None,
                    'dato_betaling': None,
                })

        db.close()
        return ret
コード例 #8
0
ファイル: bofhd_nih_cmds.py プロジェクト: unioslo/cerebrum
    def person_student_info(self, operator, person_id):
        person = self._get_person(*self._map_person_id(person_id))
        self.ba.can_get_student_info(operator.get_entity_id(), person)
        fnr = person.get_external_id(id_type=self.const.externalid_fodselsnr,
                                     source_system=self.const.system_fs)
        if not fnr:
            raise CerebrumError("No matching fnr from FS")
        fodselsdato, pnum = fodselsnr.del_fnr(fnr[0]['external_id'])
        ret = []
        try:
            fs_db = make_fs()
        except database.DatabaseError as e:
            self.logger.warn("Can't connect to FS (%s)" % e)
            raise CerebrumError("Can't connect to FS, try later")

        har_opptak = set()
        for row in fs_db.student.get_studierett(fodselsdato, pnum):
            har_opptak.add(row['studieprogramkode'])
            ret.append(
                {
                    'studprogkode': row['studieprogramkode'],
                    'studierettstatkode': row['studierettstatkode'],
                    'studentstatkode': row['studentstatkode'],
                    'studieretningkode': row['studieretningkode'],
                    'dato_tildelt': self._ticks_to_date(
                        row['dato_studierett_tildelt']),
                    'dato_gyldig_til': self._ticks_to_date(
                        row['dato_studierett_gyldig_til']),
                    'privatist': row['status_privatist'],
                }
            )

        for row in fs_db.student.get_eksamensmeldinger(fodselsdato, pnum):
            programmer = []
            for row2 in fs_db.info.get_emne_i_studieprogram(row['emnekode']):
                if row2['studieprogramkode'] in har_opptak:
                    programmer.append(row2['studieprogramkode'])
            ret.append(
                {
                    'ekskode': row['emnekode'],
                    'programmer': ",".join(programmer),
                    'dato': self._ticks_to_date(row['dato_opprettet']),
                }
            )

        for row in fs_db.student.get_utdanningsplan(fodselsdato, pnum):
            ret.append(
                {
                    'studieprogramkode': row['studieprogramkode'],
                    'terminkode_bekreft': row['terminkode_bekreft'],
                    'arstall_bekreft': row['arstall_bekreft'],
                    'dato_bekreftet': self._ticks_to_date(
                        row['dato_bekreftet']),
                }
            )

        for row in fs_db.student.get_semreg(fodselsdato, pnum):
            ret.append(
                {
                    'regformkode': row['regformkode'],
                    'betformkode': row['betformkode'],
                    'dato_endring': self._ticks_to_date(row['dato_endring']),
                    'dato_regform_endret': self._ticks_to_date(
                        row['dato_regform_endret']),
                }
            )
        return ret
コード例 #9
0
ファイル: hr2fs-person.py プロジェクト: chrnux/cerebrum
def person2fs_info(row, person, authoritative_system):
    """Convert a db-row with person id to a chunk of data to be exported to FS
    for that particular person.

    @type row: db_row instance.
    @param row:
      A row containing a person_id and affiliation information for a
      candidate to be output.

    @type person: a Factory.get('Person') instance.
    @param person:
      DB person proxy.

    @param authoritative_system: Cf. L{make_fs_updates}.

    @rtype: SimplePerson instance or None.
    @return:
      A SimplePerson object with all the allowed_keys filled in with
      appropriate data. If names or fnr are missing, None is returned (we
      cannot proceed without a certain minimum of information about a person).
    """

    person_id = int(row['person_id'])
    person.clear()
    person.find(person_id)

    fnr = find_fnr(person, authoritative_system)
    if fnr is None:
        return None

    try:
        date6, pnr = fodselsnr.del_fnr(fnr)
    except fodselsnr.InvalidFnrError:
        logger.warn('Invalid fnr: %s (person_id=%s). Person will be ignored', \
                    fnr, person_id)
        return None

    date = person.birth_date
    result = SimplePerson(**{'fnr11': fnr,
                             'fnr6': date6,
                             'pnr': pnr,
                             'birth_date': date.strftime('%Y-%m-%d'),
                             'gender': person.gender == constants.gender_male
                                         and 'M' or 'K',
                             'email': find_primary_mail_address(person),
                             'phone': find_contact_info(person,
                                                        constants.contact_phone,
                                                        authoritative_system),
                             'fax': find_contact_info(person,
                                                      constants.contact_fax,
                                                      authoritative_system),
                             'ansattnr': find_ansattnr(fnr),
                             })
    # Slurp in names...
    for name_type, attr_name in ((constants.name_first, 'name_first'),
                                 (constants.name_last, 'name_last'),):
        result[attr_name] = find_name(person, name_type, authoritative_system)

    # ... and work title
    result['work_title'] = find_title(person)
    if None in (result['name_first'], result['name_last']):
        logger.warn('Missing name for fnr=%s', fnr)
        return None

    return result