More standalone operation stuff.

Stop using `edbob.db.engine`, stop using all edbob templates, etc.
This commit is contained in:
Lance Edgar 2013-09-01 20:25:34 -07:00
parent 2a50e704ef
commit 7d19700c3c
22 changed files with 438 additions and 54 deletions

View file

@ -35,7 +35,7 @@ from ..forms.simpleform import FormRenderer
import edbob
from ..db import Session
from edbob.db.auth import authenticate_user, set_user_password
from rattail.db.auth import authenticate_user, set_user_password
class UserLogin(formencode.Schema):
@ -58,9 +58,9 @@ def login(request):
form = Form(request, schema=UserLogin)
if form.validate():
user = authenticate_user(form.data['username'],
form.data['password'],
session=Session())
user = authenticate_user(Session(),
form.data['username'],
form.data['password'])
if user:
request.session.flash("%s logged in at %s" % (
user.display_name,

View file

@ -26,12 +26,11 @@
Batch Row Views
"""
from .. import SearchableAlchemyGridView, CrudView
from pyramid.httpexceptions import HTTPFound
from ...db import Session
from .. import SearchableAlchemyGridView, CrudView
import rattail
from rattail.db.model import Batch, LabelProfile
from ...forms import GPCFieldRenderer
@ -41,8 +40,8 @@ def field_with_renderer(field, column):
field = field.with_renderer(GPCFieldRenderer)
elif column.sil_name == 'F95': # Shelf Tag Type
q = Session.query(rattail.LabelProfile)
q = q.order_by(rattail.LabelProfile.ordinal)
q = Session.query(LabelProfile)
q = q.order_by(LabelProfile.ordinal)
field = field.dropdown(options=[(x.description, x.code) for x in q])
return field
@ -50,7 +49,7 @@ def field_with_renderer(field, column):
def BatchRowsGrid(request):
uuid = request.matchdict['uuid']
batch = Session.query(rattail.Batch).get(uuid) if uuid else None
batch = Session.query(Batch).get(uuid) if uuid else None
if not batch:
return HTTPFound(location=request.route_url('batches'))
@ -141,7 +140,7 @@ def batch_rows_delete(request):
def batch_row_crud(request, attr):
batch_uuid = request.matchdict['batch_uuid']
batch = Session.query(rattail.Batch).get(batch_uuid)
batch = Session.query(Batch).get(batch_uuid)
if not batch:
return HTTPFound(location=request.route_url('batches'))

View file

@ -26,43 +26,121 @@
Role Views
"""
from . import SearchableAlchemyGridView, CrudView
from pyramid.httpexceptions import HTTPFound
from ..db import Session
from rattail.db.model import Role
from rattail.db.auth import has_permission, administrator_role, guest_role
import formalchemy
from webhelpers.html import tags
from webhelpers.html.builder import HTML
from edbob.db import auth
from ..db import Session
from . import SearchableAlchemyGridView, CrudView
from rattail.db.model import Role
from webhelpers.html import HTML
default_permissions = [
("Batches", [
('batches.list', "List Batches"),
('batches.read', "View Batches"),
('batches.create', "Create Batches"),
('batches.update', "Edit Batches"),
('batches.delete', "Delete Batches"),
('batches.execute', "Execute Batches"),
('batch_rows.read', "View Batch Rows"),
('batch_rows.update', "Edit Batch Rows"),
('batch_rows.delete', "Delete Batch Rows"),
]),
("Brands", [
('brands.list', "List Brands"),
('brands.read', "View Brands"),
('brands.create', "Create Brands"),
('brands.update', "Edit Brands"),
('brands.delete', "Delete Brands"),
('brands.force_sync', "Forcibly Sync Brands"),
]),
("Customers", [
('customers.list', "List Customers"),
('customers.read', "View Customers"),
('customers.force_sync', "Forcibly Sync Customers"),
('customer_groups.list', "List Customer Groups"),
('customer_groups.read', "View Customer Groups"),
('customer_groups.force_sync', "Forcibly Sync Customer Groups"),
]),
("Departments", [
('departments.list', "List Departments"),
('departments.read', "View Departments"),
('departments.create', "Create Departments"),
('departments.update', "Edit Departments"),
('departments.delete', "Delete Departments"),
('departments.force_sync', "Forcibly Sync Departments"),
]),
("Employees", [
('employees.list', "List Employees"),
('employees.force_sync', "Forcibly Sync Employees"),
]),
("Label Profiles", [
('label_profiles.list', "List Label Profiles"),
('label_profiles.view', "View Label Profiles"),
('label_profiles.create', "Create Label Profiles"),
('label_profiles.update', "Edit Label Profiles"),
('label_profiles.delete', "Delete Label Profiles"),
]),
("People", [
('people.list', "List People"),
('people.read', "View Person"),
('people.create', "Create Person"),
('people.update', "Edit Person"),
('people.delete', "Delete Person"),
('people.list', "List People"),
('people.read', "View People"),
('people.create', "Create People"),
('people.update', "Edit People"),
('people.delete', "Delete People"),
('people.force_sync', "Forcibly Sync People"),
]),
("Products", [
('products.list', "List Products"),
('products.read', "View Products"),
('products.create', "Create Products"),
('products.update', "Edit Products"),
('products.delete', "Delete Products"),
('products.print_labels', "Print Product Labels"),
('products.force_sync', "Forcibly Sync Products"),
]),
("Roles", [
('roles.list', "List Roles"),
('roles.read', "View Role"),
('roles.create', "Create Role"),
('roles.update', "Edit Role"),
('roles.delete', "Delete Role"),
('roles.list', "List Roles"),
('roles.read', "View Roles"),
('roles.create', "Create Roles"),
('roles.update', "Edit Roles"),
('roles.delete', "Delete Roles"),
]),
("Stores", [
('stores.list', "List Stores"),
('stores.read', "View Stores"),
('stores.create', "Create Stores"),
('stores.update', "Edit Stores"),
('stores.delete', "Delete Stores"),
('stores.force_sync', "Forcibly Sync Stores"),
]),
("Subdepartments", [
('subdepartments.list', "List Subdepartments"),
('subdepartments.read', "View Subdepartments"),
('subdepartments.create', "Create Subdepartments"),
('subdepartments.update', "Edit Subdepartments"),
('subdepartments.delete', "Delete Subdepartments"),
('subdepartments.force_sync', "Forcibly Sync Subdepartments"),
]),
("Users", [
('users.list', "List Users"),
('users.read', "View User"),
('users.create', "Create User"),
('users.update', "Edit User"),
('users.delete', "Delete User"),
('users.list', "List Users"),
('users.read', "View Users"),
('users.create', "Create Users"),
('users.update', "Edit Users"),
('users.delete', "Delete Users"),
('users.force_sync', "Forcibly Sync Users"),
]),
("Vendors", [
('vendors.list', "List Vendors"),
('vendors.read', "View Vendors"),
('vendors.create', "Create Vendors"),
('vendors.update', "Edit Vendors"),
('vendors.delete', "Delete Vendors"),
('vendors.import_catalog', "Import Vendor Catalogs"),
('vendors.force_sync', "Forcibly Sync Vendors"),
]),
]
@ -129,7 +207,7 @@ def PermissionsFieldRenderer(permissions, *args, **kwargs):
def _render(self, readonly=False, **kwargs):
role = self.field.model
admin = auth.administrator_role(Session())
admin = administrator_role(Session())
if role is admin:
html = HTML.tag('p', c="This is the administrative role; "
"it has full access to the entire system.")
@ -140,8 +218,8 @@ def PermissionsFieldRenderer(permissions, *args, **kwargs):
for group, perms in self.permissions:
inner = HTML.tag('p', c=group)
for perm, title in perms:
checked = auth.has_permission(
role, perm, include_guest=False, session=Session())
checked = has_permission(
Session(), role, perm, include_guest=False)
if readonly:
span = HTML.tag('span', c="[X]" if checked else "[ ]")
inner += HTML.tag('p', class_='perm', c=span + ' ' + title)
@ -179,8 +257,8 @@ class RoleCrud(CrudView):
return fs
def pre_delete(self, model):
admin = auth.administrator_role(Session())
guest = auth.guest_role(Session())
admin = administrator_role(Session())
guest = guest_role(Session())
if model in (admin, guest):
self.request.session.flash("You may not delete the %s role." % str(model), 'error')
return HTTPFound(location=self.request.get_referrer())

View file

@ -35,7 +35,7 @@ from . import SearchableAlchemyGridView, CrudView
from ..forms import PersonFieldRenderer
from ..db import Session
from rattail.db.model import User, Person, Role
from edbob.db.auth import guest_role
from rattail.db.auth import guest_role
from webhelpers.html import tags
from webhelpers.html import HTML