Issues (109)

datatables/column_dt.py (3 issues)

1
from __future__ import absolute_import
0 ignored issues
show
This module 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...
2
3
from collections import namedtuple
4
5
from datatables.search_methods import SEARCH_METHODS
6
7
NULLS_ORDER = ['nullsfirst', 'nullslast']
8
9
ColumnTuple = namedtuple('ColumnDT', [
10
    'sqla_expr',
11
    'column_name',
12
    'mData',
13
    'search_method',
14
    'nulls_order',
15
    'global_search',
16
])
17
18
19
class ColumnDT(ColumnTuple):
0 ignored issues
show
The variable __class__ seems to be unused.
Loading history...
20
    """
21
    Define a DataTables column.
22
23
    :param sqla_expr: SQLAlchemy queryable attribute of object
24
    (column, column_property, hybrid property, or combined expression)
25
    :param mData: name of the mData property as defined in the
26
    DataTables javascript options (default None)
27
    :param search_method: Define how to interpret search values.
28
        Possible values:
29
            - 'none'
30
            - 'string_contains' (default)
31
            - 'ilike'
32
            - 'like'
33
            - 'numeric'
34
            - 'date'
35
            - 'yadcf_text'
36
            - 'yadcf_autocomplete'
37
            - 'yadcf_select'
38
            - 'yadcf_multi_select'
39
            - 'yadcf_range_number'
40
            - 'yadcf_range_number_slider'
41
            - 'yadcf_range_date'
42
    :param nulls_order: define a sort order for the NULL values.
43
        Possible values:
44
            - None (default)
45
            - 'nullsfirst'
46
            - 'nullslast'.
47
    :param global_search: search this column for the global search box
48
49
    :type sqla_expr: SQLAlchemy query expression
50
    :type mData: str
51
    :type search_method: str
52
    :type nulls_order: str
53
    :type global_search: bool
54
55
    :return: a ColumnDT object
56
    :rtype: ColumnDT
57
    """
58
59
    def __new__(
0 ignored issues
show
Too many arguments (7/5)
Loading history...
60
            cls,
61
            sqla_expr,
62
            column_name=None,
63
            mData=None,
64
            search_method='string_contains',
65
            nulls_order=None,
66
            global_search=True,
67
    ):
68
        """Set default values due to namedtuple immutability."""
69
        if nulls_order and nulls_order not in NULLS_ORDER:
70
            raise ValueError('{} is not an allowed value for nulls_order.'.
71
                             format(nulls_order))
72
73
        if search_method not in SEARCH_METHODS:
74
            raise ValueError('{} is not an allowed value for search_method.'.
75
                             format(search_method))
76
77
        return super(ColumnDT, cls).__new__(
78
            cls,
79
            sqla_expr,
80
            column_name,
81
            mData,
82
            search_method,
83
            nulls_order,
84
            global_search,
85
        )
86