Initial tests.
This doesn't add much in the way of useful tests but it should pave the way for more. Tests may be run like so: {{{ python setup.py nosetests --with-coverage }}}
This commit is contained in:
parent
4174e6d77d
commit
84225f00e1
53
rattail/pyramid/tests/__init__.py
Normal file
53
rattail/pyramid/tests/__init__.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from pyramid import testing
|
||||||
|
|
||||||
|
|
||||||
|
class TestCase(unittest.TestCase):
|
||||||
|
"""
|
||||||
|
Base class for all test suites.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.config = testing.setUp()
|
||||||
|
# self.config = testing.setUp(settings={
|
||||||
|
# 'mako.directories': [
|
||||||
|
# 'rattail.pyramid:templates',
|
||||||
|
# 'edbob.pyramid:templates',
|
||||||
|
# ],
|
||||||
|
# })
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
testing.tearDown()
|
||||||
|
|
||||||
|
|
||||||
|
# class DataTestCase(TestCase):
|
||||||
|
# """
|
||||||
|
# Base class for all test suites which require fixture data.
|
||||||
|
# """
|
||||||
|
|
||||||
|
# def setUp(self):
|
||||||
|
# from sqlalchemy import create_engine
|
||||||
|
# from edbob import db
|
||||||
|
# from rattail.pyramid import Session
|
||||||
|
# from edbob.db.util import install_core_schema
|
||||||
|
# from edbob.db.extensions import activate_extension
|
||||||
|
# from rattail.pyramid.tests.fixtures import load_fixtures
|
||||||
|
|
||||||
|
# engine = create_engine('postgresql://rattail:1pKglVgdHOP1MYGVdUZr@localhost/rattail.test')
|
||||||
|
|
||||||
|
# db.engines = {'default': engine}
|
||||||
|
# db.engine = engine
|
||||||
|
# db.Session.configure(bind=engine)
|
||||||
|
# Session.configure(bind=engine)
|
||||||
|
|
||||||
|
# install_core_schema(engine)
|
||||||
|
# activate_extension('rattail', engine)
|
||||||
|
# load_fixtures(engine)
|
||||||
|
# super(DataTestCase, self).setUp()
|
||||||
|
|
||||||
|
# # def tearDown(self):
|
||||||
|
# # from rattail.pyramid import Session
|
||||||
|
# # super(DataTestCase, self).tearDown()
|
||||||
|
# # Session.configure(bind=None)
|
28
rattail/pyramid/tests/fixtures.py
Normal file
28
rattail/pyramid/tests/fixtures.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
import fixture
|
||||||
|
|
||||||
|
from rattail.db import model
|
||||||
|
|
||||||
|
|
||||||
|
class DepartmentData(fixture.DataSet):
|
||||||
|
|
||||||
|
class grocery:
|
||||||
|
number = 1
|
||||||
|
name = 'Grocery'
|
||||||
|
|
||||||
|
class supplements:
|
||||||
|
number = 2
|
||||||
|
name = 'Supplements'
|
||||||
|
|
||||||
|
|
||||||
|
def load_fixtures(engine):
|
||||||
|
|
||||||
|
dbfixture = fixture.SQLAlchemyFixture(
|
||||||
|
env={
|
||||||
|
'DepartmentData': model.Department,
|
||||||
|
},
|
||||||
|
engine=engine)
|
||||||
|
|
||||||
|
data = dbfixture.data(DepartmentData)
|
||||||
|
|
||||||
|
data.setup()
|
46
rattail/pyramid/tests/test_departments.py
Normal file
46
rattail/pyramid/tests/test_departments.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
from pyramid import testing
|
||||||
|
|
||||||
|
from rattail.pyramid.tests import TestCase
|
||||||
|
from rattail.pyramid.views import departments
|
||||||
|
|
||||||
|
from rattail.db.model import Department
|
||||||
|
|
||||||
|
|
||||||
|
class DepartmentTests(TestCase):
|
||||||
|
"""
|
||||||
|
Test Department views.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_grid(self):
|
||||||
|
request = testing.DummyRequest(has_perm=lambda p: True)
|
||||||
|
view = departments.DepartmentsGrid(request)
|
||||||
|
view._data = None
|
||||||
|
view._sort_config = None
|
||||||
|
self.assertIsInstance(view, departments.DepartmentsGrid)
|
||||||
|
self.assertIsInstance(view.filter_map(), dict)
|
||||||
|
self.assertIsInstance(view.filter_config(), dict)
|
||||||
|
self.assertIsInstance(view.sort_map(), dict)
|
||||||
|
self.assertIsInstance(view.grid(), object)
|
||||||
|
|
||||||
|
def test_crud(self):
|
||||||
|
request = testing.DummyRequest()
|
||||||
|
view = departments.DepartmentCrud(request)
|
||||||
|
self.assertIsInstance(view, departments.DepartmentCrud)
|
||||||
|
self.assertIsInstance(view.fieldset(Department), object)
|
||||||
|
|
||||||
|
def test_autocomplete(self):
|
||||||
|
request = testing.DummyRequest()
|
||||||
|
view = departments.DepartmentsAutocomplete(request)
|
||||||
|
self.assertIsInstance(view, departments.DepartmentsAutocomplete)
|
||||||
|
|
||||||
|
def test_vendor_grid(self):
|
||||||
|
request = testing.DummyRequest(params={'uuid': 'bogus'})
|
||||||
|
view = departments.DepartmentsByVendorGrid(request)
|
||||||
|
view._data = None
|
||||||
|
self.assertIsInstance(view, departments.DepartmentsByVendorGrid)
|
||||||
|
self.assertIsInstance(view.query(), object)
|
||||||
|
self.assertIsInstance(view.grid(), object)
|
||||||
|
|
||||||
|
def test_includeme(self):
|
||||||
|
self.config.include(departments)
|
11
rattail/pyramid/tests/test_root.py
Normal file
11
rattail/pyramid/tests/test_root.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
from rattail.pyramid.tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class RootTests(TestCase):
|
||||||
|
"""
|
||||||
|
Test root module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_includeme(self):
|
||||||
|
self.config.include('rattail.pyramid')
|
11
rattail/pyramid/tests/test_views.py
Normal file
11
rattail/pyramid/tests/test_views.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
from rattail.pyramid.tests import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class ViewTests(TestCase):
|
||||||
|
"""
|
||||||
|
Test root views module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_includeme(self):
|
||||||
|
self.config.include('rattail.pyramid.views')
|
|
@ -40,12 +40,13 @@ from edbob.pyramid.views import SearchableAlchemyGridView, CrudView, View
|
||||||
|
|
||||||
import rattail
|
import rattail
|
||||||
from rattail import batches
|
from rattail import batches
|
||||||
|
from rattail.db.model import Batch
|
||||||
from rattail.threads import Thread
|
from rattail.threads import Thread
|
||||||
|
|
||||||
|
|
||||||
class BatchesGrid(SearchableAlchemyGridView):
|
class BatchesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Batch
|
mapped_class = Batch
|
||||||
config_prefix = 'batches'
|
config_prefix = 'batches'
|
||||||
sort = 'id'
|
sort = 'id'
|
||||||
|
|
||||||
|
@ -53,15 +54,15 @@ class BatchesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
def executed_is(q, v):
|
def executed_is(q, v):
|
||||||
if v == 'True':
|
if v == 'True':
|
||||||
return q.filter(rattail.Batch.executed != None)
|
return q.filter(Batch.executed != None)
|
||||||
else:
|
else:
|
||||||
return q.filter(rattail.Batch.executed == None)
|
return q.filter(Batch.executed == None)
|
||||||
|
|
||||||
def executed_isnot(q, v):
|
def executed_isnot(q, v):
|
||||||
if v == 'True':
|
if v == 'True':
|
||||||
return q.filter(rattail.Batch.executed == None)
|
return q.filter(Batch.executed == None)
|
||||||
else:
|
else:
|
||||||
return q.filter(rattail.Batch.executed != None)
|
return q.filter(Batch.executed != None)
|
||||||
|
|
||||||
return self.make_filter_map(
|
return self.make_filter_map(
|
||||||
exact=['id'],
|
exact=['id'],
|
||||||
|
@ -113,7 +114,7 @@ class BatchesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class BatchCrud(CrudView):
|
class BatchCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Batch
|
mapped_class = Batch
|
||||||
home_route = 'batches'
|
home_route = 'batches'
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
|
@ -159,7 +160,7 @@ class ExecuteBatch(View):
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
uuid = self.request.matchdict['uuid']
|
uuid = self.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:
|
if not batch:
|
||||||
return HTTPFound(location=self.request.route_url('batches'))
|
return HTTPFound(location=self.request.route_url('batches'))
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,12 @@
|
||||||
from edbob.pyramid.views import (
|
from edbob.pyramid.views import (
|
||||||
SearchableAlchemyGridView, CrudView, AutocompleteView)
|
SearchableAlchemyGridView, CrudView, AutocompleteView)
|
||||||
|
|
||||||
import rattail
|
from rattail.db.model import Brand
|
||||||
|
|
||||||
|
|
||||||
class BrandsGrid(SearchableAlchemyGridView):
|
class BrandsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Brand
|
mapped_class = Brand
|
||||||
config_prefix = 'brands'
|
config_prefix = 'brands'
|
||||||
sort = 'name'
|
sort = 'name'
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class BrandsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class BrandCrud(CrudView):
|
class BrandCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Brand
|
mapped_class = Brand
|
||||||
home_route = 'brands'
|
home_route = 'brands'
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
|
@ -84,7 +84,7 @@ class BrandCrud(CrudView):
|
||||||
|
|
||||||
class BrandsAutocomplete(AutocompleteView):
|
class BrandsAutocomplete(AutocompleteView):
|
||||||
|
|
||||||
mapped_class = rattail.Brand
|
mapped_class = Brand
|
||||||
fieldname = 'name'
|
fieldname = 'name'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,12 @@
|
||||||
|
|
||||||
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
||||||
|
|
||||||
import rattail
|
from rattail.db.model import Category
|
||||||
|
|
||||||
|
|
||||||
class CategoriesGrid(SearchableAlchemyGridView):
|
class CategoriesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Category
|
mapped_class = Category
|
||||||
config_prefix = 'categories'
|
config_prefix = 'categories'
|
||||||
sort = 'number'
|
sort = 'number'
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class CategoriesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class CategoryCrud(CrudView):
|
class CategoryCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Category
|
mapped_class = Category
|
||||||
home_route = 'categories'
|
home_route = 'categories'
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
|
|
|
@ -28,13 +28,13 @@
|
||||||
|
|
||||||
from edbob.pyramid.views import SearchableAlchemyGridView
|
from edbob.pyramid.views import SearchableAlchemyGridView
|
||||||
|
|
||||||
import rattail
|
|
||||||
from rattail.pyramid.views import CrudView
|
from rattail.pyramid.views import CrudView
|
||||||
|
from rattail.db.model import CustomerGroup
|
||||||
|
|
||||||
|
|
||||||
class CustomerGroupsGrid(SearchableAlchemyGridView):
|
class CustomerGroupsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.CustomerGroup
|
mapped_class = CustomerGroup
|
||||||
config_prefix = 'customer_groups'
|
config_prefix = 'customer_groups'
|
||||||
sort = 'name'
|
sort = 'name'
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class CustomerGroupsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class CustomerGroupCrud(CrudView):
|
class CustomerGroupCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.CustomerGroup
|
mapped_class = CustomerGroup
|
||||||
home_route = 'customer_groups'
|
home_route = 'customer_groups'
|
||||||
pretty_name = "Customer Group"
|
pretty_name = "Customer Group"
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@
|
||||||
from edbob.pyramid.views import (
|
from edbob.pyramid.views import (
|
||||||
SearchableAlchemyGridView, CrudView, AlchemyGridView, AutocompleteView)
|
SearchableAlchemyGridView, CrudView, AlchemyGridView, AutocompleteView)
|
||||||
|
|
||||||
import rattail
|
from rattail.db.model import Department, Product, ProductCost, Vendor
|
||||||
|
|
||||||
|
|
||||||
class DepartmentsGrid(SearchableAlchemyGridView):
|
class DepartmentsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Department
|
mapped_class = Department
|
||||||
config_prefix = 'departments'
|
config_prefix = 'departments'
|
||||||
sort = 'name'
|
sort = 'name'
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class DepartmentsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class DepartmentCrud(CrudView):
|
class DepartmentCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Department
|
mapped_class = Department
|
||||||
home_route = 'departments'
|
home_route = 'departments'
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
|
@ -87,19 +87,19 @@ class DepartmentCrud(CrudView):
|
||||||
|
|
||||||
class DepartmentsByVendorGrid(AlchemyGridView):
|
class DepartmentsByVendorGrid(AlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Department
|
mapped_class = Department
|
||||||
config_prefix = 'departments.by_vendor'
|
config_prefix = 'departments.by_vendor'
|
||||||
checkboxes = True
|
checkboxes = True
|
||||||
partial_only = True
|
partial_only = True
|
||||||
|
|
||||||
def query(self):
|
def query(self):
|
||||||
q = self.make_query()
|
q = self.make_query()
|
||||||
q = q.outerjoin(rattail.Product)
|
q = q.outerjoin(Product)
|
||||||
q = q.join(rattail.ProductCost)
|
q = q.join(ProductCost)
|
||||||
q = q.join(rattail.Vendor)
|
q = q.join(Vendor)
|
||||||
q = q.filter(rattail.Vendor.uuid == self.request.params['uuid'])
|
q = q.filter(Vendor.uuid == self.request.params['uuid'])
|
||||||
q = q.distinct()
|
q = q.distinct()
|
||||||
q = q.order_by(rattail.Department.name)
|
q = q.order_by(Department.name)
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def grid(self):
|
def grid(self):
|
||||||
|
@ -114,7 +114,7 @@ class DepartmentsByVendorGrid(AlchemyGridView):
|
||||||
|
|
||||||
class DepartmentsAutocomplete(AutocompleteView):
|
class DepartmentsAutocomplete(AutocompleteView):
|
||||||
|
|
||||||
mapped_class = rattail.Department
|
mapped_class = Department
|
||||||
fieldname = 'name'
|
fieldname = 'name'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,12 @@ from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
||||||
from edbob.pyramid.grids.search import BooleanSearchFilter
|
from edbob.pyramid.grids.search import BooleanSearchFilter
|
||||||
from edbob.pyramid.forms import StrippingFieldRenderer
|
from edbob.pyramid.forms import StrippingFieldRenderer
|
||||||
|
|
||||||
import rattail
|
from rattail.db.model import LabelProfile
|
||||||
|
|
||||||
|
|
||||||
class ProfilesGrid(SearchableAlchemyGridView):
|
class ProfilesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.LabelProfile
|
mapped_class = LabelProfile
|
||||||
config_prefix = 'label_profiles'
|
config_prefix = 'label_profiles'
|
||||||
sort = 'ordinal'
|
sort = 'ordinal'
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class ProfilesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class ProfileCrud(CrudView):
|
class ProfileCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.LabelProfile
|
mapped_class = LabelProfile
|
||||||
home_route = 'label_profiles'
|
home_route = 'label_profiles'
|
||||||
pretty_name = "Label Profile"
|
pretty_name = "Label Profile"
|
||||||
update_cancel_route = 'label_profile.read'
|
update_cancel_route = 'label_profile.read'
|
||||||
|
@ -134,7 +134,7 @@ class ProfileCrud(CrudView):
|
||||||
|
|
||||||
def printer_settings(request):
|
def printer_settings(request):
|
||||||
uuid = request.matchdict['uuid']
|
uuid = request.matchdict['uuid']
|
||||||
profile = Session.query(rattail.LabelProfile).get(uuid) if uuid else None
|
profile = Session.query(LabelProfile).get(uuid) if uuid else None
|
||||||
if not profile:
|
if not profile:
|
||||||
return HTTPFound(location=request.route_url('label_profiles'))
|
return HTTPFound(location=request.route_url('label_profiles'))
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,14 @@ import edbob
|
||||||
from edbob.pyramid.progress import SessionProgress
|
from edbob.pyramid.progress import SessionProgress
|
||||||
from edbob.pyramid.views import SearchableAlchemyGridView
|
from edbob.pyramid.views import SearchableAlchemyGridView
|
||||||
|
|
||||||
import rattail
|
|
||||||
import rattail.labels
|
import rattail.labels
|
||||||
from rattail import sil
|
from rattail import sil
|
||||||
from rattail import batches
|
from rattail import batches
|
||||||
from rattail.threads import Thread
|
from rattail.threads import Thread
|
||||||
from rattail.exceptions import LabelPrintingError
|
from rattail.exceptions import LabelPrintingError
|
||||||
from rattail.db.model import ProductPrice, ProductCode
|
from rattail.db.model import (
|
||||||
|
Product, ProductPrice, ProductCost, ProductCode,
|
||||||
|
Brand, Vendor, Department, Subdepartment, LabelProfile)
|
||||||
|
|
||||||
from rattail.pyramid import Session
|
from rattail.pyramid import Session
|
||||||
from rattail.pyramid.forms import (AutocompleteFieldRenderer,
|
from rattail.pyramid.forms import (AutocompleteFieldRenderer,
|
||||||
|
@ -54,7 +55,7 @@ from rattail.pyramid.views import CrudView
|
||||||
|
|
||||||
class ProductsGrid(SearchableAlchemyGridView):
|
class ProductsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Product
|
mapped_class = Product
|
||||||
config_prefix = 'products'
|
config_prefix = 'products'
|
||||||
sort = 'description'
|
sort = 'description'
|
||||||
|
|
||||||
|
@ -62,29 +63,29 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
def join_vendor(q):
|
def join_vendor(q):
|
||||||
q = q.outerjoin(
|
q = q.outerjoin(
|
||||||
rattail.ProductCost,
|
ProductCost,
|
||||||
and_(
|
and_(
|
||||||
rattail.ProductCost.product_uuid == rattail.Product.uuid,
|
ProductCost.product_uuid == Product.uuid,
|
||||||
rattail.ProductCost.preference == 1,
|
ProductCost.preference == 1,
|
||||||
))
|
))
|
||||||
q = q.outerjoin(rattail.Vendor)
|
q = q.outerjoin(Vendor)
|
||||||
return q
|
return q
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'brand':
|
'brand':
|
||||||
lambda q: q.outerjoin(rattail.Brand),
|
lambda q: q.outerjoin(Brand),
|
||||||
'department':
|
'department':
|
||||||
lambda q: q.outerjoin(rattail.Department,
|
lambda q: q.outerjoin(Department,
|
||||||
rattail.Department.uuid == rattail.Product.department_uuid),
|
Department.uuid == Product.department_uuid),
|
||||||
'subdepartment':
|
'subdepartment':
|
||||||
lambda q: q.outerjoin(rattail.Subdepartment,
|
lambda q: q.outerjoin(Subdepartment,
|
||||||
rattail.Subdepartment.uuid == rattail.Product.subdepartment_uuid),
|
Subdepartment.uuid == Product.subdepartment_uuid),
|
||||||
'regular_price':
|
'regular_price':
|
||||||
lambda q: q.outerjoin(rattail.ProductPrice,
|
lambda q: q.outerjoin(ProductPrice,
|
||||||
rattail.ProductPrice.uuid == rattail.Product.regular_price_uuid),
|
ProductPrice.uuid == Product.regular_price_uuid),
|
||||||
'current_price':
|
'current_price':
|
||||||
lambda q: q.outerjoin(rattail.ProductPrice,
|
lambda q: q.outerjoin(ProductPrice,
|
||||||
rattail.ProductPrice.uuid == rattail.Product.current_price_uuid),
|
ProductPrice.uuid == Product.current_price_uuid),
|
||||||
'vendor':
|
'vendor':
|
||||||
join_vendor,
|
join_vendor,
|
||||||
'code':
|
'code':
|
||||||
|
@ -101,7 +102,7 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return q
|
return q
|
||||||
else:
|
else:
|
||||||
return q.filter(rattail.Product.upc == v) if v else q
|
return q.filter(Product.upc == v) if v else q
|
||||||
|
|
||||||
def filter_not(q, v):
|
def filter_not(q, v):
|
||||||
try:
|
try:
|
||||||
|
@ -109,17 +110,17 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return q
|
return q
|
||||||
else:
|
else:
|
||||||
return q.filter(rattail.Product.upc != v) if v else q
|
return q.filter(Product.upc != v) if v else q
|
||||||
|
|
||||||
return {'is': filter_is, 'nt': filter_not}
|
return {'is': filter_is, 'nt': filter_not}
|
||||||
|
|
||||||
return self.make_filter_map(
|
return self.make_filter_map(
|
||||||
ilike=['description', 'size'],
|
ilike=['description', 'size'],
|
||||||
upc=filter_upc(),
|
upc=filter_upc(),
|
||||||
brand=self.filter_ilike(rattail.Brand.name),
|
brand=self.filter_ilike(Brand.name),
|
||||||
department=self.filter_ilike(rattail.Department.name),
|
department=self.filter_ilike(Department.name),
|
||||||
subdepartment=self.filter_ilike(rattail.Subdepartment.name),
|
subdepartment=self.filter_ilike(Subdepartment.name),
|
||||||
vendor=self.filter_ilike(rattail.Vendor.name),
|
vendor=self.filter_ilike(Vendor.name),
|
||||||
code=self.filter_ilike(ProductCode.code))
|
code=self.filter_ilike(ProductCode.code))
|
||||||
|
|
||||||
def filter_config(self):
|
def filter_config(self):
|
||||||
|
@ -139,21 +140,21 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
def sort_map(self):
|
def sort_map(self):
|
||||||
return self.make_sort_map(
|
return self.make_sort_map(
|
||||||
'upc', 'description', 'size',
|
'upc', 'description', 'size',
|
||||||
brand=self.sorter(rattail.Brand.name),
|
brand=self.sorter(Brand.name),
|
||||||
department=self.sorter(rattail.Department.name),
|
department=self.sorter(Department.name),
|
||||||
subdepartment=self.sorter(rattail.Subdepartment.name),
|
subdepartment=self.sorter(Subdepartment.name),
|
||||||
regular_price=self.sorter(rattail.ProductPrice.price),
|
regular_price=self.sorter(ProductPrice.price),
|
||||||
current_price=self.sorter(rattail.ProductPrice.price),
|
current_price=self.sorter(ProductPrice.price),
|
||||||
vendor=self.sorter(rattail.Vendor.name))
|
vendor=self.sorter(Vendor.name))
|
||||||
|
|
||||||
def query(self):
|
def query(self):
|
||||||
q = self.make_query()
|
q = self.make_query()
|
||||||
q = q.options(joinedload(rattail.Product.brand))
|
q = q.options(joinedload(Product.brand))
|
||||||
q = q.options(joinedload(rattail.Product.department))
|
q = q.options(joinedload(Product.department))
|
||||||
q = q.options(joinedload(rattail.Product.subdepartment))
|
q = q.options(joinedload(Product.subdepartment))
|
||||||
q = q.options(joinedload(rattail.Product.regular_price))
|
q = q.options(joinedload(Product.regular_price))
|
||||||
q = q.options(joinedload(rattail.Product.current_price))
|
q = q.options(joinedload(Product.current_price))
|
||||||
q = q.options(joinedload(rattail.Product.vendor))
|
q = q.options(joinedload(Product.vendor))
|
||||||
return q
|
return q
|
||||||
|
|
||||||
def grid(self):
|
def grid(self):
|
||||||
|
@ -184,7 +185,7 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
g.deletable = True
|
g.deletable = True
|
||||||
g.delete_route_name = 'product.delete'
|
g.delete_route_name = 'product.delete'
|
||||||
|
|
||||||
q = Session.query(rattail.LabelProfile)
|
q = Session.query(LabelProfile)
|
||||||
if q.count():
|
if q.count():
|
||||||
def labels(row):
|
def labels(row):
|
||||||
return link_to("Print", '#', class_='print-label')
|
return link_to("Print", '#', class_='print-label')
|
||||||
|
@ -193,15 +194,15 @@ class ProductsGrid(SearchableAlchemyGridView):
|
||||||
return g
|
return g
|
||||||
|
|
||||||
def render_kwargs(self):
|
def render_kwargs(self):
|
||||||
q = Session.query(rattail.LabelProfile)
|
q = Session.query(LabelProfile)
|
||||||
q = q.filter(rattail.LabelProfile.visible == True)
|
q = q.filter(LabelProfile.visible == True)
|
||||||
q = q.order_by(rattail.LabelProfile.ordinal)
|
q = q.order_by(LabelProfile.ordinal)
|
||||||
return {'label_profiles': q.all()}
|
return {'label_profiles': q.all()}
|
||||||
|
|
||||||
|
|
||||||
class ProductCrud(CrudView):
|
class ProductCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Product
|
mapped_class = Product
|
||||||
home_route = 'products'
|
home_route = 'products'
|
||||||
|
|
||||||
def get_model(self, key):
|
def get_model(self, key):
|
||||||
|
@ -239,12 +240,12 @@ class ProductCrud(CrudView):
|
||||||
|
|
||||||
def print_labels(request):
|
def print_labels(request):
|
||||||
profile = request.params.get('profile')
|
profile = request.params.get('profile')
|
||||||
profile = Session.query(rattail.LabelProfile).get(profile) if profile else None
|
profile = Session.query(LabelProfile).get(profile) if profile else None
|
||||||
if not profile:
|
if not profile:
|
||||||
return {'error': "Label profile not found"}
|
return {'error': "Label profile not found"}
|
||||||
|
|
||||||
product = request.params.get('product')
|
product = request.params.get('product')
|
||||||
product = Session.query(rattail.Product).get(product) if product else None
|
product = Session.query(Product).get(product) if product else None
|
||||||
if not product:
|
if not product:
|
||||||
return {'error': "Product not found"}
|
return {'error': "Product not found"}
|
||||||
|
|
||||||
|
|
|
@ -30,34 +30,34 @@ from sqlalchemy import and_
|
||||||
|
|
||||||
from edbob.pyramid.views import SearchableAlchemyGridView
|
from edbob.pyramid.views import SearchableAlchemyGridView
|
||||||
|
|
||||||
import rattail
|
|
||||||
from rattail.pyramid.views import CrudView
|
from rattail.pyramid.views import CrudView
|
||||||
|
from rattail.db.model import Store, StoreEmailAddress, StorePhoneNumber
|
||||||
|
|
||||||
|
|
||||||
class StoresGrid(SearchableAlchemyGridView):
|
class StoresGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Store
|
mapped_class = Store
|
||||||
config_prefix = 'stores'
|
config_prefix = 'stores'
|
||||||
sort = 'id'
|
sort = 'id'
|
||||||
|
|
||||||
def join_map(self):
|
def join_map(self):
|
||||||
return {
|
return {
|
||||||
'email':
|
'email':
|
||||||
lambda q: q.outerjoin(rattail.StoreEmailAddress, and_(
|
lambda q: q.outerjoin(StoreEmailAddress, and_(
|
||||||
rattail.StoreEmailAddress.parent_uuid == rattail.Store.uuid,
|
StoreEmailAddress.parent_uuid == Store.uuid,
|
||||||
rattail.StoreEmailAddress.preference == 1)),
|
StoreEmailAddress.preference == 1)),
|
||||||
'phone':
|
'phone':
|
||||||
lambda q: q.outerjoin(rattail.StorePhoneNumber, and_(
|
lambda q: q.outerjoin(StorePhoneNumber, and_(
|
||||||
rattail.StorePhoneNumber.parent_uuid == rattail.Store.uuid,
|
StorePhoneNumber.parent_uuid == Store.uuid,
|
||||||
rattail.StorePhoneNumber.preference == 1)),
|
StorePhoneNumber.preference == 1)),
|
||||||
}
|
}
|
||||||
|
|
||||||
def filter_map(self):
|
def filter_map(self):
|
||||||
return self.make_filter_map(
|
return self.make_filter_map(
|
||||||
exact=['id'],
|
exact=['id'],
|
||||||
ilike=['name'],
|
ilike=['name'],
|
||||||
email=self.filter_ilike(rattail.StoreEmailAddress.address),
|
email=self.filter_ilike(StoreEmailAddress.address),
|
||||||
phone=self.filter_ilike(rattail.StorePhoneNumber.number))
|
phone=self.filter_ilike(StorePhoneNumber.number))
|
||||||
|
|
||||||
def filter_config(self):
|
def filter_config(self):
|
||||||
return self.make_filter_config(
|
return self.make_filter_config(
|
||||||
|
@ -68,8 +68,8 @@ class StoresGrid(SearchableAlchemyGridView):
|
||||||
def sort_map(self):
|
def sort_map(self):
|
||||||
return self.make_sort_map(
|
return self.make_sort_map(
|
||||||
'id', 'name',
|
'id', 'name',
|
||||||
email=self.sorter(rattail.StoreEmailAddress.address),
|
email=self.sorter(StoreEmailAddress.address),
|
||||||
phone=self.sorter(rattail.StorePhoneNumber.number))
|
phone=self.sorter(StorePhoneNumber.number))
|
||||||
|
|
||||||
def grid(self):
|
def grid(self):
|
||||||
g = self.make_grid()
|
g = self.make_grid()
|
||||||
|
@ -94,7 +94,7 @@ class StoresGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class StoreCrud(CrudView):
|
class StoreCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Store
|
mapped_class = Store
|
||||||
home_route = 'stores'
|
home_route = 'stores'
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
|
|
|
@ -28,12 +28,12 @@
|
||||||
|
|
||||||
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
||||||
|
|
||||||
import rattail
|
from rattail.db.model import Subdepartment
|
||||||
|
|
||||||
|
|
||||||
class SubdepartmentsGrid(SearchableAlchemyGridView):
|
class SubdepartmentsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
mapped_class = rattail.Subdepartment
|
mapped_class = Subdepartment
|
||||||
config_prefix = 'subdepartments'
|
config_prefix = 'subdepartments'
|
||||||
sort = 'name'
|
sort = 'name'
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class SubdepartmentsGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
class SubdepartmentCrud(CrudView):
|
class SubdepartmentCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = rattail.Subdepartment
|
mapped_class = Subdepartment
|
||||||
home_route = 'subdepartments'
|
home_route = 'subdepartments'
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
|
|
|
@ -28,16 +28,16 @@
|
||||||
|
|
||||||
import formalchemy
|
import formalchemy
|
||||||
|
|
||||||
import edbob
|
|
||||||
from edbob.pyramid.views import users
|
from edbob.pyramid.views import users
|
||||||
|
|
||||||
from rattail.pyramid.views import CrudView
|
from rattail.pyramid.views import CrudView
|
||||||
from rattail.pyramid.forms import PersonFieldRenderer
|
from rattail.pyramid.forms import PersonFieldRenderer
|
||||||
|
from rattail.db.model import User
|
||||||
|
|
||||||
|
|
||||||
class UserCrud(CrudView):
|
class UserCrud(CrudView):
|
||||||
|
|
||||||
mapped_class = edbob.User
|
mapped_class = User
|
||||||
home_route = 'users'
|
home_route = 'users'
|
||||||
|
|
||||||
def fieldset(self, user):
|
def fieldset(self, user):
|
||||||
|
|
7
setup.cfg
Normal file
7
setup.cfg
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[nosetests]
|
||||||
|
nocapture = 1
|
||||||
|
cover-package = rattail.pyramid
|
||||||
|
cover-erase = 1
|
||||||
|
cover-inclusive = 1
|
||||||
|
cover-html = 1
|
||||||
|
cover-html-dir = htmlcov
|
2
setup.py
2
setup.py
|
@ -94,6 +94,8 @@ setup(
|
||||||
],
|
],
|
||||||
|
|
||||||
install_requires = requires,
|
install_requires = requires,
|
||||||
|
tests_require = requires + ['nose', 'coverage'],
|
||||||
|
test_suite = 'nose.collector',
|
||||||
|
|
||||||
namespace_packages = ['rattail'],
|
namespace_packages = ['rattail'],
|
||||||
packages = find_packages(),
|
packages = find_packages(),
|
||||||
|
|
Loading…
Reference in a new issue