Field
lumi_filter.field
BooleanField
Bases: FilterField
Boolean field filter for true/false filtering operations.
Handles parsing and validation of boolean values for filtering operations. Accepts various string representations of boolean values and converts them to proper Python boolean types. Supports flexible input formats commonly used in web applications and configuration files.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Supported lookup expressions: - "" (empty): Exact equality (only supports exact boolean matching) |
Source code in lumi_filter/field.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
parse_value(value)
Parse various representations to boolean.
Converts string and boolean inputs to Python boolean values. Accepts multiple common representations of true/false values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Input value to convert to boolean. Can be bool, string, or other types. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (parsed_value, is_valid) where: - parsed_value (bool or None): The boolean value if conversion succeeds, None if it fails - is_valid (bool): True if conversion succeeds, False otherwise |
Note
Accepted true values: 'true', '1', 'yes', 'on' (case-insensitive) Accepted false values: 'false', '0', 'no', 'off' (case-insensitive)
Examples:
>>> field = BooleanField()
>>> field.parse_value("true")
(True, True)
>>> field.parse_value("0")
(False, True)
>>> field.parse_value("invalid")
(None, False)
Source code in lumi_filter/field.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
DateField
Bases: FilterField
Date field filter for date-only filtering operations.
Handles parsing and validation of date values for filtering operations. Accepts both datetime.date objects and ISO format date strings. Provides date-based comparisons without time components.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Supported lookup expressions: - "" (empty): Exact date equality - "!": Not equal - "gt": After date (greater than) - "lt": Before date (less than) - "gte": On or after date (greater than or equal) - "lte": On or before date (less than or equal) - "in": Date list membership |
Source code in lumi_filter/field.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
parse_value(value)
Parse datetime.date objects or ISO date strings.
Converts input to datetime.date objects. Accepts existing date objects or parses ISO format date strings (YYYY-MM-DD).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Input value to convert to date. Can be datetime.date object or string in ISO format (YYYY-MM-DD). |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (parsed_value, is_valid) where: - parsed_value (datetime.date or None): The date value if conversion succeeds, None if it fails - is_valid (bool): True if conversion succeeds, False otherwise |
Examples:
>>> field = DateField()
>>> field.parse_value("2023-12-25")
(datetime.date(2023, 12, 25), True)
>>> field.parse_value("invalid-date")
(None, False)
Source code in lumi_filter/field.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
DateTimeField
Bases: FilterField
DateTime field filter for date and time filtering operations.
Handles parsing and validation of datetime values for filtering operations. Accepts both datetime.datetime objects and ISO format datetime strings. Provides timestamp-based comparisons including both date and time components.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Supported lookup expressions: - "" (empty): Exact datetime equality - "!": Not equal - "gt": After datetime (greater than) - "lt": Before datetime (less than) - "gte": On or after datetime (greater than or equal) - "lte": On or before datetime (less than or equal) - "in": DateTime list membership |
Source code in lumi_filter/field.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
parse_value(value)
Parse datetime.datetime objects or ISO datetime strings.
Converts input to datetime.datetime objects. Accepts existing datetime objects or parses ISO format datetime strings (YYYY-MM-DDTHH:MM:SS).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Input value to convert to datetime. Can be datetime.datetime object or string in ISO format (YYYY-MM-DDTHH:MM:SS). |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (parsed_value, is_valid) where: - parsed_value (datetime.datetime or None): The datetime value if conversion succeeds, None if it fails - is_valid (bool): True if conversion succeeds, False otherwise |
Examples:
>>> field = DateTimeField()
>>> field.parse_value("2023-12-25T14:30:00")
(datetime.datetime(2023, 12, 25, 14, 30), True)
>>> field.parse_value("invalid-datetime")
(None, False)
Source code in lumi_filter/field.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
DecimalField
Bases: FilterField
Decimal field filter for precise numeric filtering operations.
Handles parsing and validation of decimal values for filtering operations. Provides precise decimal arithmetic suitable for financial calculations, scientific measurements, and other scenarios requiring exact decimal representation without floating-point precision issues.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Supported lookup expressions: - "" (empty): Exact equality - "!": Not equal - "gt": Greater than - "lt": Less than - "gte": Greater than or equal - "lte": Less than or equal - "in": List membership |
Source code in lumi_filter/field.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
parse_value(value)
Parse string or numeric input to Decimal.
Converts the input value to a decimal.Decimal object for precise arithmetic operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Input value to convert to Decimal. Can be string, int, float, or other numeric types. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (parsed_value, is_valid) where: - parsed_value (Decimal or None): The Decimal value if conversion succeeds, None if it fails - is_valid (bool): True if conversion succeeds, False otherwise |
Examples:
>>> field = DecimalField()
>>> field.parse_value("123.45")
(Decimal('123.45'), True)
>>> field.parse_value("invalid")
(None, False)
Source code in lumi_filter/field.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
FilterField
Base class for filter fields with common functionality.
This class provides the foundation for all filter field types, handling basic parsing and validation operations. It defines the interface for field-specific value parsing and validation.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Set of supported lookup expressions for filtering operations. Includes equality, negation, comparisons, containment checks, and list membership. |
request_arg_name |
str or None
|
Name of the request argument to bind to. If None, uses the field name from the filter class. |
source |
str or None
|
Source field or attribute name in the data model. If None, uses the field name from the filter class. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_arg_name
|
str
|
Name of the request argument. Defaults to None. |
None
|
source
|
str
|
Source field or attribute name. Defaults to None. |
None
|
Source code in lumi_filter/field.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
parse_value(value)
Parse and validate the input value.
This is the base implementation that accepts any value as valid. Subclasses should override this method to provide type-specific parsing and validation logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
The input value to parse and validate. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (parsed_value, is_valid) where: - parsed_value: The parsed and potentially converted value - is_valid (bool): True if the value is valid, False otherwise |
Source code in lumi_filter/field.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
IntField
Bases: FilterField
Integer field filter for numeric filtering operations.
Handles parsing and validation of integer values for filtering operations. Supports numerical comparison operations like equality, greater than, less than, and list membership. String representations of integers are automatically converted to int type.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Supported lookup expressions: - "" (empty): Exact equality - "!": Not equal - "gt": Greater than - "lt": Less than - "gte": Greater than or equal - "lte": Less than or equal - "in": List membership |
Source code in lumi_filter/field.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
parse_value(value)
Parse string or numeric input to integer.
Attempts to convert the input value to an integer type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Input value to convert to integer. Can be string, int, or other numeric types. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing (parsed_value, is_valid) where: - parsed_value (int or None): The integer value if conversion succeeds, None if it fails - is_valid (bool): True if conversion succeeds, False otherwise |
Examples:
>>> field = IntField()
>>> field.parse_value("123")
(123, True)
>>> field.parse_value("invalid")
(None, False)
Source code in lumi_filter/field.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
StrField
Bases: FilterField
String field filter for text-based filtering operations.
Handles parsing and validation of string values for filtering operations. Supports comprehensive text matching operations including exact matches, case-sensitive and case-insensitive containment checks, comparisons, and list membership.
Attributes:
Name | Type | Description |
---|---|---|
SUPPORTED_LOOKUP_EXPR |
frozenset
|
Supported lookup expressions: - "" (empty): Exact equality (case-sensitive) - "!": Not equal - "gt": Greater than (lexicographical) - "lt": Less than (lexicographical) - "gte": Greater than or equal (lexicographical) - "lte": Less than or equal (lexicographical) - "in": List membership - "contains": Case-sensitive substring match - "icontains": Case-insensitive substring match |
Source code in lumi_filter/field.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|