Pydantic Types#
pyticktick.models.pydantic
#
Generic custom pydantic types, not specific to any API version.
Classes:
Name | Description |
---|---|
Color |
Represents a color in pydantic-based TickTick models. |
HttpUrl |
Represents an HTTP URL in pydantic-based TickTick models. |
Color
#
Bases: Color
Represents a color in pydantic-based TickTick models.
Methods:
Name | Description |
---|---|
__get_pydantic_core_schema__ |
Change the serialization logic of the color field to always be a string. |
__str__ |
Return the color as a hex string. |
__get_pydantic_core_schema__
classmethod
#
__get_pydantic_core_schema__(
source: type[Any], handler: Callable[[Any], CoreSchema]
) -> core_schema.CoreSchema
Change the serialization logic of the color field to always be a string.
This method mirrors the logic of the standard __get_pydantic_core_schema__
method
in pydantic_extra_types.color.Color
,
but changes the when_used
parameter to be "always"
instead of the default of
"json-unless-none"
.
Source code in src/pyticktick/models/pydantic.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
__str__
#
__str__() -> str
Return the color as a hex string.
TickTick uses the long hex format for colors, so this method allows for easy
serialization of the color field into the correct format. Equivalent to calling
as_hex(format="long")
.
It will be lowercase and always have 7 characters (and #
): #rrggbb
.
Example
color = Color((0, 255, 255))
assert color.as_named() == "cyan"
assert str(color) == "#00ffff"
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The color as a hex string. |
Source code in src/pyticktick/models/pydantic.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
HttpUrl
#
Bases: HttpUrl
Represents an HTTP URL in pydantic-based TickTick models.
Methods:
Name | Description |
---|---|
join |
Join the current URL with additional path segments. |
join
#
join(*args: str) -> HttpUrl
Join the current URL with additional path segments.
This method is a convenience method to join additional path segments to the
current URL. It takes its inspiration from the urllib.parse.urljoin
and pathlib.PurePath.joinpath
methods in Python.
Example
from pyticktick.models.v2 import HttpUrl
url = HttpUrl("https://example.com")
assert url.join("foo") == HttpUrl("https://example.com/foo")
assert url.join("foo", "bar") == HttpUrl("https://example.com/foo/bar")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
str
|
The path segments to join with the current URL. |
()
|
Returns:
Name | Type | Description |
---|---|---|
HttpUrl |
HttpUrl
|
A new URL with the path segments joined to the current URL. |
Source code in src/pyticktick/models/pydantic.py
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 |
|