Ejemplo n.º 1
0
def p_create(fnr, lname, fname):
    gender = constants.gender_female
    try:
        fodselsnr.personnr_ok(fnr)
    except fodselsnr.InvalidFnrError:
        logger.error("Cannot create person, bad no_ssn |%s|", fnr)
        return None
    if not (lname and fname):
        logger.error("Cannot create person %s, missing name")
        return None
    if fodselsnr.er_mann(fnr):
        gender = constants.gender_female
    # this is very wrong, but as we do not have any birth days
    # registered we need to try producing them.
    year, mon, day = fodselsnr.fodt_dato(fnr)
    # in order to be a guardian you need to be over 18 years old which
    # excludes anyone born in after 1990 so this will work for now :-)
    birth_date = db.Date(year, mon, day)
    person.clear()
    # Create person
    person.populate(birth_date, gender)
    person.affect_external_id(constants.system_manual,
                              constants.externalid_fodselsnr)
    person.populate_external_id(constants.system_manual,
                                constants.externalid_fodselsnr, fnr)
    person.write_db()
    logger.info("Created new person with fnr %s", fnr)
    # Add person_name
    person.affect_names(constants.system_manual, constants.name_first,
                        constants.name_last)
    person.populate_name(constants.name_first, fname)
    person.populate_name(constants.name_last, lname)
    person.write_db()
    logger.debug("Added name %s %s to fnr %s", fname, lname, fnr)
    return person.entity_id
Ejemplo n.º 2
0
def p_create(fnr, lname, fname):
    gender = constants.gender_female
    try:
        fodselsnr.personnr_ok(fnr)
    except fodselsnr.InvalidFnrError:
        logger.error("Cannot create person, bad no_ssn |%s|", fnr)
        return None
    if not (lname and fname):
        logger.error("Cannot create person %s, missing name")
        return None
    if fodselsnr.er_mann(fnr):
        gender = constants.gender_female
    # this is very wrong, but as we do not have any birth days
    # registered we need to try producing them.
    year, mon, day = fodselsnr.fodt_dato(fnr)
    # in order to be a guardian you need to be over 18 years old which
    # excludes anyone born in after 1990 so this will work for now :-)
    birth_date = db.Date(year, mon, day)
    person.clear()
    # Create person
    person.populate(birth_date, gender)
    person.affect_external_id(constants.system_manual,
                              constants.externalid_fodselsnr)
    person.populate_external_id(constants.system_manual,
                                constants.externalid_fodselsnr, fnr)
    person.write_db()
    logger.info("Created new person with fnr %s", fnr)
    # Add person_name
    person.affect_names(constants.system_manual,
                        constants.name_first,
                        constants.name_last)
    person.populate_name(constants.name_first, fname)
    person.populate_name(constants.name_last, lname)
    person.write_db()
    logger.debug("Added name %s %s to fnr %s", fname, lname, fnr)
    return person.entity_id
Ejemplo n.º 3
0
    def next_object(self, element):

        def get_value(element_value):
            return ensure_unicode(element_value, self.encoding)

        def extract(element_attr):
            return get_value(element.get(element_attr, ""))

        result = HRDataPerson()

        # Pull out all names
        self._register_names(result, element)
        # Pull out fnr
        tmp = "%02d%02d%02d%05d" % tuple([int(element.get(x))
                                          for x in ("fodtdag",
                                                    "fodtmnd",
                                                    "fodtar",
                                                    "personnr")])
        fnr = fodselsnr.personnr_ok(tmp)
        result.add_id(result.NO_SSN, fnr)
        # Since LT does not provide birth date directly, we extract it from fnr
        result.birth_date = Date(*fodselsnr.fodt_dato(fnr))
        # ... and gender
        if fodselsnr.er_mann(fnr):
            result.gender = result.GENDER_MALE
        else:
            result.gender = result.GENDER_FEMALE
        # fi
        # Register address
        # extract = lambda y: ensure_unicode(element.get(y, ""), self.encoding)
        result.address = DataAddress(
            kind=DataAddress.ADDRESS_PRIVATE,
            street=(extract("adresselinje1_privatadresse"),
                    extract("adresselinje2_privatadresse")),
            zip=extract("poststednr_privatadresse"),
            city=extract("poststednavn_privatadresse"))

        # Contact information and jobs
        # FIXME: We do not have anything more intelligent for priorities
        priorities = dict()
        for sub in element.getiterator():
            if sub.tag in ("bilag", "gjest", "tils",):
                emp = self._make_employment(sub)
                result.add_employment(emp)
            elif sub.tag in ("komm", "arbtlf",):
                for contact in self._make_contact(sub, priorities):
                    result.add_contact(contact)
                # od
        # od

        # Reservation rules. Roughly, all employees are not reserved, unless
        # they say otherwise. Everyone else *is* reserved, unless they
        # explicitly allow publication in catalogues.
        has_active = result.has_active_employments()
        if has_active:
            to_reserve = False
            for resv in element.findall("res"):
                if (resv.get("katalogkode") == "ELKAT" and
                        resv.get("felttypekode") not in
                        ("PRIVADR", "PRIVTLF") and
                        resv.get("resnivakode") != "SAMTYKKE"):
                    to_reserve = True
        else:
            to_reserve = True
            for resv in element.findall("res"):
                if (resv.get("katalogkode") == "ELKAT" and
                        resv.get("felttypekode") not in
                        ("PRIVADR", "PRIVTLF")):
                    to_reserve = resv.get("resnivakode") != "SAMTYKKE"
        result.reserved = to_reserve
        if (element.get("fakultetnr_for_lonnsslip") and
                element.get("instituttnr_for_lonnsslip") and
                element.get("gruppenr_for_lonnsslip")):
            result.primary_ou = (cereconf.DEFAULT_INSTITUSJONSNR,
                                 extract("fakultetnr_for_lonnsslip"),
                                 extract("instituttnr_for_lonnsslip"),
                                 extract("gruppenr_for_lonnsslip"))

        if not (result.get_name(result.NAME_FIRST) and
                result.get_name(result.NAME_LAST)):
            raise AssertionError("Missing name for %s" %
                                 list(result.iterids()))

        return result
Ejemplo n.º 4
0
    def next_object(self, element):
        def get_value(element_value):
            return ensure_unicode(element_value, self.encoding)

        def extract(element_attr):
            return get_value(element.get(element_attr, ""))

        result = HRDataPerson()

        # Pull out all names
        self._register_names(result, element)
        # Pull out fnr
        tmp = "%02d%02d%02d%05d" % tuple([
            int(element.get(x))
            for x in ("fodtdag", "fodtmnd", "fodtar", "personnr")
        ])
        fnr = fodselsnr.personnr_ok(tmp)
        result.add_id(result.NO_SSN, fnr)
        # Since LT does not provide birth date directly, we extract it from fnr
        result.birth_date = Date(*fodselsnr.fodt_dato(fnr))
        # ... and gender
        if fodselsnr.er_mann(fnr):
            result.gender = result.GENDER_MALE
        else:
            result.gender = result.GENDER_FEMALE
        # fi
        # Register address
        # extract = lambda y: ensure_unicode(element.get(y, ""), self.encoding)
        result.address = DataAddress(
            kind=DataAddress.ADDRESS_PRIVATE,
            street=(extract("adresselinje1_privatadresse"),
                    extract("adresselinje2_privatadresse")),
            zip=extract("poststednr_privatadresse"),
            city=extract("poststednavn_privatadresse"))

        # Contact information and jobs
        # FIXME: We do not have anything more intelligent for priorities
        priorities = dict()
        for sub in element.getiterator():
            if sub.tag in (
                    "bilag",
                    "gjest",
                    "tils",
            ):
                emp = self._make_employment(sub)
                result.add_employment(emp)
            elif sub.tag in (
                    "komm",
                    "arbtlf",
            ):
                for contact in self._make_contact(sub, priorities):
                    result.add_contact(contact)
                # od
        # od

        # Reservation rules. Roughly, all employees are not reserved, unless
        # they say otherwise. Everyone else *is* reserved, unless they
        # explicitly allow publication in catalogues.
        has_active = result.has_active_employments()
        if has_active:
            to_reserve = False
            for resv in element.findall("res"):
                if (resv.get("katalogkode") == "ELKAT" and
                        resv.get("felttypekode") not in ("PRIVADR", "PRIVTLF")
                        and resv.get("resnivakode") != "SAMTYKKE"):
                    to_reserve = True
        else:
            to_reserve = True
            for resv in element.findall("res"):
                if (resv.get("katalogkode") == "ELKAT"
                        and resv.get("felttypekode")
                        not in ("PRIVADR", "PRIVTLF")):
                    to_reserve = resv.get("resnivakode") != "SAMTYKKE"
        result.reserved = to_reserve
        if (element.get("fakultetnr_for_lonnsslip")
                and element.get("instituttnr_for_lonnsslip")
                and element.get("gruppenr_for_lonnsslip")):
            result.primary_ou = (cereconf.DEFAULT_INSTITUSJONSNR,
                                 extract("fakultetnr_for_lonnsslip"),
                                 extract("instituttnr_for_lonnsslip"),
                                 extract("gruppenr_for_lonnsslip"))

        if not (result.get_name(result.NAME_FIRST)
                and result.get_name(result.NAME_LAST)):
            raise AssertionError("Missing name for %s" %
                                 list(result.iterids()))

        return result