Add cache table, importer for NationBuilder People
This commit is contained in:
parent
93af35eb4e
commit
c3b93edd4d
13 changed files with 562 additions and 2 deletions
27
rattail_nationbuilder/importing/__init__.py
Normal file
27
rattail_nationbuilder/importing/__init__.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-nationbuilder importing
|
||||
"""
|
||||
|
||||
from . import model
|
36
rattail_nationbuilder/importing/model.py
Normal file
36
rattail_nationbuilder/importing/model.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-nationbuilder model importers
|
||||
"""
|
||||
|
||||
from rattail.importing.model import ToRattail
|
||||
from rattail_nationbuilder.db import model
|
||||
|
||||
|
||||
##############################
|
||||
# nationbuilder cache
|
||||
##############################
|
||||
|
||||
class NationBuilderCachePersonImporter(ToRattail):
|
||||
model_class = model.NationBuilderCachePerson
|
132
rattail_nationbuilder/importing/nationbuilder.py
Normal file
132
rattail_nationbuilder/importing/nationbuilder.py
Normal file
|
@ -0,0 +1,132 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
NationBuilder -> Rattail importing
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
from rattail import importing
|
||||
from rattail_nationbuilder import importing as nationbuilder_importing
|
||||
from rattail_nationbuilder.nationbuilder.webapi import NationBuilderWebAPI
|
||||
|
||||
|
||||
class FromNationBuilderToRattail(importing.ToRattailHandler):
|
||||
"""
|
||||
Import handler for NationBuilder -> Rattail
|
||||
"""
|
||||
host_key = 'nationbuilder'
|
||||
host_title = "NationBuilder"
|
||||
generic_host_title = "NationBuilder"
|
||||
|
||||
def get_importers(self):
|
||||
importers = OrderedDict()
|
||||
importers['NationBuilderCachePerson'] = NationBuilderCachePersonImporter
|
||||
return importers
|
||||
|
||||
|
||||
class FromNationBuilder(importing.Importer):
|
||||
"""
|
||||
Base class for all NationBuilder importers
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
super().setup()
|
||||
self.setup_api()
|
||||
|
||||
def setup_api(self):
|
||||
self.nationbuilder = NationBuilderWebAPI(self.config)
|
||||
|
||||
|
||||
class NationBuilderCachePersonImporter(FromNationBuilder, nationbuilder_importing.model.NationBuilderCachePersonImporter):
|
||||
"""
|
||||
Importer for NB Person cache
|
||||
"""
|
||||
key = 'id'
|
||||
|
||||
primary_address_fields = [
|
||||
'primary_address_address1',
|
||||
'primary_address_address2',
|
||||
'primary_address_city',
|
||||
'primary_address_state',
|
||||
'primary_address_zip',
|
||||
]
|
||||
|
||||
supported_fields = [
|
||||
'id',
|
||||
'created_at',
|
||||
'email',
|
||||
'email_opt_in',
|
||||
'external_id',
|
||||
'first_name',
|
||||
'middle_name',
|
||||
'last_name',
|
||||
'mobile',
|
||||
'mobile_opt_in',
|
||||
'note',
|
||||
'phone',
|
||||
'primary_image_url_ssl',
|
||||
'signup_type',
|
||||
'tags',
|
||||
'updated_at',
|
||||
] + primary_address_fields
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.nationbuilder.get_people(page_size=500)
|
||||
|
||||
def normalize_timestamp(self, value):
|
||||
if not value:
|
||||
return
|
||||
|
||||
dt = datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S%z')
|
||||
dt = self.app.localtime(dt)
|
||||
return self.app.make_utc(dt)
|
||||
|
||||
def normalize_host_object(self, person):
|
||||
|
||||
# nb. some fields may not be present in person dict
|
||||
data = dict([(field, person.get(field))
|
||||
for field in self.fields])
|
||||
if data:
|
||||
|
||||
for field in ('created_at', 'updated_at'):
|
||||
data[field] = self.normalize_timestamp(data[field])
|
||||
|
||||
if 'tags' in self.fields:
|
||||
tags = data['tags']
|
||||
if tags:
|
||||
data['tags'] = self.config.make_list_string(tags)
|
||||
|
||||
if self.fields_active(self.primary_address_fields):
|
||||
address = person.get('primary_address')
|
||||
if address:
|
||||
data.update({
|
||||
'primary_address_address1': address['address1'],
|
||||
'primary_address_address2': address['address2'],
|
||||
'primary_address_state': address['state'],
|
||||
'primary_address_city': address['city'],
|
||||
'primary_address_zip': address['zip'],
|
||||
})
|
||||
|
||||
return data
|
41
rattail_nationbuilder/importing/versions.py
Normal file
41
rattail_nationbuilder/importing/versions.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2023 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-nationbuilder version importing
|
||||
"""
|
||||
|
||||
from rattail.importing import versions as base
|
||||
|
||||
|
||||
class NationBuilderVersionMixin(object):
|
||||
|
||||
def add_nationbuilder_importers(self, importers):
|
||||
importers['NationBuilderCachePerson'] = NationBuilderCachePersonImporter
|
||||
return importers
|
||||
|
||||
|
||||
class NationBuilderCachePersonImporter(base.VersionImporter):
|
||||
|
||||
@property
|
||||
def host_model_class(self):
|
||||
return self.model.NationBuilderCachePerson
|
Loading…
Add table
Add a link
Reference in a new issue