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 mako.template import Template
|
||||||
|
|
||||||
from rattail.util import (load_object, load_entry_points,
|
from rattail.util import (load_object, load_entry_points,
|
||||||
progress_loop,
|
progress_loop, prettify,
|
||||||
pretty_quantity, pretty_hours,
|
pretty_quantity, pretty_hours,
|
||||||
NOTSET)
|
NOTSET)
|
||||||
from rattail.files import temp_path, resource_path
|
from rattail.files import temp_path, resource_path
|
||||||
|
@ -1200,6 +1200,32 @@ class AppHandler(object):
|
||||||
"""
|
"""
|
||||||
return self.get_membership_handler().get_member(obj, **kwargs)
|
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):
|
def get_session(self, obj):
|
||||||
"""
|
"""
|
||||||
Returns the SQLAlchemy session with which the given object is
|
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.exceptions import WindowsExtensionsNotInstalled, ConfigurationError
|
||||||
from rattail.files import temp_path
|
from rattail.files import temp_path
|
||||||
from rattail.logging import TimeConverter
|
from rattail.logging import TimeConverter
|
||||||
from rattail.util import prettify
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -643,33 +642,25 @@ class RattailConfiguration:
|
||||||
return self.get_bool('rattail.db.versioning.enabled', usedb=False,
|
return self.get_bool('rattail.db.versioning.enabled', usedb=False,
|
||||||
default=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
|
Deprecated; instead please see
|
||||||
the canonical product key field, e.g. ``'upc'`` or
|
:meth:`rattail.app.AppHandler.get_product_key_field()`.
|
||||||
``'item_id'`` etc.
|
|
||||||
"""
|
"""
|
||||||
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):
|
def product_key_title(self, key=None):
|
||||||
"""
|
"""
|
||||||
Returns the title string to be used when displaying product
|
Deprecated; instead please see
|
||||||
key field, e.g. "UPC" or "Part No." etc.
|
:meth:`rattail.app.AppHandler.get_product_key_label()`.
|
||||||
|
|
||||||
: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.
|
|
||||||
"""
|
"""
|
||||||
title = self.get('rattail.product.key_title')
|
warnings.warn("config.product_key_title() is deprecated; please "
|
||||||
if title:
|
"use app.get_product_key_label() instead",
|
||||||
return title
|
DeprecationWarning, stacklevel=2)
|
||||||
if not key:
|
return self.get_app().get_product_key_label(field=key)
|
||||||
key = self.product_key()
|
|
||||||
if key == 'upc':
|
|
||||||
return "UPC"
|
|
||||||
if key == 'item_id':
|
|
||||||
return "Item ID"
|
|
||||||
return prettify(key)
|
|
||||||
|
|
||||||
def app_package(self, default=None):
|
def app_package(self, default=None):
|
||||||
"""
|
"""
|
||||||
|
@ -1474,32 +1465,25 @@ class RattailConfig(object):
|
||||||
spec = self.require('rattail.trainwreck', 'model', usedb=False)
|
spec = self.require('rattail.trainwreck', 'model', usedb=False)
|
||||||
return importlib.import_module(spec)
|
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
|
Deprecated; instead please see
|
||||||
canonical product key field, e.g. 'upc' or 'item_id' etc.
|
: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):
|
def product_key_title(self, key=None):
|
||||||
"""
|
"""
|
||||||
Returns the title string to be used when displaying product key field,
|
Deprecated; instead please see
|
||||||
e.g. "UPC" or "Part No." etc.
|
:meth:`rattail.app.AppHandler.get_product_key_label()`.
|
||||||
|
|
||||||
: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.
|
|
||||||
"""
|
"""
|
||||||
title = self.get('rattail', 'product.key_title')
|
warnings.warn("config.product_key_title() is deprecated; please "
|
||||||
if title:
|
"use app.get_product_key_label() instead",
|
||||||
return title
|
DeprecationWarning, stacklevel=2)
|
||||||
if not key:
|
return self.get_app().get_product_key_label(field=key)
|
||||||
key = self.product_key()
|
|
||||||
if key == 'upc':
|
|
||||||
return "UPC"
|
|
||||||
if key == 'item_id':
|
|
||||||
return "Item ID"
|
|
||||||
return prettify(key)
|
|
||||||
|
|
||||||
def single_store(self):
|
def single_store(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue