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

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
tailbone_nationbuilder.egg-info/

10
CHANGELOG.md Normal file
View file

@ -0,0 +1,10 @@
# Changelog
All notable changes to tailbone-nationbuilder will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [0.1.0] - ??
### Added
- Initial version.

3
MANIFEST.in Normal file
View file

@ -0,0 +1,3 @@
include *.md
include *.rst
recursive-include tailbone_nationbuilder/templates *.mako

11
README.md Normal file
View file

@ -0,0 +1,11 @@
# tailbone-nationbuilder
Rattail is a retail software framework, released under the GNU General
Public License.
This package contains software interfaces for
[NationBuilder](https://nationbuilder.com/).
Please see the [Rattail Project](https://rattailproject.org/)
for more information.

37
setup.cfg Normal file
View file

@ -0,0 +1,37 @@
# -*- coding: utf-8; -*-
[metadata]
name = tailbone-nationbuilder
version = attr: tailbone_nationbuilder.__version__
author = Lance Edgar
author_email = lance@edbob.org
url = https://rattailproject.org/
license = GNU GPL v3
description = Tailbone integration package for NationBuilder
long_description = file: README.md
classifiers =
Development Status :: 4 - Beta
Environment :: Web Environment
Framework :: Pyramid
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Topic :: Office/Business
Topic :: Software Development :: Libraries :: Python Modules
[options]
install_requires =
Tailbone
packages = find:
include_package_data = True
[options.entry_points]
tailbone.providers =
tailbone_nationbuilder = tailbone_nationbuilder.provider:TailboneNationBuilderProvider

29
setup.py Normal file
View file

@ -0,0 +1,29 @@
# -*- 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 setup script
"""
from setuptools import setup
setup()

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)

51
tasks.py Normal file
View file

@ -0,0 +1,51 @@
# -*- 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/>.
#
################################################################################
"""
Tasks for tailbone-nationbuilder
"""
import os
import shutil
from invoke import task
here = os.path.abspath(os.path.dirname(__file__))
exec(open(os.path.join(here, 'tailbone_nationbuilder', '_version.py')).read())
@task
def release(c):
"""
Release a new version of tailbone-nationbuilder
"""
# rebuild local tar.gz file for distribution
if os.path.exists('tailbone_nationbuilder.egg-info'):
shutil.rmtree('tailbone_nationbuilder.egg-info')
c.run('python -m build --sdist')
# filename of built package
filename = f'tailbone-nationbuilder-{__version__}.tar.gz'
# upload to PyPI
c.run(f'twine upload dist/{filename}')