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