Add first version of project template

For use with Pyramid scaffold system, i.e.:

  pcreate -s rattail mynewproject

Note however that the Tailbone project registers the template, this is
*not* done within this (rattail) project because we don't require
Pyramid at this level.
This commit is contained in:
Lance Edgar 2016-10-07 19:01:40 -05:00
parent 7b596ab0cf
commit a1b50dd32e
22 changed files with 573 additions and 0 deletions

View file

@ -0,0 +1,8 @@
# -*- coding: utf-8; mode: python -*-
"""
{{project}} package root
"""
from __future__ import unicode_literals, absolute_import
from ._version import __version__

View file

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

View file

@ -0,0 +1,42 @@
# -*- coding: utf-8; mode: python -*-
"""
{{project}} commands
"""
from __future__ import unicode_literals, absolute_import
import sys
from rattail import commands
from {{package}} import __version__
def main(*args):
"""
Main entry point for {{project}} command system
"""
args = list(args or sys.argv[1:])
cmd = Command()
cmd.run(*args)
class Command(commands.Command):
"""
Main command for {{project}}
"""
name = '{{package}}'
version = __version__
description = "{{project}} (custom Rattail system)"
long_description = ''
class HelloWorld(commands.Subcommand):
"""
The requisite 'hello world' example
"""
name = 'hello'
description = __doc__.strip()
def run(self, args):
self.stdout.write("hello world!\n")

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8; mode: python -*-
"""
Rattail config extension
"""
from __future__ import unicode_literals, absolute_import
from rattail.config import ConfigExtension
class {{package}}Config(ConfigExtension):
"""
Rattail config extension for {{project}}.
"""
key = '{{package}}'
def configure(self, config):
# set some default config values
config.setdefault('rattail.mail', 'emails', '{{package}}.emails')

View file

@ -0,0 +1 @@
Generic single-database configuration.

View file

@ -0,0 +1,71 @@
# -*- coding: utf-8; mode: python -*-
"""
Alembic environment script
"""
from __future__ import unicode_literals, absolute_import
from alembic import context
from rattail.config import make_config
from rattail.db.util import get_default_engine
from {{package}}.db import model
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
alembic_config = context.config
# use same config file for Rattail
rattail_config = make_config(alembic_config.config_file_name, usedb=False)
# needed for 'autogenerate' support
target_metadata = model.Base.metadata
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
engine = get_default_engine(rattail_config)
context.configure(
url=engine.url,
target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = get_default_engine(rattail_config)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from __future__ import unicode_literals, absolute_import
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
from alembic import op
import sqlalchemy as sa
import rattail.db.types
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View file

@ -0,0 +1,12 @@
# -*- coding: utf-8; mode: python -*-
"""
{{project}} data models
"""
from __future__ import unicode_literals, absolute_import
# bring in all the normal stuff from rattail
from rattail.db.model import *
# add custom models as needed
from .core import {{package}}Customer

View file

@ -0,0 +1,43 @@
# -*- coding: utf-8; mode: python -*-
"""
Rattail core data model extensions
"""
from __future__ import unicode_literals, absolute_import
import sqlalchemy as sa
from sqlalchemy import orm
from rattail.db import model
from rattail.db.core import uuid_column
class {{package}}Customer(model.Base):
"""
{{project}} extensions to core ``Customer`` model.
"""
__tablename__ = '{{package}}_customer'
__table_args__ = (
sa.ForeignKeyConstraint(['uuid'], ['customer.uuid'], name='{{package}}_customer_fk_customer'),
)
uuid = uuid_column(default=None)
customer = orm.relationship(
model.Customer,
doc="""
Customer to which this extension record pertains.
""",
backref=orm.backref(
'_{{package}}',
uselist=False,
cascade='all, delete-orphan',
doc="""
{{project}}-specific extension record for the customer.
"""),
)
mail_list_synced = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
Flag indicating whether the customer's email address has been synced to the
general mailing list.
""")

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8; mode: python -*-
"""
Custom email profiles
"""
from __future__ import unicode_literals, absolute_import
from rattail.mail import Email
# bring in some common ones from rattail
from rattail.emails import datasync_error_watcher_get_changes, filemon_action_error
class rattail_import_sample_updates(Email):
"""
Sent when a Sample -> {{project}} import involves data changes.
"""
fallback_key = 'rattail_import_updates'
default_subject = "Changes from Sample -> {{project}} data import"

View file

@ -0,0 +1,35 @@
# -*- coding: utf-8; mode: python -*-
"""
{{project}} web app
"""
from __future__ import unicode_literals, absolute_import
from tailbone import app
def main(global_config, **settings):
"""
This function returns a Pyramid WSGI application.
"""
# set some defaults for PostgreSQL
app.provide_postgresql_settings(settings)
# prefer {{project}} templates over Tailbone; use 'better' theme
settings.setdefault('mako.directories', ['{{package}}.web:templates',
'tailbone:templates/themes/better',
'tailbone:templates',])
# make config objects
rattail_config = app.make_rattail_config(settings)
pyramid_config = app.make_pyramid_config(settings)
# bring in the rest of {{project}}
pyramid_config.include('{{package}}.web.static')
pyramid_config.include('{{package}}.web.subscribers')
pyramid_config.include('{{package}}.web.views')
# configure PostgreSQL some more
app.configure_postgresql(pyramid_config)
return pyramid_config.make_wsgi_app()

View file

@ -0,0 +1,9 @@
# -*- coding: utf-8; mode: python -*-
"""
Static assets
"""
def includeme(config):
config.include('tailbone.static')
config.add_static_view('{{package}}', '{{package}}.web:static', cache_max_age=3600)

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8; mode: python -*-
"""
Pyramid event subscribers
"""
from __future__ import unicode_literals, absolute_import
import {{package}}
def add_{{package}}_to_context(event):
renderer_globals = event
renderer_globals['{{package}}'] = {{package}}
def includeme(config):
config.include('tailbone.subscribers')
config.add_subscriber(add_{{package}}_to_context, 'pyramid.events.BeforeRender')

View file

@ -0,0 +1,139 @@
## -*- coding: utf-8 -*-
<%def name="main_menu_items()">
% if request.has_any_perm('schedule.view', 'timesheet.view'):
<li>
<a>Time Clock</a>
<ul>
% if request.has_perm('schedule.view'):
<li>${h.link_to("Employee Schedule", url('schedule.employee'))}</li>
% endif
% if request.has_perm('timesheet.view'):
<li>${h.link_to("Employee Time Sheet", url('timesheet.employee'))}</li>
% endif
% if request.has_any_perm('schedule.viewall', 'timesheet.viewall'):
<li>-</li>
% if request.has_perm('schedule.viewall'):
<li>${h.link_to("Full Schedule", url('schedule'))}</li>
% endif
% if request.has_perm('timesheet.viewall'):
<li>${h.link_to("Full Time Sheet", url('timesheet'))}</li>
% endif
% endif
</ul>
</li>
% endif
<li>
<a>Products</a>
<ul>
% if request.has_perm('products.list'):
<li>${h.link_to("Products", url('products'))}</li>
% endif
% if request.has_perm('brands.list'):
<li>${h.link_to("Brands", url('brands'))}</li>
% endif
% if request.has_perm('families.list'):
<li>${h.link_to("Families", url('families'))}</li>
% endif
% if request.has_perm('reportcodes.list'):
<li>${h.link_to("Report Codes", url('reportcodes'))}</li>
% endif
</ul>
</li>
<li>
<a>Vendors</a>
<ul>
<li>${h.link_to("Vendors", url('vendors'))}</li>
% if request.has_any_perm('vendorcatalogs.list', 'vendorcatalogs.create'):
<li>-</li>
% if request.has_perm('vendorcatalogs.list'):
<li>${h.link_to("Catalogs", url('vendorcatalogs'))}</li>
% endif
% if request.has_perm('vendorcatalogs.create'):
<li>${h.link_to("Upload New Catalog", url('vendorcatalogs.create'))}</li>
% endif
% endif
</ul>
</li>
<li>
<a>Company</a>
<ul>
<li>${h.link_to("Stores", url('stores'))}</li>
<li>${h.link_to("Departments", url('departments'))}</li>
<li>${h.link_to("Subdepartments", url('subdepartments'))}</li>
<li>-</li>
<li>${h.link_to("Employees", url('employees'))}</li>
<li>-</li>
<li>${h.link_to("Customers", url('customers'))}</li>
% if request.has_perm('customergroups.list'):
<li>${h.link_to("Customer Groups", url('customergroups'))}</li>
% endif
</ul>
</li>
<li>
<a>Reports</a>
<ul>
<li>${h.link_to("Ordering Worksheet", url('reports.ordering'))}</li>
<li>${h.link_to("Inventory Worksheet", url('reports.inventory'))}</li>
</ul>
</li>
% if request.has_any_perm('batch.handheld.list', 'batch.inventory.list'):
<li>
<a>Batches</a>
<ul>
% if request.has_perm('batch.handheld.list'):
<li>${h.link_to("Handheld", url('batch.handheld'))}</li>
% endif
% if request.has_perm('batch.inventory.list'):
<li>${h.link_to("Inventory", url('batch.inventory'))}</li>
% endif
</ul>
</li>
% endif
% if request.has_any_perm('users.list', 'roles.list', 'labelprofiles.list', 'settings.list', 'emailprofiles.list', 'datasyncchanges.list'):
<li>
<a>Admin</a>
<ul>
% if request.has_perm('users.list'):
<li>${h.link_to("Users", url('users'))}</li>
% endif
% if request.has_perm('roles.list'):
<li>${h.link_to("Roles", url('roles'))}</li>
% endif
% if request.has_perm('labelprofiles.list'):
<li>${h.link_to("Label Profiles", url('labelprofiles'))}</li>
% endif
% if request.has_perm('settings.list'):
<li>${h.link_to("Settings", url('settings'))}</li>
% endif
% if request.has_perm('emailprofiles.list'):
<li>${h.link_to("Email Profiles", url('emailprofiles'))}</li>
% endif
% if request.has_perm('datasyncchanges.list'):
<li>${h.link_to("DataSync Changes", url('datasyncchanges'))}</li>
% endif
</ul>
</li>
% endif
% if request.user:
<li>
<a>${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
<ul>
<li>${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'))}</li>
<li>${h.link_to("Change Password", url('change_password'))}</li>
<li>${h.link_to("Logout", url('logout'))}</li>
</ul>
</li>
% else:
<li>${h.link_to("Login", url('login'))}</li>
% endif
</%def>

View file

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
Views
"""
from __future__ import unicode_literals, absolute_import
def includeme(config):
config.include('tailbone.views')

View file

@ -0,0 +1 @@
{{project}}.egg-info/

View file

@ -0,0 +1,8 @@
# -*- mode: conf -*-
include *.rst
recursive-include {{package}}/web/static *.css
recursive-include {{package}}/web/static *.js
recursive-include {{package}}/web/templates *.mako

View file

@ -0,0 +1,8 @@
.. -*- mode: rst -*-
{{project}}
===========
This is a starter Rattail project. See the `Rattail website`_ for more info.
.. _`Rattail website`: https://rattailproject.org/

View file

@ -0,0 +1,96 @@
# -*- coding: utf-8; mode: python -*-
"""
{{project}} setup script
"""
from __future__ import unicode_literals, absolute_import
import os
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
execfile(os.path.join(here, '{{package}}', '_version.py'))
README = open(os.path.join(here, 'README.rst')).read()
requires = [
#
# Version numbers within comments below have specific meanings.
# Basically the 'low' value is a "soft low," and 'high' a "soft high."
# In other words:
#
# If either a 'low' or 'high' value exists, the primary point to be
# made about the value is that it represents the most current (stable)
# version available for the package (assuming typical public access
# methods) whenever this project was started and/or documented.
# Therefore:
#
# If a 'low' version is present, you should know that attempts to use
# versions of the package significantly older than the 'low' version
# may not yield happy results. (A "hard" high limit may or may not be
# indicated by a true version requirement.)
#
# Similarly, if a 'high' version is present, and especially if this
# project has laid dormant for a while, you may need to refactor a bit
# when attempting to support a more recent version of the package. (A
# "hard" low limit should be indicated by a true version requirement
# when a 'high' version is present.)
#
# In any case, developers and other users are encouraged to play
# outside the lines with regard to these soft limits. If bugs are
# encountered then they should be filed as such.
#
# package # low high
'psycopg2', # 2.6.2
'rattail', # 0.7.25
'Tailbone', # 0.5.29
]
setup(
name = "{{project}}",
version = __version__,
author = "Your Name",
author_email = "you@example.com",
# url = "",
description = "Rattail project for Your Company",
long_description = README,
classifiers = [
'Private :: Do No Upload',
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Environment :: Web Environment',
'Framework :: Pyramid',
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Topic :: Office/Business',
],
install_requires = requires,
packages = find_packages(),
entry_points = {
'rattail.config.extensions': [
'{{package}} = {{package}}.config:{{package}}Config',
],
'console_scripts': [
'{{package}} = {{package}}.commands:main',
],
'{{package}}.commands': [
'hello = {{package}}.commands:HelloWorld',
],
'paste.app_factory': [
'main = {{package}}.web.app:main',
],
},
)