Make config
param more explicit, for GridFilter constructor
i.e. the rattail config object
This commit is contained in:
parent
539f4a5c31
commit
ad4ec41e15
|
@ -24,12 +24,9 @@
|
||||||
Core Grid Classes
|
Core Grid Classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import
|
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import six
|
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
@ -493,8 +490,8 @@ class Grid(object):
|
||||||
return ""
|
return ""
|
||||||
enum = self.enums.get(column_name)
|
enum = self.enums.get(column_name)
|
||||||
if enum and value in enum:
|
if enum and value in enum:
|
||||||
return six.text_type(enum[value])
|
return str(enum[value])
|
||||||
return six.text_type(value)
|
return str(value)
|
||||||
|
|
||||||
def render_gpc(self, obj, column_name):
|
def render_gpc(self, obj, column_name):
|
||||||
value = self.obtain_value(obj, column_name)
|
value = self.obtain_value(obj, column_name)
|
||||||
|
@ -687,14 +684,16 @@ class Grid(object):
|
||||||
factory = gridfilters.AlchemyDateTimeFilter
|
factory = gridfilters.AlchemyDateTimeFilter
|
||||||
elif isinstance(column.type, GPCType):
|
elif isinstance(column.type, GPCType):
|
||||||
factory = gridfilters.AlchemyGPCFilter
|
factory = gridfilters.AlchemyGPCFilter
|
||||||
|
kwargs['column'] = column
|
||||||
|
kwargs.setdefault('config', self.request.rattail_config)
|
||||||
kwargs.setdefault('encode_values', self.use_byte_string_filters)
|
kwargs.setdefault('encode_values', self.use_byte_string_filters)
|
||||||
return factory(key, column=column, config=self.request.rattail_config, **kwargs)
|
return factory(key, **kwargs)
|
||||||
|
|
||||||
def iter_filters(self):
|
def iter_filters(self):
|
||||||
"""
|
"""
|
||||||
Iterate over all filters available to the grid.
|
Iterate over all filters available to the grid.
|
||||||
"""
|
"""
|
||||||
return six.itervalues(self.filters)
|
return self.filters.values()
|
||||||
|
|
||||||
def iter_active_filters(self):
|
def iter_active_filters(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1002,7 +1001,7 @@ class Grid(object):
|
||||||
else: # source = session
|
else: # source = session
|
||||||
settings['{}.active'.format(prefix)] = self.get_setting(
|
settings['{}.active'.format(prefix)] = self.get_setting(
|
||||||
source, settings, '{}.active'.format(prefix),
|
source, settings, '{}.active'.format(prefix),
|
||||||
normalize=lambda v: six.text_type(v).lower() == 'true', default=False)
|
normalize=lambda v: str(v).lower() == 'true', default=False)
|
||||||
settings['{}.verb'.format(prefix)] = self.get_setting(
|
settings['{}.verb'.format(prefix)] = self.get_setting(
|
||||||
source, settings, '{}.verb'.format(prefix), default='')
|
source, settings, '{}.verb'.format(prefix), default='')
|
||||||
settings['{}.value'.format(prefix)] = self.get_setting(
|
settings['{}.value'.format(prefix)] = self.get_setting(
|
||||||
|
@ -1071,7 +1070,7 @@ class Grid(object):
|
||||||
|
|
||||||
if self.filterable:
|
if self.filterable:
|
||||||
for filtr in self.iter_filters():
|
for filtr in self.iter_filters():
|
||||||
persist('filter.{}.active'.format(filtr.key), value=lambda k: six.text_type(settings[k]).lower())
|
persist('filter.{}.active'.format(filtr.key), value=lambda k: str(settings[k]).lower())
|
||||||
persist('filter.{}.verb'.format(filtr.key))
|
persist('filter.{}.verb'.format(filtr.key))
|
||||||
persist('filter.{}.value'.format(filtr.key))
|
persist('filter.{}.value'.format(filtr.key))
|
||||||
|
|
||||||
|
@ -1305,7 +1304,7 @@ class Grid(object):
|
||||||
'multiple_value_verbs': multiple_values,
|
'multiple_value_verbs': multiple_values,
|
||||||
'verb_labels': filtr.verb_labels,
|
'verb_labels': filtr.verb_labels,
|
||||||
'verb': filtr.verb or filtr.default_verb or filtr.verbs[0],
|
'verb': filtr.verb or filtr.default_verb or filtr.verbs[0],
|
||||||
'value': six.text_type(filtr.value) if filtr.value is not None else "",
|
'value': str(filtr.value) if filtr.value is not None else "",
|
||||||
'data_type': filtr.data_type,
|
'data_type': filtr.data_type,
|
||||||
'choices': choices,
|
'choices': choices,
|
||||||
'choice_labels': choice_labels,
|
'choice_labels': choice_labels,
|
||||||
|
@ -1478,7 +1477,7 @@ class Grid(object):
|
||||||
value = self.obtain_value(rowobj, name)
|
value = self.obtain_value(rowobj, name)
|
||||||
if value is None:
|
if value is None:
|
||||||
value = ""
|
value = ""
|
||||||
row[name] = six.text_type(value)
|
row[name] = str(value)
|
||||||
|
|
||||||
# maybe add UUID for convenience
|
# maybe add UUID for convenience
|
||||||
if 'uuid' not in self.columns:
|
if 'uuid' not in self.columns:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2022 Lance Edgar
|
# Copyright © 2010-2023 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,13 +24,10 @@
|
||||||
Grid Filters
|
Grid Filters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import six
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
from rattail.gpc import GPC
|
from rattail.gpc import GPC
|
||||||
|
@ -117,7 +114,7 @@ class EnumValueRenderer(ChoiceValueRenderer):
|
||||||
sorted_keys = list(enum.keys())
|
sorted_keys = list(enum.keys())
|
||||||
else:
|
else:
|
||||||
sorted_keys = sorted(enum, key=lambda k: enum[k].lower())
|
sorted_keys = sorted(enum, key=lambda k: enum[k].lower())
|
||||||
self.options = [tags.Option(enum[k], six.text_type(k)) for k in sorted_keys]
|
self.options = [tags.Option(enum[k], str(k)) for k in sorted_keys]
|
||||||
|
|
||||||
|
|
||||||
class GridFilter(object):
|
class GridFilter(object):
|
||||||
|
@ -173,10 +170,12 @@ class GridFilter(object):
|
||||||
data_type = 'string' # default, but will be set from value renderer
|
data_type = 'string' # default, but will be set from value renderer
|
||||||
choices = {}
|
choices = {}
|
||||||
|
|
||||||
def __init__(self, key, label=None, verbs=None, value_enum=None, value_renderer=None,
|
def __init__(self, key, config=None, label=None, verbs=None,
|
||||||
|
value_enum=None, value_renderer=None,
|
||||||
default_active=False, default_verb=None, default_value=None,
|
default_active=False, default_verb=None, default_value=None,
|
||||||
encode_values=False, value_encoding='utf-8', **kwargs):
|
encode_values=False, value_encoding='utf-8', **kwargs):
|
||||||
self.key = key
|
self.key = key
|
||||||
|
self.config = config
|
||||||
self.label = label or prettify(key)
|
self.label = label or prettify(key)
|
||||||
self.verbs = verbs or self.get_default_verbs()
|
self.verbs = verbs or self.get_default_verbs()
|
||||||
if value_renderer:
|
if value_renderer:
|
||||||
|
@ -279,7 +278,7 @@ class GridFilter(object):
|
||||||
return value if value is not UNSPECIFIED else self.value
|
return value if value is not UNSPECIFIED else self.value
|
||||||
|
|
||||||
def encode_value(self, value):
|
def encode_value(self, value):
|
||||||
if self.encode_values and isinstance(value, six.string_types):
|
if self.encode_values and isinstance(value, str):
|
||||||
return value.encode('utf-8')
|
return value.encode('utf-8')
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -536,7 +535,7 @@ class AlchemyByteStringFilter(AlchemyStringFilter):
|
||||||
|
|
||||||
def get_value(self, value=UNSPECIFIED):
|
def get_value(self, value=UNSPECIFIED):
|
||||||
value = super(AlchemyByteStringFilter, self).get_value(value)
|
value = super(AlchemyByteStringFilter, self).get_value(value)
|
||||||
if isinstance(value, six.text_type):
|
if isinstance(value, str):
|
||||||
value = value.encode(self.value_encoding)
|
value = value.encode(self.value_encoding)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -590,7 +589,7 @@ class AlchemyNumericFilter(AlchemyGridFilter):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return bool(value and len(six.text_type(value)) > 8)
|
return bool(value and len(str(value)) > 8)
|
||||||
|
|
||||||
def filter_equal(self, query, value):
|
def filter_equal(self, query, value):
|
||||||
if self.value_invalid(value):
|
if self.value_invalid(value):
|
||||||
|
|
Loading…
Reference in a new issue