Add get_product_key_field()
and _label()
to AppHandler
and deprecate corresponding config methods
This commit is contained in:
parent
f96f1794be
commit
57ef54dec3
|
@ -42,7 +42,7 @@ import humanize
|
|||
from mako.template import Template
|
||||
|
||||
from rattail.util import (load_object, load_entry_points,
|
||||
progress_loop,
|
||||
progress_loop, prettify,
|
||||
pretty_quantity, pretty_hours,
|
||||
NOTSET)
|
||||
from rattail.files import temp_path, resource_path
|
||||
|
@ -1200,6 +1200,32 @@ class AppHandler(object):
|
|||
"""
|
||||
return self.get_membership_handler().get_member(obj, **kwargs)
|
||||
|
||||
def get_product_key_field(self):
|
||||
"""
|
||||
Returns the configured fieldname for product key,
|
||||
e.g. ``'upc'``.
|
||||
"""
|
||||
return self.config.get('rattail', 'product.key', default='upc')
|
||||
|
||||
def get_product_key_label(self, field=None):
|
||||
"""
|
||||
Returns the configured field label for product key,
|
||||
e.g. ``'UPC'``.
|
||||
"""
|
||||
title = self.config.get('rattail', 'product.key_title')
|
||||
if title:
|
||||
return title
|
||||
|
||||
if not field:
|
||||
field = self.get_product_key_field()
|
||||
|
||||
if field == 'upc':
|
||||
return "UPC"
|
||||
if field == 'item_id':
|
||||
return "Item ID"
|
||||
|
||||
return prettify(field)
|
||||
|
||||
def get_session(self, obj):
|
||||
"""
|
||||
Returns the SQLAlchemy session with which the given object is
|
||||
|
|
|
@ -41,7 +41,6 @@ from rattail.util import load_entry_points, load_object
|
|||
from rattail.exceptions import WindowsExtensionsNotInstalled, ConfigurationError
|
||||
from rattail.files import temp_path
|
||||
from rattail.logging import TimeConverter
|
||||
from rattail.util import prettify
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -643,33 +642,25 @@ class RattailConfiguration:
|
|||
return self.get_bool('rattail.db.versioning.enabled', usedb=False,
|
||||
default=False)
|
||||
|
||||
def product_key(self, default='upc'):
|
||||
def product_key(self, **kwargs):
|
||||
"""
|
||||
Returns the name of the attribute which should be treated as
|
||||
the canonical product key field, e.g. ``'upc'`` or
|
||||
``'item_id'`` etc.
|
||||
Deprecated; instead please see
|
||||
:meth:`rattail.app.AppHandler.get_product_key_field()`.
|
||||
"""
|
||||
return self.get('rattail.product.key', default=default)
|
||||
warnings.warn("config.product_key() is deprecated; please "
|
||||
"use app.get_product_key_field() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return self.get_app().get_product_key_field()
|
||||
|
||||
def product_key_title(self, key=None):
|
||||
"""
|
||||
Returns the title string to be used when displaying product
|
||||
key field, e.g. "UPC" or "Part No." etc.
|
||||
|
||||
:param key: The product key for which to return a label. This
|
||||
is optional; if not specified then :meth:`product_key()`
|
||||
will be called to determine the key.
|
||||
Deprecated; instead please see
|
||||
:meth:`rattail.app.AppHandler.get_product_key_label()`.
|
||||
"""
|
||||
title = self.get('rattail.product.key_title')
|
||||
if title:
|
||||
return title
|
||||
if not key:
|
||||
key = self.product_key()
|
||||
if key == 'upc':
|
||||
return "UPC"
|
||||
if key == 'item_id':
|
||||
return "Item ID"
|
||||
return prettify(key)
|
||||
warnings.warn("config.product_key_title() is deprecated; please "
|
||||
"use app.get_product_key_label() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return self.get_app().get_product_key_label(field=key)
|
||||
|
||||
def app_package(self, default=None):
|
||||
"""
|
||||
|
@ -1474,32 +1465,25 @@ class RattailConfig(object):
|
|||
spec = self.require('rattail.trainwreck', 'model', usedb=False)
|
||||
return importlib.import_module(spec)
|
||||
|
||||
def product_key(self, default='upc'):
|
||||
def product_key(self, **kwargs):
|
||||
"""
|
||||
Returns the name of the attribute which should be treated as the
|
||||
canonical product key field, e.g. 'upc' or 'item_id' etc.
|
||||
Deprecated; instead please see
|
||||
:meth:`rattail.app.AppHandler.get_product_key_field()`.
|
||||
"""
|
||||
return self.get('rattail', 'product.key', default=default) or default
|
||||
warnings.warn("config.product_key() is deprecated; please "
|
||||
"use app.get_product_key_field() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return self.get_app().get_product_key_field()
|
||||
|
||||
def product_key_title(self, key=None):
|
||||
"""
|
||||
Returns the title string to be used when displaying product key field,
|
||||
e.g. "UPC" or "Part No." etc.
|
||||
|
||||
:param key: The product key for which to return a label. This
|
||||
is optional; if not specified then :meth:`product_key()`
|
||||
will be called to determine the key.
|
||||
Deprecated; instead please see
|
||||
:meth:`rattail.app.AppHandler.get_product_key_label()`.
|
||||
"""
|
||||
title = self.get('rattail', 'product.key_title')
|
||||
if title:
|
||||
return title
|
||||
if not key:
|
||||
key = self.product_key()
|
||||
if key == 'upc':
|
||||
return "UPC"
|
||||
if key == 'item_id':
|
||||
return "Item ID"
|
||||
return prettify(key)
|
||||
warnings.warn("config.product_key_title() is deprecated; please "
|
||||
"use app.get_product_key_label() instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
return self.get_app().get_product_key_label(field=key)
|
||||
|
||||
def single_store(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue