Refactored model imports, etc.

This is in preparation for using database models only from `rattail` (i.e. no
`edbob`).  Mostly the model and enum imports were affected.
This commit is contained in:
Lance Edgar 2013-12-17 05:57:55 -08:00
parent d838203ec7
commit 1a557f3947
6 changed files with 42 additions and 43 deletions

View file

@ -36,7 +36,7 @@ from webhelpers.html.builder import format_attrs
from pyramid.renderers import render from pyramid.renderers import render
from edbob.core import Object from rattail.core import Object
__all__ = ['Grid'] __all__ = ['Grid']

View file

@ -35,7 +35,7 @@ from pyramid.renderers import render
from pyramid_simpleform import Form from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer from pyramid_simpleform.renderers import FormRenderer
from edbob.core import Object from rattail.core import Object
from edbob.util import prettify from edbob.util import prettify

View file

@ -110,7 +110,7 @@
<td class="brand">${cost.product.brand or ''}</td> <td class="brand">${cost.product.brand or ''}</td>
<td class="desc">${cost.product.description}</td> <td class="desc">${cost.product.description}</td>
<td class="size">${cost.product.size or ''}</td> <td class="size">${cost.product.size or ''}</td>
<td class="case-qty">${cost.case_size} ${rattail.UNIT_OF_MEASURE.get(cost.product.unit_of_measure, '')}</td> <td class="case-qty">${cost.case_size} ${rattail.enum.UNIT_OF_MEASURE.get(cost.product.unit_of_measure, '')}</td>
<td class="code">${cost.code or ''}</td> <td class="code">${cost.code or ''}</td>
<td class="preferred">${'X' if cost.preference == 1 else ''}</td> <td class="preferred">${'X' if cost.preference == 1 else ''}</td>
% for i in range(14): % for i in range(14):

View file

@ -37,7 +37,7 @@ from ...grids.search import BooleanSearchFilter
from edbob.pyramid.progress import SessionProgress from edbob.pyramid.progress import SessionProgress
from .. import SearchableAlchemyGridView, CrudView, View from .. import SearchableAlchemyGridView, CrudView, View
import rattail from rattail import enum
from rattail import batches from rattail import batches
from ...db import Session from ...db import Session
from rattail.db.model import Batch from rattail.db.model import Batch
@ -119,7 +119,7 @@ class BatchCrud(CrudView):
def fieldset(self, model): def fieldset(self, model):
fs = self.make_fieldset(model) fs = self.make_fieldset(model)
fs.action_type.set(renderer=EnumFieldRenderer(rattail.BATCH_ACTION)) fs.action_type.set(renderer=EnumFieldRenderer(enum.BATCH_ACTION))
fs.executed.set(renderer=PrettyDateTimeFieldRenderer(from_='utc')) fs.executed.set(renderer=PrettyDateTimeFieldRenderer(from_='utc'))
fs.configure( fs.configure(
include=[ include=[

View file

@ -30,41 +30,37 @@ from sqlalchemy import and_
from edbob.enum import EMAIL_PREFERENCE from edbob.enum import EMAIL_PREFERENCE
from . import SearchableAlchemyGridView from . import SearchableAlchemyGridView, CrudView
from ..forms import EnumFieldRenderer from ..forms import EnumFieldRenderer
import rattail
from ..db import Session from ..db import Session
from rattail.db.model import ( from rattail.db import model
Customer, CustomerPerson, CustomerGroupAssignment,
CustomerEmailAddress, CustomerPhoneNumber)
from . import CrudView
class CustomersGrid(SearchableAlchemyGridView): class CustomersGrid(SearchableAlchemyGridView):
mapped_class = Customer mapped_class = model.Customer
config_prefix = 'customers' config_prefix = 'customers'
sort = 'name' sort = 'name'
def join_map(self): def join_map(self):
return { return {
'email': 'email':
lambda q: q.outerjoin(CustomerEmailAddress, and_( lambda q: q.outerjoin(model.CustomerEmailAddress, and_(
CustomerEmailAddress.parent_uuid == Customer.uuid, model.CustomerEmailAddress.parent_uuid == model.Customer.uuid,
CustomerEmailAddress.preference == 1)), model.CustomerEmailAddress.preference == 1)),
'phone': 'phone':
lambda q: q.outerjoin(CustomerPhoneNumber, and_( lambda q: q.outerjoin(model.CustomerPhoneNumber, and_(
CustomerPhoneNumber.parent_uuid == Customer.uuid, model.CustomerPhoneNumber.parent_uuid == model.Customer.uuid,
CustomerPhoneNumber.preference == 1)), model.CustomerPhoneNumber.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(CustomerEmailAddress.address), email=self.filter_ilike(model.CustomerEmailAddress.address),
phone=self.filter_ilike(CustomerPhoneNumber.number)) phone=self.filter_ilike(model.CustomerPhoneNumber.number))
def filter_config(self): def filter_config(self):
return self.make_filter_config( return self.make_filter_config(
@ -77,8 +73,8 @@ class CustomersGrid(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(CustomerEmailAddress.address), email=self.sorter(model.CustomerEmailAddress.address),
phone=self.sorter(CustomerPhoneNumber.number)) phone=self.sorter(model.CustomerPhoneNumber.number))
def grid(self): def grid(self):
g = self.make_grid() g = self.make_grid()
@ -106,20 +102,20 @@ class CustomersGrid(SearchableAlchemyGridView):
class CustomerCrud(CrudView): class CustomerCrud(CrudView):
mapped_class = Customer mapped_class = model.Customer
home_route = 'customers' home_route = 'customers'
def get_model(self, key): def get_model(self, key):
model = super(CustomerCrud, self).get_model(key) model = super(CustomerCrud, self).get_model(key)
if model: if model:
return model return model
model = Session.query(Customer).filter_by(id=key).first() model = Session.query(model.Customer).filter_by(id=key).first()
if model: if model:
return model return model
model = Session.query(CustomerPerson).get(key) model = Session.query(model.CustomerPerson).get(key)
if model: if model:
return model.customer return model.customer
model = Session.query(CustomerGroupAssignment).get(key) model = Session.query(model.CustomerGroupAssignment).get(key)
if model: if model:
return model.customer return model.customer
return None return None

View file

@ -26,16 +26,19 @@
Report Views Report Views
""" """
import re
from .core import View from .core import View
from mako.template import Template from mako.template import Template
from pyramid.response import Response from pyramid.response import Response
from ..db import Session from ..db import Session
from rattail.db.model import Vendor, Department, Product, ProductCost
import re
import rattail
from edbob.time import local_time from edbob.time import local_time
import rattail
from rattail import enum
from rattail.db import model
from rattail.files import resource_path from rattail.files import resource_path
@ -64,13 +67,13 @@ class OrderingWorksheet(View):
def __call__(self): def __call__(self):
if self.request.params.get('vendor'): if self.request.params.get('vendor'):
vendor = Session.query(Vendor).get(self.request.params['vendor']) vendor = Session.query(model.Vendor).get(self.request.params['vendor'])
if vendor: if vendor:
departments = [] departments = []
uuids = self.request.params.get('departments') uuids = self.request.params.get('departments')
if uuids: if uuids:
for uuid in uuids.split(','): for uuid in uuids.split(','):
dept = Session.query(Department).get(uuid) dept = Session.query(model.Department).get(uuid)
if dept: if dept:
departments.append(dept) departments.append(dept)
preferred_only = self.request.params.get('preferred_only') == '1' preferred_only = self.request.params.get('preferred_only') == '1'
@ -87,12 +90,12 @@ class OrderingWorksheet(View):
Rendering engine for the ordering worksheet report. Rendering engine for the ordering worksheet report.
""" """
q = Session.query(ProductCost) q = Session.query(model.ProductCost)
q = q.join(Product) q = q.join(model.Product)
q = q.filter(ProductCost.vendor == vendor) q = q.filter(model.ProductCost.vendor == vendor)
q = q.filter(Product.department_uuid.in_([x.uuid for x in departments])) q = q.filter(model.Product.department_uuid.in_([x.uuid for x in departments]))
if preferred_only: if preferred_only:
q = q.filter(ProductCost.preference == 1) q = q.filter(model.ProductCost.preference == 1)
costs = {} costs = {}
for cost in q: for cost in q:
@ -138,7 +141,7 @@ class InventoryWorksheet(View):
This is the "Inventory Worksheet" report. This is the "Inventory Worksheet" report.
""" """
departments = Session.query(Department) departments = Session.query(model.Department)
if self.request.params.get('department'): if self.request.params.get('department'):
department = departments.get(self.request.params['department']) department = departments.get(self.request.params['department'])
@ -150,7 +153,7 @@ class InventoryWorksheet(View):
response.text = body response.text = body
return response return response
departments = departments.order_by(rattail.Department.name) departments = departments.order_by(model.Department.name)
departments = departments.all() departments = departments.all()
return{'departments': departments} return{'departments': departments}
@ -160,12 +163,12 @@ class InventoryWorksheet(View):
""" """
def get_products(subdepartment): def get_products(subdepartment):
q = Session.query(rattail.Product) q = Session.query(model.Product)
q = q.outerjoin(rattail.Brand) q = q.outerjoin(model.Brand)
q = q.filter(rattail.Product.subdepartment == subdepartment) q = q.filter(model.Product.subdepartment == subdepartment)
if self.request.params.get('weighted-only'): if self.request.params.get('weighted-only'):
q = q.filter(rattail.Product.unit_of_measure == rattail.UNIT_OF_MEASURE_POUND) q = q.filter(model.Product.unit_of_measure == enum.UNIT_OF_MEASURE_POUND)
q = q.order_by(rattail.Brand.name, rattail.Product.description) q = q.order_by(model.Brand.name, model.Product.description)
return q.all() return q.all()
now = local_time() now = local_time()