1 | import datetime |
||
0 ignored issues
–
show
|
|||
2 | import logging |
||
3 | |||
4 | from dateutil.parser import parse as date_parse |
||
5 | from sqlalchemy import Text |
||
6 | |||
7 | logger = logging.getLogger(__name__) |
||
0 ignored issues
–
show
The name
logger does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site.
Loading history...
|
|||
8 | |||
9 | search_operators = { |
||
0 ignored issues
–
show
The name
search_operators does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site.
Loading history...
|
|||
10 | '=': lambda expr, value: expr == value, |
||
11 | '>': lambda expr, value: expr > value, |
||
12 | '>=': lambda expr, value: expr >= value, |
||
13 | '<': lambda expr, value: expr < value, |
||
14 | '<=': lambda expr, value: expr <= value, |
||
15 | } |
||
16 | |||
17 | |||
18 | def parse_query_value(combined_value): |
||
19 | """Parse value in form of '>value' to a lambda and a value.""" |
||
20 | split = len(combined_value) - len(combined_value.lstrip('<>=')) |
||
21 | operator = combined_value[:split] |
||
22 | if operator == '': |
||
23 | operator = '=' |
||
24 | try: |
||
25 | operator_func = search_operators[operator] |
||
26 | except KeyError: |
||
27 | raise ValueError( |
||
28 | 'Numeric query should start with operator, choose from %s' % |
||
29 | ', '.join(search_operators.keys())) |
||
30 | value = combined_value[split:].strip() |
||
31 | return operator_func, value |
||
32 | |||
33 | |||
34 | def numeric_query(expr, value): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.
Loading history...
|
|||
35 | operator_func, value = parse_query_value(value) |
||
36 | if value == '': |
||
37 | num_value = 0 |
||
38 | else: |
||
39 | num_value = float(value) |
||
40 | |||
41 | return operator_func(expr, num_value) |
||
42 | |||
43 | |||
44 | def date_query(expr, value): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.
Loading history...
|
|||
45 | operator_func, value = parse_query_value(value) |
||
46 | try: |
||
47 | date_value = date_parse(value) |
||
48 | except ValueError: |
||
49 | date_value = datetime.datetime.now() |
||
50 | |||
51 | return operator_func(expr, date_value) |
||
52 | |||
53 | |||
54 | def yadcf_range_number(expr, value): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.
Loading history...
|
|||
55 | v_from, v_to = value.split('-yadcf_delim-') |
||
56 | v_from = float(v_from) if v_from != '' else -float('inf') |
||
57 | v_to = float(v_to) if v_to != '' else float('inf') |
||
58 | logger.debug('yadcf_range_number: between %f and %f', v_from, v_to) |
||
59 | return expr.between(v_from, v_to) |
||
60 | |||
61 | |||
62 | def yadcf_range_date(expr, value): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.
Loading history...
|
|||
63 | v_from, v_to = value.split('-yadcf_delim-') |
||
64 | v_from = date_parse(v_from) if v_from != '' else datetime.date.min |
||
65 | v_to = date_parse(v_to) if v_to != '' else datetime.date.max |
||
66 | logger.debug('yadcf_range_date: between %s and %s', v_from, v_to) |
||
67 | return expr.between(v_from, v_to) |
||
68 | |||
69 | |||
70 | def yadcf_multi_select(expr, value): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.
Loading history...
|
|||
71 | options = value.split('|') |
||
72 | logger.debug('yadcf_multi_select: in %s', options) |
||
73 | return expr.cast(Text).in_(options) |
||
74 | |||
75 | |||
76 | SEARCH_METHODS = { |
||
77 | 'none': lambda expr, value: None, |
||
78 | 'string_contains': lambda expr, value: expr.ilike('%' + value + '%'), |
||
79 | 'ilike': lambda expr, value: expr.ilike(value), |
||
80 | 'like': lambda expr, value: expr.like(value), |
||
81 | 'numeric': numeric_query, |
||
82 | 'date': date_query, |
||
83 | 'yadcf_text': lambda expr, value: expr.ilike('%' + value + '%'), |
||
84 | 'yadcf_autocomplete': lambda expr, value: expr == value, |
||
85 | 'yadcf_select': lambda expr, value: expr.ilike('%' + value + '%'), |
||
86 | 'yadcf_multi_select': yadcf_multi_select, |
||
87 | 'yadcf_range_number': yadcf_range_number, |
||
88 | 'yadcf_range_number_slider': yadcf_range_number, |
||
89 | 'yadcf_range_date': yadcf_range_date |
||
90 | } |
||
91 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.