Initial commit, as generated by Rattail Demo

This commit is contained in:
Lance Edgar 2020-12-02 22:18:22 -06:00
commit e188096fe7
41 changed files with 1542 additions and 0 deletions

5
corporal/__init__.py Normal file
View file

@ -0,0 +1,5 @@
"""
Corporal package root
"""
from ._version import __version__

3
corporal/_version.py Normal file
View file

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

39
corporal/commands.py Normal file
View file

@ -0,0 +1,39 @@
"""
Corporal commands
"""
import sys
from rattail import commands
from corporal import __version__
def main(*args):
"""
Main entry point for Corporal command system
"""
args = list(args or sys.argv[1:])
cmd = Command()
cmd.run(*args)
class Command(commands.Command):
"""
Main command for Corporal
"""
name = 'corporal'
version = __version__
description = "Corporal (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")

20
corporal/config.py Normal file
View file

@ -0,0 +1,20 @@
"""
Custom config
"""
from rattail.config import ConfigExtension
class CorporalConfig(ConfigExtension):
"""
Rattail config extension for Corporal
"""
key = 'corporal'
def configure(self, config):
# set some default config values
config.setdefault('rattail.mail', 'emails', 'corporal.emails')
config.setdefault('rattail', 'settings', 'corporal.settings')
config.setdefault('tailbone', 'menus', 'corporal.web.menus')

View file

@ -0,0 +1,131 @@
############################################################
#
# base config for Corporal
#
############################################################
##############################
# rattail
##############################
[rattail]
# TODO: this will of course depend on your location
timezone.default = America/Chicago
# TODO: you should change these to absolute path
batch.files = app/batch
workdir = app/work
[rattail.config]
# include = /etc/rattail/rattail.conf
configure_logging = true
usedb = true
preferdb = true
[rattail.db]
default.url = postgresql://rattail:rattailpass@localhost/corporal
# TODO: disable if you do not want data versioning
versioning.enabled = true
[rattail.mail]
# TODO: enable this if you want emails to send
send_emails = false
smtp.server = localhost
templates = rattail:templates/mail
default.prefix = [Corporal]
default.from = rattail@localhost
default.to = root@localhost
# default.enabled = false
##############################
# alembic
##############################
[alembic]
script_location = rattail.db:alembic
version_locations = rattail.db:alembic/versions
##############################
# logging
##############################
[loggers]
keys = root, exc_logger, beaker, txn, sqlalchemy, django_db, flufl_bounce, requests
[handlers]
keys = file, console, email
[formatters]
keys = generic, console
[logger_root]
handlers = file, console
level = DEBUG
[logger_exc_logger]
qualname = exc_logger
handlers = email
level = ERROR
[logger_beaker]
qualname = beaker
handlers =
level = INFO
[logger_txn]
qualname = txn
handlers =
level = INFO
[logger_sqlalchemy]
qualname = sqlalchemy.engine
handlers =
# handlers = file
# level = INFO
[logger_django_db]
qualname = django.db.backends
handlers =
level = INFO
# level = DEBUG
[logger_flufl_bounce]
qualname = flufl.bounce
handlers =
level = WARNING
[logger_requests]
qualname = requests
handlers =
# level = WARNING
[handler_file]
class = handlers.RotatingFileHandler
# TODO: you probably should change this to absolute path
args = ('app/log/rattail.log', 'a', 1000000, 100, 'utf_8')
formatter = generic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
formatter = console
# formatter = generic
# level = INFO
# level = WARNING
[handler_email]
class = handlers.SMTPHandler
args = ('localhost', 'rattail@localhost', ['root@localhost'], "[Corporal] Logging")
formatter = generic
level = ERROR
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(funcName)s: %(message)s
datefmt = %Y-%m-%d %H:%M:%S
[formatter_console]
format = %(levelname)-5.5s [%(name)s][%(threadName)s] %(funcName)s: %(message)s

View file

@ -0,0 +1,71 @@
############################################################
#
# config for Corporal web app
#
############################################################
##############################
# rattail
##############################
[rattail.config]
include = %(here)s/rattail.conf
[tailbone]
products.print_labels = false
##############################
# pyramid
##############################
[app:main]
use = egg:Corporal
# TODO: you should probably disable these first two for production
pyramid.reload_templates = true
pyramid.debug_all = true
pyramid.default_locale_name = en
# pyramid.includes = pyramid_debugtoolbar
beaker.session.type = file
beaker.session.data_dir = %(here)s/sessions/data
beaker.session.lock_dir = %(here)s/sessions/lock
# TODO: you should change this
beaker.session.secret = XXXXXXXXXXXXXXXXXXXX
beaker.session.key = corporal
exclog.extra_info = true
# required for tailbone
rattail.config = %(__file__)s
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 9761
# NOTE: this is needed for local reverse proxy stuff to work with HTTPS
# https://docs.pylonsproject.org/projects/waitress/en/latest/reverse-proxy.html
# https://docs.pylonsproject.org/projects/waitress/en/latest/arguments.html
# trusted_proxy = 127.0.0.1
# TODO: leave this empty if proxy serves as root site, e.g. http://rattail.example.com/
# url_prefix =
# TODO: or, if proxy serves as subpath of root site, e.g. http://rattail.example.com/backend/
# url_prefix = /backend
##############################
# logging
##############################
[handler_console]
level = INFO
[handler_file]
# TODO: you probably should change this to absolute path
args = ('app/log/web.log', 'a', 1000000, 100, 'utf_8')

15
corporal/emails.py Normal file
View file

@ -0,0 +1,15 @@
# -*- coding: utf-8; -*-
"""
Custom email profiles
"""
from rattail.mail import Email
# bring in some common config from rattail
from rattail.emails import (ImporterEmail,
# ProblemReportEmail,
upgrade_failure,
upgrade_success,
user_feedback)

View file

@ -0,0 +1,8 @@
"""
Fabric library for Corporal
"""
from rattail_fabric2 import make_deploy
deploy_common = make_deploy(__file__)

View file

@ -0,0 +1,18 @@
#!/bin/bash
# This hook is run after a new virtualenv is created and before it is activated.
cat >$1/pip.conf <<EOF
[global]
extra-index-url =
https://pypi.rattailproject.org/simple/
log-file = $WORKON_HOME/$1/pip.log
exists-action = i
EOF
cat >$1/bin/postactivate <<EOF
export PIP_CONFIG_FILE=$WORKON_HOME/$1/pip.conf
EOF
cat >$1/bin/postdeactivate <<EOF
unset PIP_CONFIG_FILE
EOF

27
corporal/fablib/python.py Normal file
View file

@ -0,0 +1,27 @@
# -*- coding: utf-8; -*-
"""
Fabric library for Python
"""
from rattail_fabric2 import python as base
from corporal.fablib import make_deploy
deploy = make_deploy(__file__)
def bootstrap_python(c, workon_home='/srv/envs', user='rattail', **kwargs):
"""
Bootstrap a "complete" Python install.
"""
env = kwargs.pop('env')
# first do normal bootstrapping
kwargs['workon_home'] = workon_home
kwargs['user'] = user
base.bootstrap_python(c, **kwargs)
# customize the `premkvirtualenv` hook
deploy(c, 'python/premkvirtualenv.mako', '{}/premkvirtualenv'.format(workon_home),
owner=user, mode='0700', use_sudo=True, context={'env': env})

27
corporal/settings.py Normal file
View file

@ -0,0 +1,27 @@
# -*- coding: utf-8; -*-
"""
App Settings
"""
from rattail.settings import Setting
# bring in some common settings from rattail
from rattail.settings import (
# (General)
rattail_app_title,
tailbone_background_color,
# Email
rattail_mail_record_attempts,
# Product
rattail_product_key,
rattail_product_key_title,
tailbone_products_show_pod_image,
# Purchasing / Receiving
rattail_batch_purchase_allow_cases,
rattail_batch_purchase_allow_expired_credits,
)

0
corporal/web/__init__.py Normal file
View file

28
corporal/web/app.py Normal file
View file

@ -0,0 +1,28 @@
# -*- coding: utf-8; -*-
"""
Corporal web app
"""
from tailbone import app
def main(global_config, **settings):
"""
This function returns a Pyramid WSGI application.
"""
# prefer Corporal templates over Tailbone
settings.setdefault('mako.directories', ['corporal.web:templates',
'tailbone:templates'])
# make config objects
rattail_config = app.make_rattail_config(settings)
pyramid_config = app.make_pyramid_config(settings)
# maybe configure integration db connections
# bring in the rest of Corporal
pyramid_config.include('corporal.web.static')
pyramid_config.include('corporal.web.subscribers')
pyramid_config.include('corporal.web.views')
return pyramid_config.make_wsgi_app()

209
corporal/web/menus.py Normal file
View file

@ -0,0 +1,209 @@
# -*- coding: utf-8; -*-
"""
Corporal Web Menus
"""
def simple_menus(request):
url = request.route_url
people_menu = {
'title': "People",
'type': 'menu',
'items': [
{
'title': "Members",
'url': url('members'),
'perm': 'members.list',
},
{
'title': "Customers",
'url': url('customers'),
'perm': 'customers.list',
},
{
'title': "Customer Groups",
'url': url('customergroups'),
'perm': 'customergroups.list',
},
{
'title': "Employees",
'url': url('employees'),
'perm': 'employees.list',
},
{
'title': "All People",
'url': url('people'),
'perm': 'people.list',
},
],
}
products_menu = {
'title': "Products",
'type': 'menu',
'items': [
{
'title': "Products",
'url': url('products'),
'perm': 'products.list',
},
{
'title': "Departments",
'url': url('departments'),
'perm': 'departments.list',
},
{
'title': "Subdepartments",
'url': url('subdepartments'),
'perm': 'subdepartments.list',
},
{
'title': "Brands",
'url': url('brands'),
'perm': 'brands.list',
},
{
'title': "Families",
'url': url('families'),
'perm': 'families.list',
},
{
'title': "Report Codes",
'url': url('reportcodes'),
'perm': 'reportcodes.list',
},
],
}
vendors_menu = {
'title': "Vendors",
'type': 'menu',
'items': [
{
'title': "Vendors",
'url': url('vendors'),
'perm': 'vendors.list',
},
{'type': 'sep'},
{
'title': "Ordering",
'url': url('ordering'),
'perm': 'ordering.list',
},
{
'title': "Receiving",
'url': url('receiving'),
'perm': 'receiving.list',
},
{'type': 'sep'},
{
'title': "Purchases",
'url': url('purchases'),
'perm': 'purchases.list',
},
{
'title': "Credits",
'url': url('purchases.credits'),
'perm': 'purchases.credits.list',
},
# {'type': 'sep'},
# {
# 'title': "Catalogs",
# 'url': url('vendorcatalogs'),
# 'perm': 'vendorcatalogs.list',
# },
# {
# 'title': "Upload New Catalog",
# 'url': url('vendorcatalogs.create'),
# 'perm': 'vendorcatalogs.create',
# },
],
}
batches_menu = {
'title': "Batches",
'type': 'menu',
'items': [
{
'title': "Handheld",
'url': url('batch.handheld'),
'perm': 'batch.handheld.list',
},
# {
# 'title': "Inventory",
# 'url': url('batch.inventory'),
# 'perm': 'batch.inventory.list',
# },
],
}
admin_menu = {
'title': "Admin",
'type': 'menu',
'items': [
{
'title': "Stores",
'url': url('stores'),
'perm': 'stores.list',
},
{
'title': "Users",
'url': url('users'),
'perm': 'users.list',
},
{
'title': "User Events",
'url': url('userevents'),
'perm': 'userevents.list',
},
{
'title': "Roles",
'url': url('roles'),
'perm': 'roles.list',
},
{'type': 'sep'},
{
'title': "App Settings",
'url': url('appsettings'),
'perm': 'settings.list',
},
{
'title': "Email Settings",
'url': url('emailprofiles'),
'perm': 'emailprofiles.list',
},
{
'title': "Email Attempts",
'url': url('email_attempts'),
'perm': 'email_attempts.list',
},
{
'title': "Raw Settings",
'url': url('settings'),
'perm': 'settings.list',
},
{'type': 'sep'},
{
'title': "Tables",
'url': url('tables'),
'perm': 'tables.list',
},
{
'title': "Corporal Upgrades",
'url': url('upgrades'),
'perm': 'upgrades.list',
},
],
}
menus = [
people_menu,
products_menu,
vendors_menu,
batches_menu,
admin_menu,
]
return menus

View file

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

View file

@ -0,0 +1,16 @@
# -*- coding: utf-8; -*-
"""
Pyramid event subscribers
"""
import corporal
def add_corporal_to_context(event):
renderer_globals = event
renderer_globals['corporal'] = corporal
def includeme(config):
config.include('tailbone.subscribers')
config.add_subscriber(add_corporal_to_context, 'pyramid.events.BeforeRender')

View file

@ -0,0 +1,17 @@
# -*- coding: utf-8; mode: html; -*-
<%inherit file="tailbone:templates/base_meta.mako" />
<%def name="favicon()">
## <link rel="icon" type="image/x-icon" href="${request.static_url('corporal.web:static/favicon.ico')}" />
<link rel="icon" type="image/x-icon" href="${request.static_url('tailbone:static/img/rattail.ico')}" />
</%def>
<%def name="header_logo()">
${h.image(request.static_url('tailbone:static/img/rattail.ico'), "Header Logo", style="height: 49px;")}
</%def>
<%def name="footer()">
<p class="has-text-centered">
${h.link_to("Corporal {}{}".format(corporal.__version__, '' if request.rattail_config.production() else '+dev'), url('about'))}
</p>
</%def>

View file

@ -0,0 +1,46 @@
# -*- coding: utf-8; -*-
"""
Corporal Views
"""
def includeme(config):
# core views
config.include('corporal.web.views.common')
config.include('tailbone.views.auth')
config.include('tailbone.views.tables')
config.include('tailbone.views.upgrades')
config.include('tailbone.views.progress')
# main table views
config.include('tailbone.views.customergroups')
config.include('tailbone.views.datasync')
config.include('tailbone.views.email')
config.include('tailbone.views.families')
config.include('tailbone.views.members')
config.include('tailbone.views.messages')
config.include('tailbone.views.people')
config.include('tailbone.views.reportcodes')
config.include('tailbone.views.roles')
config.include('tailbone.views.settings')
config.include('tailbone.views.subdepartments')
config.include('tailbone.views.shifts')
config.include('tailbone.views.users')
config.include('tailbone.views.stores')
config.include('tailbone.views.customers')
config.include('tailbone.views.employees')
config.include('tailbone.views.taxes')
config.include('tailbone.views.departments')
config.include('tailbone.views.brands')
config.include('tailbone.views.vendors')
config.include('tailbone.views.products')
# purchasing / receiving
config.include('tailbone.views.purchases')
config.include('tailbone.views.purchasing')
# batch views
config.include('tailbone.views.handheld')
config.include('tailbone.views.batch.inventory')

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8; -*-
"""
Common views
"""
from tailbone.views import common as base
import corporal
class CommonView(base.CommonView):
project_title = "Corporal"
project_version = corporal.__version__ + '+dev'
def includeme(config):
CommonView.defaults(config)