fix: refactor config.get_model()
=> app.model
per rattail changes
This commit is contained in:
parent
4eb5866379
commit
ae8212069c
|
@ -53,7 +53,7 @@ dependencies = [
|
||||||
"pyramid_mako",
|
"pyramid_mako",
|
||||||
"pyramid_retry",
|
"pyramid_retry",
|
||||||
"pyramid_tm",
|
"pyramid_tm",
|
||||||
"rattail[db,bouncer]",
|
"rattail[db,bouncer]>=0.16.0",
|
||||||
"sa-filters",
|
"sa-filters",
|
||||||
"simplejson",
|
"simplejson",
|
||||||
"transaction",
|
"transaction",
|
||||||
|
|
|
@ -875,7 +875,8 @@ class Form(object):
|
||||||
for field in self])
|
for field in self])
|
||||||
|
|
||||||
def get_field_markdowns(self):
|
def get_field_markdowns(self):
|
||||||
model = self.request.rattail_config.get_model()
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
|
|
||||||
if not hasattr(self, 'field_markdowns'):
|
if not hasattr(self, 'field_markdowns'):
|
||||||
infos = Session.query(model.TailboneFieldInfo)\
|
infos = Session.query(model.TailboneFieldInfo)\
|
||||||
|
|
|
@ -477,7 +477,8 @@ class CustomerAutocompleteWidget(JQueryAutocompleteWidget):
|
||||||
def __init__(self, request, *args, **kwargs):
|
def __init__(self, request, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.request = request
|
self.request = request
|
||||||
model = self.request.rattail_config.get_model()
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
|
|
||||||
# must figure out URL providing autocomplete service
|
# must figure out URL providing autocomplete service
|
||||||
if 'service_url' not in kwargs:
|
if 'service_url' not in kwargs:
|
||||||
|
@ -498,7 +499,8 @@ class CustomerAutocompleteWidget(JQueryAutocompleteWidget):
|
||||||
""" """
|
""" """
|
||||||
# fetch customer to provide button label, if we have a value
|
# fetch customer to provide button label, if we have a value
|
||||||
if cstruct:
|
if cstruct:
|
||||||
model = self.request.rattail_config.get_model()
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
customer = Session.get(model.Customer, cstruct)
|
customer = Session.get(model.Customer, cstruct)
|
||||||
if customer:
|
if customer:
|
||||||
self.field_display = str(customer)
|
self.field_display = str(customer)
|
||||||
|
@ -552,7 +554,8 @@ class DepartmentWidget(dfwidget.SelectWidget):
|
||||||
def __init__(self, request, **kwargs):
|
def __init__(self, request, **kwargs):
|
||||||
|
|
||||||
if 'values' not in kwargs:
|
if 'values' not in kwargs:
|
||||||
model = request.rattail_config.get_model()
|
app = request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
departments = Session.query(model.Department)\
|
departments = Session.query(model.Department)\
|
||||||
.order_by(model.Department.number)
|
.order_by(model.Department.number)
|
||||||
values = [(dept.uuid, str(dept))
|
values = [(dept.uuid, str(dept))
|
||||||
|
@ -594,7 +597,8 @@ class VendorAutocompleteWidget(JQueryAutocompleteWidget):
|
||||||
def __init__(self, request, *args, **kwargs):
|
def __init__(self, request, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.request = request
|
self.request = request
|
||||||
model = self.request.rattail_config.get_model()
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
|
|
||||||
# must figure out URL providing autocomplete service
|
# must figure out URL providing autocomplete service
|
||||||
if 'service_url' not in kwargs:
|
if 'service_url' not in kwargs:
|
||||||
|
@ -615,7 +619,8 @@ class VendorAutocompleteWidget(JQueryAutocompleteWidget):
|
||||||
""" """
|
""" """
|
||||||
# fetch vendor to provide button label, if we have a value
|
# fetch vendor to provide button label, if we have a value
|
||||||
if cstruct:
|
if cstruct:
|
||||||
model = self.request.rattail_config.get_model()
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
vendor = Session.get(model.Vendor, cstruct)
|
vendor = Session.get(model.Vendor, cstruct)
|
||||||
if vendor:
|
if vendor:
|
||||||
self.field_display = str(vendor)
|
self.field_display = str(vendor)
|
||||||
|
@ -643,7 +648,8 @@ class VendorDropdownWidget(dfwidget.SelectWidget):
|
||||||
vendors = vendors()
|
vendors = vendors()
|
||||||
|
|
||||||
else: # default vendor list
|
else: # default vendor list
|
||||||
model = self.request.rattail_config.get_model()
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
vendors = Session.query(model.Vendor)\
|
vendors = Session.query(model.Vendor)\
|
||||||
.order_by(model.Vendor.name)\
|
.order_by(model.Vendor.name)\
|
||||||
.all()
|
.all()
|
||||||
|
|
|
@ -32,7 +32,7 @@ import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from rattail.db.types import GPCType
|
from rattail.db.types import GPCType
|
||||||
from rattail.util import prettify, pretty_boolean, pretty_quantity
|
from rattail.util import prettify, pretty_boolean
|
||||||
|
|
||||||
from pyramid.renderers import render
|
from pyramid.renderers import render
|
||||||
from webhelpers2.html import HTML, tags
|
from webhelpers2.html import HTML, tags
|
||||||
|
@ -60,7 +60,7 @@ class FieldList(list):
|
||||||
self.insert(i + 1, newfield)
|
self.insert(i + 1, newfield)
|
||||||
|
|
||||||
|
|
||||||
class Grid(object):
|
class Grid:
|
||||||
"""
|
"""
|
||||||
Core grid class. In sore need of documentation.
|
Core grid class. In sore need of documentation.
|
||||||
|
|
||||||
|
@ -532,7 +532,8 @@ class Grid(object):
|
||||||
|
|
||||||
def render_quantity(self, obj, column_name):
|
def render_quantity(self, obj, column_name):
|
||||||
value = self.obtain_value(obj, column_name)
|
value = self.obtain_value(obj, column_name)
|
||||||
return pretty_quantity(value)
|
app = self.request.rattail_config.get_app()
|
||||||
|
return app.render_quantity(value)
|
||||||
|
|
||||||
def render_duration(self, obj, column_name):
|
def render_duration(self, obj, column_name):
|
||||||
seconds = self.obtain_value(obj, column_name)
|
seconds = self.obtain_value(obj, column_name)
|
||||||
|
@ -1152,10 +1153,12 @@ class Grid(object):
|
||||||
"""
|
"""
|
||||||
Persist the given settings in some way, as defined by ``func``.
|
Persist the given settings in some way, as defined by ``func``.
|
||||||
"""
|
"""
|
||||||
|
app = self.request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
|
|
||||||
def persist(key, value=lambda k: settings[k]):
|
def persist(key, value=lambda k: settings[k]):
|
||||||
if to == 'defaults':
|
if to == 'defaults':
|
||||||
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
skey = 'tailbone.{}.grid.{}.{}'.format(self.request.user.uuid, self.key, key)
|
||||||
app = self.request.rattail_config.get_app()
|
|
||||||
app.save_setting(Session(), skey, value(key))
|
app.save_setting(Session(), skey, value(key))
|
||||||
else: # to == session
|
else: # to == session
|
||||||
skey = 'grid.{}.{}'.format(self.key, key)
|
skey = 'grid.{}.{}'.format(self.key, key)
|
||||||
|
@ -1172,7 +1175,6 @@ class Grid(object):
|
||||||
# first clear existing settings for *sorting* only
|
# first clear existing settings for *sorting* only
|
||||||
# nb. this is because number of sort settings will vary
|
# nb. this is because number of sort settings will vary
|
||||||
if to == 'defaults':
|
if to == 'defaults':
|
||||||
model = self.request.rattail_config.get_model()
|
|
||||||
prefix = f'tailbone.{self.request.user.uuid}.grid.{self.key}'
|
prefix = f'tailbone.{self.request.user.uuid}.grid.{self.key}'
|
||||||
query = Session.query(model.Setting)\
|
query = Session.query(model.Setting)\
|
||||||
.filter(sa.or_(
|
.filter(sa.or_(
|
||||||
|
|
|
@ -92,7 +92,8 @@ def new_request(event):
|
||||||
user = None
|
user = None
|
||||||
uuid = request.authenticated_userid
|
uuid = request.authenticated_userid
|
||||||
if uuid:
|
if uuid:
|
||||||
model = request.rattail_config.get_model()
|
app = request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
user = Session.get(model.User, uuid)
|
user = Session.get(model.User, uuid)
|
||||||
if user:
|
if user:
|
||||||
Session().set_continuum_user(user)
|
Session().set_continuum_user(user)
|
||||||
|
@ -174,7 +175,7 @@ def before_render(event):
|
||||||
renderer_globals['url'] = request.route_url
|
renderer_globals['url'] = request.route_url
|
||||||
renderer_globals['rattail'] = rattail
|
renderer_globals['rattail'] = rattail
|
||||||
renderer_globals['tailbone'] = tailbone
|
renderer_globals['tailbone'] = tailbone
|
||||||
renderer_globals['model'] = request.rattail_config.get_model()
|
renderer_globals['model'] = app.model
|
||||||
renderer_globals['enum'] = request.rattail_config.get_enum()
|
renderer_globals['enum'] = request.rattail_config.get_enum()
|
||||||
renderer_globals['json'] = json
|
renderer_globals['json'] = json
|
||||||
renderer_globals['datetime'] = datetime
|
renderer_globals['datetime'] = datetime
|
||||||
|
@ -258,8 +259,9 @@ def add_inbox_count(event):
|
||||||
request = event.get('request') or threadlocal.get_current_request()
|
request = event.get('request') or threadlocal.get_current_request()
|
||||||
if request.user:
|
if request.user:
|
||||||
renderer_globals = event
|
renderer_globals = event
|
||||||
|
app = request.rattail_config.get_app()
|
||||||
|
model = app.model
|
||||||
enum = request.rattail_config.get_enum()
|
enum = request.rattail_config.get_enum()
|
||||||
model = request.rattail_config.get_model()
|
|
||||||
renderer_globals['inbox_count'] = Session.query(model.Message)\
|
renderer_globals['inbox_count'] = Session.query(model.Message)\
|
||||||
.outerjoin(model.MessageRecipient)\
|
.outerjoin(model.MessageRecipient)\
|
||||||
.filter(model.MessageRecipient.recipient == Session.merge(request.user))\
|
.filter(model.MessageRecipient.recipient == Session.merge(request.user))\
|
||||||
|
|
|
@ -506,7 +506,7 @@ def include_configured_views(pyramid_config):
|
||||||
"""
|
"""
|
||||||
rattail_config = pyramid_config.registry.settings.get('rattail_config')
|
rattail_config = pyramid_config.registry.settings.get('rattail_config')
|
||||||
app = rattail_config.get_app()
|
app = rattail_config.get_app()
|
||||||
model = rattail_config.get_model()
|
model = app.model
|
||||||
session = app.make_session()
|
session = app.make_session()
|
||||||
|
|
||||||
# fetch all include-related settings at once
|
# fetch all include-related settings at once
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2023 Lance Edgar
|
# Copyright © 2010-2024 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -41,12 +41,13 @@ class MockRequest(dict):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WebsocketView(object):
|
class WebsocketView:
|
||||||
|
|
||||||
def __init__(self, pyramid_config):
|
def __init__(self, pyramid_config):
|
||||||
self.pyramid_config = pyramid_config
|
self.pyramid_config = pyramid_config
|
||||||
self.registry = self.pyramid_config.registry
|
self.registry = self.pyramid_config.registry
|
||||||
self.model = self.rattail_config.get_model()
|
app = self.get_rattail_app()
|
||||||
|
self.model = app.model
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rattail_config(self):
|
def rattail_config(self):
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2023 Lance Edgar
|
# Copyright © 2010-2024 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -26,10 +26,6 @@ Base View Class
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from rattail.db import model
|
|
||||||
from rattail.core import Object
|
|
||||||
from rattail.util import progress_loop
|
|
||||||
|
|
||||||
from pyramid import httpexceptions
|
from pyramid import httpexceptions
|
||||||
from pyramid.renderers import render_to_response
|
from pyramid.renderers import render_to_response
|
||||||
from pyramid.response import FileResponse
|
from pyramid.response import FileResponse
|
||||||
|
@ -40,7 +36,7 @@ from tailbone.progress import SessionProgress
|
||||||
from tailbone.config import protected_usernames
|
from tailbone.config import protected_usernames
|
||||||
|
|
||||||
|
|
||||||
class View(object):
|
class View:
|
||||||
"""
|
"""
|
||||||
Base class for all class-based views.
|
Base class for all class-based views.
|
||||||
"""
|
"""
|
||||||
|
@ -62,8 +58,9 @@ class View(object):
|
||||||
|
|
||||||
config = self.rattail_config
|
config = self.rattail_config
|
||||||
if config:
|
if config:
|
||||||
|
app = config.get_app()
|
||||||
|
self.model = app.model
|
||||||
self.enum = config.get_enum()
|
self.enum = config.get_enum()
|
||||||
self.model = config.get_model()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rattail_config(self):
|
def rattail_config(self):
|
||||||
|
@ -94,6 +91,7 @@ class View(object):
|
||||||
Returns the :class:`rattail:rattail.db.model.User` instance
|
Returns the :class:`rattail:rattail.db.model.User` instance
|
||||||
corresponding to the "late login" form data (if any), or ``None``.
|
corresponding to the "late login" form data (if any), or ``None``.
|
||||||
"""
|
"""
|
||||||
|
model = self.model
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
uuid = self.request.POST.get('late-login-user')
|
uuid = self.request.POST.get('late-login-user')
|
||||||
if uuid:
|
if uuid:
|
||||||
|
@ -120,7 +118,8 @@ class View(object):
|
||||||
return httpexceptions.HTTPFound(location=url, **kwargs)
|
return httpexceptions.HTTPFound(location=url, **kwargs)
|
||||||
|
|
||||||
def progress_loop(self, func, items, factory, *args, **kwargs):
|
def progress_loop(self, func, items, factory, *args, **kwargs):
|
||||||
return progress_loop(func, items, factory, *args, **kwargs)
|
app = self.get_rattail_app()
|
||||||
|
return app.progress_loop(func, items, factory, *args, **kwargs)
|
||||||
|
|
||||||
def make_progress(self, key, **kwargs):
|
def make_progress(self, key, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -165,7 +164,8 @@ class View(object):
|
||||||
return self.expose_quickie_search
|
return self.expose_quickie_search
|
||||||
|
|
||||||
def get_quickie_context(self):
|
def get_quickie_context(self):
|
||||||
return Object(
|
app = self.get_rattail_app()
|
||||||
|
return app.make_object(
|
||||||
url=self.get_quickie_url(),
|
url=self.get_quickie_url(),
|
||||||
perm=self.get_quickie_perm(),
|
perm=self.get_quickie_perm(),
|
||||||
placeholder=self.get_quickie_placeholder())
|
placeholder=self.get_quickie_placeholder())
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2023 Lance Edgar
|
# Copyright © 2010-2024 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
Base class for customer order batch views
|
Base class for customer order batch views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db.model import CustomerOrderBatch, CustomerOrderBatchRow
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
from webhelpers2.html import tags
|
from webhelpers2.html import tags
|
||||||
|
@ -38,8 +38,8 @@ class CustomerOrderBatchView(BatchMasterView):
|
||||||
Master view base class, for customer order batches. The views for the
|
Master view base class, for customer order batches. The views for the
|
||||||
various mode/workflow batches will derive from this.
|
various mode/workflow batches will derive from this.
|
||||||
"""
|
"""
|
||||||
model_class = model.CustomerOrderBatch
|
model_class = CustomerOrderBatch
|
||||||
model_row_class = model.CustomerOrderBatchRow
|
model_row_class = CustomerOrderBatchRow
|
||||||
default_handler_spec = 'rattail.batch.custorder:CustomerOrderBatchHandler'
|
default_handler_spec = 'rattail.batch.custorder:CustomerOrderBatchHandler'
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
|
@ -122,7 +122,7 @@ class CustomerOrderBatchView(BatchMasterView):
|
||||||
]
|
]
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
super(CustomerOrderBatchView, self).configure_grid(g)
|
super().configure_grid(g)
|
||||||
|
|
||||||
g.set_type('total_price', 'currency')
|
g.set_type('total_price', 'currency')
|
||||||
|
|
||||||
|
@ -131,9 +131,9 @@ class CustomerOrderBatchView(BatchMasterView):
|
||||||
g.set_link('created_by')
|
g.set_link('created_by')
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(CustomerOrderBatchView, self).configure_form(f)
|
super().configure_form(f)
|
||||||
order = f.model_instance
|
order = f.model_instance
|
||||||
model = self.rattail_config.get_model()
|
model = self.model
|
||||||
|
|
||||||
# readonly fields
|
# readonly fields
|
||||||
f.set_readonly('rows')
|
f.set_readonly('rows')
|
||||||
|
@ -201,7 +201,7 @@ class CustomerOrderBatchView(BatchMasterView):
|
||||||
return 'notice'
|
return 'notice'
|
||||||
|
|
||||||
def configure_row_grid(self, g):
|
def configure_row_grid(self, g):
|
||||||
super(CustomerOrderBatchView, self).configure_row_grid(g)
|
super().configure_row_grid(g)
|
||||||
|
|
||||||
g.set_type('case_quantity', 'quantity')
|
g.set_type('case_quantity', 'quantity')
|
||||||
g.set_type('cases_ordered', 'quantity')
|
g.set_type('cases_ordered', 'quantity')
|
||||||
|
@ -215,7 +215,7 @@ class CustomerOrderBatchView(BatchMasterView):
|
||||||
g.set_link('product_description')
|
g.set_link('product_description')
|
||||||
|
|
||||||
def configure_row_form(self, f):
|
def configure_row_form(self, f):
|
||||||
super(CustomerOrderBatchView, self).configure_row_form(f)
|
super().configure_row_form(f)
|
||||||
|
|
||||||
f.set_renderer('product', self.render_product)
|
f.set_renderer('product', self.render_product)
|
||||||
f.set_renderer('pending_product', self.render_pending_product)
|
f.set_renderer('pending_product', self.render_pending_product)
|
||||||
|
|
6
tasks.py
6
tasks.py
|
@ -31,16 +31,18 @@ from invoke import task
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def release(c, tests=False):
|
def release(c, skip_tests=False):
|
||||||
"""
|
"""
|
||||||
Release a new version of 'Tailbone'.
|
Release a new version of 'Tailbone'.
|
||||||
"""
|
"""
|
||||||
if tests:
|
if not skip_tests:
|
||||||
c.run('tox')
|
c.run('tox')
|
||||||
|
|
||||||
if os.path.exists('dist'):
|
if os.path.exists('dist'):
|
||||||
shutil.rmtree('dist')
|
shutil.rmtree('dist')
|
||||||
if os.path.exists('Tailbone.egg-info'):
|
if os.path.exists('Tailbone.egg-info'):
|
||||||
shutil.rmtree('Tailbone.egg-info')
|
shutil.rmtree('Tailbone.egg-info')
|
||||||
|
|
||||||
c.run('python -m build --sdist')
|
c.run('python -m build --sdist')
|
||||||
|
|
||||||
c.run('twine upload dist/*')
|
c.run('twine upload dist/*')
|
||||||
|
|
Loading…
Reference in a new issue