Initial version, to expose NationBuilder cache tables

This commit is contained in:
Lance Edgar 2023-09-12 18:20:15 -05:00
commit 87dcb51600
16 changed files with 463 additions and 0 deletions

View 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/>.
#
################################################################################
"""
tailbone-nationbuilder package root
"""
from ._version import __version__

View file

@ -0,0 +1,3 @@
# -*- coding: utf-8; -*-
__version__ = '0.1.0'

View file

@ -0,0 +1,56 @@
# -*- 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/>.
#
################################################################################
"""
Common menus for NationBuilder
"""
from rattail_nationbuilder.nationbuilder.util import get_nationbuilder_url
def make_nationbuilder_menu(request):
url = request.route_url
nationbuilder_menu = {
'title': "NationBuilder",
'type': 'menu',
'items': [
{
'title': "People",
'route': 'nationbuilder.cache.people',
'perm': 'nationbuilder.cache.people.list',
},
],
}
url = get_nationbuilder_url(request.rattail_config)
if url:
nationbuilder_menu['items'].insert(
0, {
'title': "Go to NationBuilder",
'url': f'{url}/admin/',
'target': '_blank',
})
nationbuilder_menu['items'].insert(
1, {'type': 'sep'})
return nationbuilder_menu

View file

@ -0,0 +1,38 @@
# -*- 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/>.
#
################################################################################
"""
Tailbone Provider for NationBuilder Integration
"""
from tailbone.providers import TailboneProvider
class TailboneNationBuilderProvider(TailboneProvider):
"""
View provider for tailbone-nationbuilder
"""
key = 'tailbone_nationbuilder'
def make_integration_menu(self, request, **kwargs):
from tailbone_nationbuilder.menus import make_nationbuilder_menu
return make_nationbuilder_menu(request)

View file

View file

View file

@ -0,0 +1,37 @@
# -*- 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 Views
"""
from .master import NationBuilderMasterView
def defaults(config, **kwargs):
mod = lambda spec: kwargs.get(spec, spec)
config.include(mod('tailbone_nationbuilder.views.nationbuilder.people'))
def includeme(config):
defaults(config)

View file

@ -0,0 +1,33 @@
# -*- 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 cache master view
"""
from tailbone.views import MasterView
class NationBuilderMasterView(MasterView):
"""
Base class for NationBuilder cache master views
"""

View file

@ -0,0 +1,127 @@
# -*- 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 Cache Person views
"""
from rattail_nationbuilder.db.model import NationBuilderCachePerson
from webhelpers2.html import HTML
from .master import NationBuilderMasterView
class NationBuilderCachePersonView(NationBuilderMasterView):
"""
Master view for NationBuilder Users
"""
model_class = NationBuilderCachePerson
url_prefix = '/nationbuilder/cache/people'
route_prefix = 'nationbuilder.cache.people'
has_versions = True
labels = {
'id': "ID",
'external_id': "External ID",
'primary_image_url_ssl': "Primary Image URL",
'primary_address_address1': "Address 1",
'primary_address_address2': "Address 2",
'primary_address_city': "City",
'primary_address_state': "State",
'primary_address_zip': "Zip",
}
grid_columns = [
'id',
'external_id',
'first_name',
'last_name',
'email',
'mobile',
'updated_at',
]
form_fields = [
'id',
'signup_type',
'external_id',
'first_name',
'middle_name',
'last_name',
'email',
'email_opt_in',
'mobile',
'mobile_opt_in',
'phone',
'primary_address_address1',
'primary_address_address2',
'primary_address_city',
'primary_address_state',
'primary_address_zip',
'primary_image_url_ssl',
'tags',
'note',
'created_at',
'updated_at',
]
def configure_grid(self, g):
super().configure_grid(g)
g.set_link('external_id')
if 'external_id' in g.filters:
g.filters['external_id'].default_active = True
g.filters['external_id'].default_verb = 'contains'
g.set_link('id')
g.set_link('first_name')
g.set_link('last_name')
g.set_link('email')
g.set_sort_defaults('updated_at', 'desc')
def render_tags(self, person, field):
tags = getattr(person, field)
if not tags:
return
items = []
for tag in self.rattail_config.parse_list(tags):
items.append(HTML.tag('li', c=[tag]))
return HTML.tag('ul', c=items)
def configure_form(self, f):
super().configure_form(f)
f.set_renderer('tags', self.render_tags)
def defaults(config, **kwargs):
base = globals()
NationBuilderCachePersonView = kwargs.get('NationBuilderCachePersonView', base['NationBuilderCachePersonView'])
NationBuilderCachePersonView.defaults(config)
def includeme(config):
defaults(config)