TypeDAL 3.1.3__py3-none-any.whl → 3.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of TypeDAL might be problematic. Click here for more details.
- typedal/__about__.py +1 -1
- typedal/core.py +10 -3
- typedal/mixins.py +43 -6
- {typedal-3.1.3.dist-info → typedal-3.2.0.dist-info}/METADATA +3 -2
- {typedal-3.1.3.dist-info → typedal-3.2.0.dist-info}/RECORD +7 -7
- {typedal-3.1.3.dist-info → typedal-3.2.0.dist-info}/WHEEL +1 -1
- {typedal-3.1.3.dist-info → typedal-3.2.0.dist-info}/entry_points.txt +0 -0
typedal/__about__.py
CHANGED
typedal/core.py
CHANGED
|
@@ -12,6 +12,7 @@ import types
|
|
|
12
12
|
import typing
|
|
13
13
|
import warnings
|
|
14
14
|
from collections import defaultdict
|
|
15
|
+
from copy import copy
|
|
15
16
|
from decimal import Decimal
|
|
16
17
|
from pathlib import Path
|
|
17
18
|
from typing import Any, Optional
|
|
@@ -494,9 +495,15 @@ class TypeDAL(pydal.DAL): # type: ignore
|
|
|
494
495
|
# now it's only used to extract relationships from the object.
|
|
495
496
|
# other properties of the class (incl methods) should not be touched
|
|
496
497
|
|
|
497
|
-
for key in typedfields.keys() - full_dict.keys():
|
|
498
|
-
|
|
499
|
-
|
|
498
|
+
# for key in typedfields.keys() - full_dict.keys():
|
|
499
|
+
# # typed fields that don't haven't been added to the object yet
|
|
500
|
+
# setattr(cls, key, typedfields[key])
|
|
501
|
+
|
|
502
|
+
for key, field in typedfields.items():
|
|
503
|
+
# clone every property so it can be re-used across mixins:
|
|
504
|
+
clone = copy(field)
|
|
505
|
+
setattr(cls, key, clone)
|
|
506
|
+
typedfields[key] = clone
|
|
500
507
|
|
|
501
508
|
# start with base classes and overwrite with current class:
|
|
502
509
|
relationships = filter_out(full_dict, Relationship) | relationships | filter_out(other_kwargs, Relationship)
|
typedal/mixins.py
CHANGED
|
@@ -7,13 +7,20 @@ Mixins can add reusable fields and behavior (optimally both, otherwise it doesn'
|
|
|
7
7
|
import base64
|
|
8
8
|
import os
|
|
9
9
|
import typing
|
|
10
|
+
import warnings
|
|
10
11
|
from datetime import datetime
|
|
11
|
-
from typing import Any
|
|
12
|
+
from typing import Any, Optional
|
|
12
13
|
|
|
13
14
|
from slugify import slugify
|
|
14
15
|
|
|
15
|
-
from .core import
|
|
16
|
-
|
|
16
|
+
from .core import ( # noqa F401 - used by example in docstring
|
|
17
|
+
QueryBuilder,
|
|
18
|
+
T_MetaInstance,
|
|
19
|
+
TableMeta,
|
|
20
|
+
TypeDAL,
|
|
21
|
+
TypedTable,
|
|
22
|
+
_TypedTable,
|
|
23
|
+
)
|
|
17
24
|
from .fields import DatetimeField, StringField
|
|
18
25
|
from .types import OpRow, Set
|
|
19
26
|
|
|
@@ -79,7 +86,7 @@ class SlugMixin(Mixin):
|
|
|
79
86
|
Some random bytes are added at the end to prevent duplicates.
|
|
80
87
|
|
|
81
88
|
Example:
|
|
82
|
-
>>> class MyTable(TypedTable, SlugMixin, slug_field="some_name"):
|
|
89
|
+
>>> class MyTable(TypedTable, SlugMixin, slug_field="some_name", slug_suffix_length=8):
|
|
83
90
|
>>> some_name: str
|
|
84
91
|
>>> ...
|
|
85
92
|
"""
|
|
@@ -95,11 +102,11 @@ class SlugMixin(Mixin):
|
|
|
95
102
|
},
|
|
96
103
|
) # set via init subclass
|
|
97
104
|
|
|
98
|
-
def __init_subclass__(cls, slug_field: str = None,
|
|
105
|
+
def __init_subclass__(cls, slug_field: str = None, slug_suffix_length: int = 0, **kw: Any) -> None:
|
|
99
106
|
"""
|
|
100
107
|
Bind 'slug field' option to be used later (on_define).
|
|
101
108
|
|
|
102
|
-
You can control the length of the random suffix with the `
|
|
109
|
+
You can control the length of the random suffix with the `slug_suffix_length` option (0 is no suffix).
|
|
103
110
|
"""
|
|
104
111
|
# unfortunately, PyCharm and mypy do not recognize/autocomplete/typecheck init subclass (keyword) arguments.
|
|
105
112
|
if slug_field is None:
|
|
@@ -108,6 +115,14 @@ class SlugMixin(Mixin):
|
|
|
108
115
|
"e.g. `class MyClass(TypedTable, SlugMixin, slug_field='title'): ...`"
|
|
109
116
|
)
|
|
110
117
|
|
|
118
|
+
if "slug_suffix" in kw:
|
|
119
|
+
warnings.warn(
|
|
120
|
+
"The 'slug_suffix' option is deprecated, use 'slug_suffix_length' instead.",
|
|
121
|
+
DeprecationWarning,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
slug_suffix = slug_suffix_length or kw.get("slug_suffix", 0)
|
|
125
|
+
|
|
111
126
|
cls.__settings__ = {
|
|
112
127
|
"slug_field": slug_field,
|
|
113
128
|
"slug_suffix": slug_suffix,
|
|
@@ -133,3 +148,25 @@ class SlugMixin(Mixin):
|
|
|
133
148
|
row["slug"] = slugify(generated_slug)
|
|
134
149
|
|
|
135
150
|
cls._before_insert.append(generate_slug_before_insert)
|
|
151
|
+
|
|
152
|
+
@classmethod
|
|
153
|
+
def from_slug(cls: typing.Type[T_MetaInstance], slug: str, join: bool = True) -> Optional[T_MetaInstance]:
|
|
154
|
+
"""
|
|
155
|
+
Find a row by its slug.
|
|
156
|
+
"""
|
|
157
|
+
builder = cls.where(slug=slug)
|
|
158
|
+
if join:
|
|
159
|
+
builder = builder.join()
|
|
160
|
+
|
|
161
|
+
return builder.first()
|
|
162
|
+
|
|
163
|
+
@classmethod
|
|
164
|
+
def from_slug_or_fail(cls: typing.Type[T_MetaInstance], slug: str, join: bool = True) -> T_MetaInstance:
|
|
165
|
+
"""
|
|
166
|
+
Find a row by its slug, or raise an error if it doesn't exist.
|
|
167
|
+
"""
|
|
168
|
+
builder = cls.where(slug=slug)
|
|
169
|
+
if join:
|
|
170
|
+
builder = builder.join()
|
|
171
|
+
|
|
172
|
+
return builder.first_or_fail()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: TypeDAL
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: Typing support for PyDAL
|
|
5
5
|
Project-URL: Documentation, https://typedal.readthedocs.io/
|
|
6
6
|
Project-URL: Issues, https://github.com/trialandsuccess/TypeDAL/issues
|
|
@@ -35,6 +35,7 @@ Requires-Dist: mkdocs-dracula-theme; extra == 'dev'
|
|
|
35
35
|
Requires-Dist: pytest-mypy-testing; extra == 'dev'
|
|
36
36
|
Requires-Dist: python-semantic-release<8; extra == 'dev'
|
|
37
37
|
Requires-Dist: su6[all]; extra == 'dev'
|
|
38
|
+
Requires-Dist: testcontainers; extra == 'dev'
|
|
38
39
|
Requires-Dist: types-pyyaml; extra == 'dev'
|
|
39
40
|
Requires-Dist: types-tabulate; extra == 'dev'
|
|
40
41
|
Provides-Extra: migrations
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
typedal/__about__.py,sha256=
|
|
1
|
+
typedal/__about__.py,sha256=JM7UvclHJLbyevmmJGGt8HQwzgu3SMpy7q2WeNEm9Io,206
|
|
2
2
|
typedal/__init__.py,sha256=QQpLiVl9w9hm2LBxey49Y_tCF_VB2bScVaS_mCjYy54,366
|
|
3
3
|
typedal/caching.py,sha256=8UABVAhOlBpL96ykmqhxLaFYOe-XeAh7JoGh57OkxP8,11818
|
|
4
4
|
typedal/cli.py,sha256=3tge8B-YjgjMC6425-RMczmWvpOTfWV5QYPXRY23IWA,18200
|
|
5
5
|
typedal/config.py,sha256=jS1K0_1F5rwJtvwTZ-qR29ZCX7WlyORGEIFvfSnusko,11645
|
|
6
|
-
typedal/core.py,sha256=
|
|
6
|
+
typedal/core.py,sha256=tocfC9KDnuOoPgUTpBhFo2WGTupS5Y0esyFSTcANwLc,95866
|
|
7
7
|
typedal/fields.py,sha256=z2PD9vLWqBR_zXtiY0DthqTG4AeF3yxKoeuVfGXnSdg,5197
|
|
8
8
|
typedal/for_py4web.py,sha256=d07b8hL_PvNDUS26Z5fDH2OxWb-IETBuAFPSzrRwm04,1285
|
|
9
9
|
typedal/for_web2py.py,sha256=4RHgzGXgKIO_BYB-7adC5e35u52rX-p1t4tPEz-NK24,1867
|
|
10
10
|
typedal/helpers.py,sha256=mtRYPFlS0dx2wK8kYSJ4vm1wsTXRkdPumFRlOAjF_xU,7177
|
|
11
|
-
typedal/mixins.py,sha256=
|
|
11
|
+
typedal/mixins.py,sha256=OHhVYLBGTzPSJKgp1uovBs1Y6NJa0d-DxHTOk9LyOXA,5414
|
|
12
12
|
typedal/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
typedal/types.py,sha256=1kGkNX6vfGg6ln84AG558C4Zx5ACRz-emrUTnuy-rRY,3410
|
|
14
14
|
typedal/web2py_py4web_shared.py,sha256=VK9T8P5UwVLvfNBsY4q79ANcABv-jX76YKADt1Zz_co,1539
|
|
15
15
|
typedal/serializers/as_json.py,sha256=ffo152W-sARYXym4BzwX709rrO2-QwKk2KunWY8RNl4,2229
|
|
16
|
-
typedal-3.
|
|
17
|
-
typedal-3.
|
|
18
|
-
typedal-3.
|
|
19
|
-
typedal-3.
|
|
16
|
+
typedal-3.2.0.dist-info/METADATA,sha256=foiNGED0K4DE5WJOKqWZt693_ms7zMp8JO8GXbblkok,9316
|
|
17
|
+
typedal-3.2.0.dist-info/WHEEL,sha256=uNdcs2TADwSd5pVaP0Z_kcjcvvTUklh2S7bxZMF8Uj0,87
|
|
18
|
+
typedal-3.2.0.dist-info/entry_points.txt,sha256=m1wqcc_10rHWPdlQ71zEkmJDADUAnZtn7Jac_6mbyUc,44
|
|
19
|
+
typedal-3.2.0.dist-info/RECORD,,
|
|
File without changes
|