TypeDAL 3.1.4__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 CHANGED
@@ -5,4 +5,4 @@ This file contains the Version info for this package.
5
5
  # SPDX-FileCopyrightText: 2023-present Robin van der Noord <robinvandernoord@gmail.com>
6
6
  #
7
7
  # SPDX-License-Identifier: MIT
8
- __version__ = "3.1.4"
8
+ __version__ = "3.2.0"
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 TypedTable # noqa F401 - used by example in docstring
16
- from .core import TypeDAL, _TypedTable
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, slug_suffix: int = 8, **kw: Any) -> 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 `slug_suffix` option (0 is no suffix).
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
1
+ Metadata-Version: 2.3
2
2
  Name: TypeDAL
3
- Version: 3.1.4
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,4 +1,4 @@
1
- typedal/__about__.py,sha256=rg1ktSg7m5s-wVEyJZGLexDBUkbBQvnRft88RSv-4tY,206
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
@@ -8,12 +8,12 @@ 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=UzuTgrJF30cowpKTHI4Y4iSub9wJoxo88XmrWHRrtGs,4361
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.1.4.dist-info/METADATA,sha256=yh1PzCqEG-XLvhPRLgD33O6fW-GAspkIKobbj7qNA5I,9270
17
- typedal-3.1.4.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
18
- typedal-3.1.4.dist-info/entry_points.txt,sha256=m1wqcc_10rHWPdlQ71zEkmJDADUAnZtn7Jac_6mbyUc,44
19
- typedal-3.1.4.dist-info/RECORD,,
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,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.17.1
2
+ Generator: hatchling 1.22.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any