Пример #1
0
def _create_grs_from_user(oid, email="", user_attrs=None):
    user_attrs = user_attrs or {}
    gender_map = {"male": u"М", "female": u"Ж"}

    person_info = user_attrs.get("person_info", {})
    # person_contacts = user_attrs.get('person_contacts', {})
    # person_addresses = user_attrs.get('person_addresses', [])
    # rf_passports = filter(lambda doc: doc['type'] == 'RF_PASSPORT' and 'Identifiable' in doc['stateFacts'],
    #                       user_attrs.get('person_docs', []))
    # reg_address = {}
    # prozhiv_address = {}
    #
    # for person_address in person_addresses:
    #     if person_address.get('type', '') == 'PRG':
    #         reg_address = person_address
    #     elif person_address.get('type', '') == 'PLV':
    #         prozhiv_address = person_address

    # phone_contact = {}
    # for person_contact in person_contacts:
    #     if person_contact.get('type', '') == 'MBT':
    #         phone_contact = person_contact

    # foreigner = u''
    # citizenship = person_info.get('citizenship', '').lower()
    #
    # if citizenship:
    #     if citizenship == 'rus':
    #         foreigner = u'0'
    #     else:
    #         foreigner = u'1'

    birth_date = person_info.get("birth_year", "")
    if birth_date:
        birth_date += "0101"

    record = grs.Record()

    def add_field_to_record(tag, value):
        if not value:
            return
        record.add_field(grs.Field(tag, value))

    add_field_to_record("101", normalize_fio(person_info.get("lname", "")))
    add_field_to_record("102", normalize_fio(person_info.get("fname", "")))
    add_field_to_record("103", normalize_fio(person_info.get("pname", "")))
    add_field_to_record("105", datetime.now().strftime("%Y%m%d"))
    add_field_to_record("115", _generate_password())
    # add_field_to_record('120', phone_contact.get('value', ''))
    # add_field_to_record('121', _generate_registraion_address(prozhiv_address))
    add_field_to_record("122", email)
    # add_field_to_record('130', _generate_registraion_address(reg_address))
    add_field_to_record("234", birth_date)
    # add_field_to_record('402', person_info.get('snils', ''))
    add_field_to_record(OID_FIELD, oid)
    add_field_to_record("404", gender_map.get(person_info.get("gender", "").lower(), u""))

    organisations = person_info.get("organizations", [])
    for organisation in organisations:
        add_field_to_record("505", unicode(organisation.get("id", "")))
        add_field_to_record("506", unicode(organisation.get("region", {}).get("id")))
    # if rf_passports:
    #     rf_passport = rf_passports[-1]
    #     add_field_to_record('417', u'Паспорт')
    #     add_field_to_record('418', rf_passport.get('series', ''))
    #     add_field_to_record('419', rf_passport.get('number', ''))
    #     add_field_to_record('420', rf_passport.get('issuedBy', ''))
    #     issue_date_parts = rf_passport.get('issueDate', '').split('.')
    #     issue_date = ''
    #     if len(issue_date_parts) == 3:
    #         issue_date = issue_date_parts[2] + issue_date_parts[1] + issue_date_parts[0]
    #     add_field_to_record('421', issue_date)
    #     add_field_to_record('422', rf_passport.get('issueId', ''))
    #
    # add_field_to_record('423', reg_address.get('zipCode', ''))
    # add_field_to_record('424', _generate_region_city(reg_address))
    # add_field_to_record('425', prozhiv_address.get('zipCode', ''))
    # add_field_to_record('426', _generate_region_city(prozhiv_address))
    # add_field_to_record('427', foreigner)
    add_field_to_record("501", "3")

    # Trusted
    # add_field_to_record('502', '1')
    # add_field_to_record('503', '1')

    return record
Пример #2
0
def _create_grs_from_esia(oid, email='', user_attrs=None):
    user_attrs = user_attrs or {}
    gender_map = {
        'm': u'М',
        'f': u'Ж'
    }

    person_info = user_attrs.get('person_info', {})
    person_contacts = user_attrs.get('person_contacts', {})
    person_addresses = user_attrs.get('person_addresses', [])
    rf_passports = filter(lambda doc: doc['type'] == 'RF_PASSPORT' and 'Identifiable' in doc['stateFacts'],
                          user_attrs.get('person_docs', []))
    reg_address = {}
    prozhiv_address = {}

    for person_address in person_addresses:
        if person_address.get('type', '') == 'PRG':
            reg_address = person_address
        elif person_address.get('type', '') == 'PLV':
            prozhiv_address = person_address

    phone_contact = {}
    for person_contact in person_contacts:
        if person_contact.get('type', '') == 'MBT':
            phone_contact = person_contact

    foreigner = u''
    citizenship = person_info.get('citizenship', '').lower()

    if citizenship:
        if citizenship == 'rus':
            foreigner = u'0'
        else:
            foreigner = u'1'

    birth_date = person_info.get('birthDate', '')
    if birth_date:
        birth_date = datetime.strptime(birth_date, '%d.%m.%Y').strftime('%Y%m%d')

    record = grs.Record()

    def add_field_to_record(tag, value):
        if not value:
            return
        record.add_field(grs.Field(tag, value))

    add_field_to_record('101', normalize_fio(person_info.get('lastName', '')))
    add_field_to_record('102', normalize_fio(person_info.get('firstName', '')))
    add_field_to_record('103', normalize_fio(person_info.get('middleName', '')))
    add_field_to_record('105', datetime.now().strftime('%Y%m%d'))
    add_field_to_record('115', _generate_password())
    add_field_to_record('120', phone_contact.get('value', ''))
    add_field_to_record('121', _generate_registraion_address(prozhiv_address))
    add_field_to_record('122', email)
    add_field_to_record('130', _generate_registraion_address(reg_address))
    add_field_to_record('234', birth_date)
    add_field_to_record('402', person_info.get('snils', ''))
    add_field_to_record('403', oid)
    add_field_to_record('404', gender_map.get(person_info.get('gender', '').lower(), u''))

    if rf_passports:
        rf_passport = rf_passports[-1]
        add_field_to_record('417', u'Паспорт')
        add_field_to_record('418', rf_passport.get('series', ''))
        add_field_to_record('419', rf_passport.get('number', ''))
        add_field_to_record('420', rf_passport.get('issuedBy', ''))
        issue_date_parts = rf_passport.get('issueDate', '').split('.')
        issue_date = ''
        if len(issue_date_parts) == 3:
            issue_date = issue_date_parts[2] + issue_date_parts[1] + issue_date_parts[0]
        add_field_to_record('421', issue_date)
        add_field_to_record('422', rf_passport.get('issueId', ''))

    add_field_to_record('423', reg_address.get('zipCode', ''))
    add_field_to_record('424', _generate_region_city(reg_address))
    add_field_to_record('425', prozhiv_address.get('zipCode', ''))
    add_field_to_record('426', _generate_region_city(prozhiv_address))
    add_field_to_record('427', foreigner)
    add_field_to_record('501', '2')

    trusted = person_info.get('trusted', False)
    if trusted is True:
        add_field_to_record('502', '1')
        add_field_to_record('503', '1')

    return record
Пример #3
0
def _create_grs_from_esia(oid, email='', user_attrs=None):
    user_attrs = user_attrs or {}
    gender_map = {'m': u'М', 'f': u'Ж'}

    person_info = user_attrs.get('person_info', {})
    person_contacts = user_attrs.get('person_contacts', {})
    person_addresses = user_attrs.get('person_addresses', [])
    rf_passports = filter(
        lambda doc: doc['type'] == 'RF_PASSPORT' and 'Identifiable' in doc[
            'stateFacts'], user_attrs.get('person_docs', []))
    reg_address = {}
    prozhiv_address = {}

    for person_address in person_addresses:
        if person_address.get('type', '') == 'PRG':
            reg_address = person_address
        elif person_address.get('type', '') == 'PLV':
            prozhiv_address = person_address

    phone_contact = {}
    for person_contact in person_contacts:
        if person_contact.get('type', '') == 'MBT':
            phone_contact = person_contact

    foreigner = u''
    citizenship = person_info.get('citizenship', '').lower()

    if citizenship:
        if citizenship == 'rus':
            foreigner = u'0'
        else:
            foreigner = u'1'

    birth_date = person_info.get('birthDate', '')
    if birth_date:
        birth_date = datetime.strptime(birth_date,
                                       '%d.%m.%Y').strftime('%Y%m%d')

    record = grs.Record()

    def add_field_to_record(tag, value):
        if not value:
            return
        record.add_field(grs.Field(tag, value))

    add_field_to_record('101', normalize_fio(person_info.get('lastName', '')))
    add_field_to_record('102', normalize_fio(person_info.get('firstName', '')))
    add_field_to_record('103', normalize_fio(person_info.get('middleName',
                                                             '')))
    add_field_to_record('105', datetime.now().strftime('%Y%m%d'))
    add_field_to_record('115', _generate_password())
    add_field_to_record('120', phone_contact.get('value', ''))
    add_field_to_record('121', _generate_registraion_address(prozhiv_address))
    add_field_to_record('122', email)
    add_field_to_record('130', _generate_registraion_address(reg_address))
    add_field_to_record('234', birth_date)
    add_field_to_record('402', person_info.get('snils', ''))
    add_field_to_record('403', oid)
    add_field_to_record(
        '404', gender_map.get(person_info.get('gender', '').lower(), u''))

    if rf_passports:
        rf_passport = rf_passports[-1]
        add_field_to_record('417', u'Паспорт')
        add_field_to_record('418', rf_passport.get('series', ''))
        add_field_to_record('419', rf_passport.get('number', ''))
        add_field_to_record('420', rf_passport.get('issuedBy', ''))
        issue_date_parts = rf_passport.get('issueDate', '').split('.')
        issue_date = ''
        if len(issue_date_parts) == 3:
            issue_date = issue_date_parts[2] + issue_date_parts[
                1] + issue_date_parts[0]
        add_field_to_record('421', issue_date)
        add_field_to_record('422', rf_passport.get('issueId', ''))

    add_field_to_record('423', reg_address.get('zipCode', ''))
    add_field_to_record('424', _generate_region_city(reg_address))
    add_field_to_record('425', prozhiv_address.get('zipCode', ''))
    add_field_to_record('426', _generate_region_city(prozhiv_address))
    add_field_to_record('427', foreigner)
    add_field_to_record('501', '2')

    trusted = person_info.get('trusted', False)
    if trusted is True:
        add_field_to_record('502', '1')
        add_field_to_record('503', '1')

    return record
Пример #4
0
def _create_grs_from_user(oid, email='', user_attrs=None):
    user_attrs = user_attrs or {}
    gender_map = {'male': u'М', 'female': u'Ж'}

    person_info = user_attrs.get('person_info', {})
    # person_contacts = user_attrs.get('person_contacts', {})
    # person_addresses = user_attrs.get('person_addresses', [])
    # rf_passports = filter(lambda doc: doc['type'] == 'RF_PASSPORT' and 'Identifiable' in doc['stateFacts'],
    #                       user_attrs.get('person_docs', []))
    # reg_address = {}
    # prozhiv_address = {}
    #
    # for person_address in person_addresses:
    #     if person_address.get('type', '') == 'PRG':
    #         reg_address = person_address
    #     elif person_address.get('type', '') == 'PLV':
    #         prozhiv_address = person_address

    # phone_contact = {}
    # for person_contact in person_contacts:
    #     if person_contact.get('type', '') == 'MBT':
    #         phone_contact = person_contact

    # foreigner = u''
    # citizenship = person_info.get('citizenship', '').lower()
    #
    # if citizenship:
    #     if citizenship == 'rus':
    #         foreigner = u'0'
    #     else:
    #         foreigner = u'1'

    birth_date = person_info.get('birth_year', '')
    if birth_date:
        birth_date += '0101'

    record = grs.Record()

    def add_field_to_record(tag, value):
        if not value:
            return
        record.add_field(grs.Field(tag, value))

    add_field_to_record('101', normalize_fio(person_info.get('lname', '')))
    add_field_to_record('102', normalize_fio(person_info.get('fname', '')))
    add_field_to_record('103', normalize_fio(person_info.get('pname', '')))
    add_field_to_record('105', datetime.now().strftime('%Y%m%d'))
    add_field_to_record('115', _generate_password())
    # add_field_to_record('120', phone_contact.get('value', ''))
    # add_field_to_record('121', _generate_registraion_address(prozhiv_address))
    add_field_to_record('122', email)
    # add_field_to_record('130', _generate_registraion_address(reg_address))
    add_field_to_record('234', birth_date)
    # add_field_to_record('402', person_info.get('snils', ''))
    add_field_to_record(OID_FIELD, oid)
    add_field_to_record(
        '404', gender_map.get(person_info.get('gender', '').lower(), u''))

    organisations = person_info.get('organizations', [])
    for organisation in organisations:
        add_field_to_record('505', unicode(organisation.get('id', '')))
        add_field_to_record('506',
                            unicode(organisation.get('region', {}).get('id')))
    # if rf_passports:
    #     rf_passport = rf_passports[-1]
    #     add_field_to_record('417', u'Паспорт')
    #     add_field_to_record('418', rf_passport.get('series', ''))
    #     add_field_to_record('419', rf_passport.get('number', ''))
    #     add_field_to_record('420', rf_passport.get('issuedBy', ''))
    #     issue_date_parts = rf_passport.get('issueDate', '').split('.')
    #     issue_date = ''
    #     if len(issue_date_parts) == 3:
    #         issue_date = issue_date_parts[2] + issue_date_parts[1] + issue_date_parts[0]
    #     add_field_to_record('421', issue_date)
    #     add_field_to_record('422', rf_passport.get('issueId', ''))
    #
    # add_field_to_record('423', reg_address.get('zipCode', ''))
    # add_field_to_record('424', _generate_region_city(reg_address))
    # add_field_to_record('425', prozhiv_address.get('zipCode', ''))
    # add_field_to_record('426', _generate_region_city(prozhiv_address))
    # add_field_to_record('427', foreigner)
    add_field_to_record('501', '3')
    add_field_to_record('510', datetime.now().strftime('%Y%m%d'))

    # Trusted
    # add_field_to_record('502', '1')
    # add_field_to_record('503', '1')

    return record