Skip to content

Commit

Permalink
Merge 1da56b0 into 049ab5f
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeyas00 committed Sep 11, 2020
2 parents 049ab5f + 1da56b0 commit 6f3ae52
Show file tree
Hide file tree
Showing 14 changed files with 616 additions and 370 deletions.
10 changes: 5 additions & 5 deletions datatables/clean_regex.py
Expand Up @@ -11,29 +11,29 @@ def clean_regex(regex):

# these characters are escaped (all except alternation | and escape \)
# see http://www.regular-expressions.info/refquick.html
escape_chars = '[^$.?*+(){}'
escape_chars = "[^$.?*+(){}"

# remove any escape chars
ret_regex = ret_regex.replace('\\', '')
ret_regex = ret_regex.replace("\\", "")

# escape any characters which are used by regex
# could probably concoct something incomprehensible using re.sub() but
# prefer to write clear code with this loop
# note expectation that no characters have already been escaped
for c in escape_chars:
ret_regex = ret_regex.replace(c, '\\' + c)
ret_regex = ret_regex.replace(c, "\\" + c)

# remove any double alternations until these don't exist any more
while True:
old_regex = ret_regex
ret_regex = ret_regex.replace('||', '|')
ret_regex = ret_regex.replace("||", "|")
if old_regex == ret_regex:
break

# if last char is alternation | remove it because this
# will cause operational error
# this can happen as user is typing in global search box
while len(ret_regex) >= 1 and ret_regex[-1] == '|':
while len(ret_regex) >= 1 and ret_regex[-1] == "|":
ret_regex = ret_regex[:-1]

# and back to the caller
Expand Down
51 changes: 30 additions & 21 deletions datatables/column_dt.py
Expand Up @@ -4,16 +4,20 @@

from datatables.search_methods import SEARCH_METHODS

NULLS_ORDER = ['nullsfirst', 'nullslast']
NULLS_ORDER = ["nullsfirst", "nullslast"]

ColumnTuple = namedtuple('ColumnDT', [
'sqla_expr',
'column_name',
'mData',
'search_method',
'nulls_order',
'global_search',
])
ColumnTuple = namedtuple(
"ColumnDT",
[
"sqla_expr",
"column_name",
"mData",
"search_method",
"nulls_order",
"global_search",
"yadcf_data",
],
)


class ColumnDT(ColumnTuple):
Expand Down Expand Up @@ -45,7 +49,10 @@ class ColumnDT(ColumnTuple):
- 'nullsfirst'
- 'nullslast'.
:param global_search: search this column for the global search box
:param yadcf_data : define if the data needs to be returned for yadcf plugin.
Possible values:
- False
- True (default)
:type sqla_expr: SQLAlchemy query expression
:type mData: str
:type search_method: str
Expand All @@ -57,24 +64,25 @@ class ColumnDT(ColumnTuple):
"""

def __new__(
cls,
sqla_expr,
column_name=None,
mData=None,
search_method='string_contains',
nulls_order=None,
global_search=True,
cls,
sqla_expr,
column_name=None,
mData=None,
search_method="string_contains",
nulls_order=None,
global_search=True,
yadcf_data=True,
):
"""Set default values due to namedtuple immutability."""
if nulls_order and nulls_order not in NULLS_ORDER:
raise ValueError(
'{} is not an allowed value for nulls_order.'.format(
nulls_order))
"{} is not an allowed value for nulls_order.".format(nulls_order)
)

if search_method not in SEARCH_METHODS:
raise ValueError(
'{} is not an allowed value for search_method.'.format(
search_method))
"{} is not an allowed value for search_method.".format(search_method)
)

return super(ColumnDT, cls).__new__(
cls,
Expand All @@ -84,4 +92,5 @@ def __new__(
search_method,
nulls_order,
global_search,
yadcf_data,
)

0 comments on commit 6f3ae52

Please sign in to comment.