Finaliza ajustes para iniciar Repositorio Git do SDK de Integração do Notion separado do meu projeto original
--- - Cria singleton de `client` com func `configure` para inicializar e `get_instance` para buscar instância do client; - Ajusta clients para buscar headers vindo do pai `client` e fixa versão legacy no client de databases; - Adiciona inicialização de `client` no init do projeto com api_token e api_version informados pelo usuário; - Altera `NotionConfig` para inserir `database_id` no lugar de `database_name`; - Altera sistema para receber `database_id` no lugar de `database_name`; - Altera tipo de `properties` em `schemas.responses.pages.Page` de `Union[Dict[str, Any]], TDB` para `Union[Any, TDB]` para resolver reclamações de type hint; - Adiciona param `generic_response` no init de `client` e nos clients e databases e pages para pular uso de mapping ao usar `.generic`; - Adiciona param `raw_response` para pular parser e mappings e retornar resposta original da api; - Finaliza `types` com subpastas para importações mas com init mãe vazio para evitar dependência circular e permitir uso de `notion.types.` pelo usuário; - Remove importações do projeto original não relacionadas com o SDK; - Adiciona param `timezone` na func `start_date` em `orm.common.SetProperty` que antes vinha do env, para posteriormente puxar da init da integração; - Monta `LICENSE`, `README.md` e `pyproject.toml` base simples para commit inicial do projeto permitindo build de pacote; ---
This commit is contained in:
Executable
+12
@@ -0,0 +1,12 @@
|
||||
import json
|
||||
from ..QueryFilter import QueryFilter
|
||||
|
||||
filter1 = QueryFilter.and_(
|
||||
QueryFilter.title("Name", "contains", "Teste"),
|
||||
QueryFilter.or_(
|
||||
QueryFilter.number("Value", "greater_than", 10),
|
||||
QueryFilter.number("Value", "less_than", 5)
|
||||
)
|
||||
)
|
||||
|
||||
print(json.dumps({"filter":filter1.to_dict()}))
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
import json
|
||||
from ..QuerySort import QuerySort
|
||||
|
||||
sort1 = QuerySort.ascending("Teste")
|
||||
|
||||
print(json.dumps({"sorts":sort1.to_dict()}))
|
||||
|
||||
sort2 = QuerySort.and_(
|
||||
QuerySort.ascending("Teste")
|
||||
)
|
||||
|
||||
print(json.dumps({"sorts":sort2.to_dict()}))
|
||||
Executable
+541
@@ -0,0 +1,541 @@
|
||||
from typing import Any, Dict, Literal, Union
|
||||
from datetime import datetime, date
|
||||
|
||||
class _NotionFilter:
|
||||
|
||||
"Classe base para filtros do Notion"
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"Converte o filtro para o formato JSON do Notion"
|
||||
raise NotImplementedError
|
||||
|
||||
def and_(self, *filters: '_NotionFilter') -> '_NotionFilter':
|
||||
"Combina este filtro com outros usando AND"
|
||||
return _AndFilter(self, *filters)
|
||||
|
||||
def or_(self, *filters: '_NotionFilter') -> '_NotionFilter':
|
||||
"Combina este filtro com outros usando OR"
|
||||
return _OrFilter(self, *filters)
|
||||
|
||||
class _PropertyFilter(_NotionFilter):
|
||||
|
||||
"Filtro para uma propriedade específica"
|
||||
|
||||
def __init__(self,
|
||||
property_name: str,
|
||||
property_type: str,
|
||||
condition: str,
|
||||
value: Any
|
||||
):
|
||||
self.property_name = property_name
|
||||
self.property_type = property_type
|
||||
self.condition = condition
|
||||
self.value = value
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"property": self.property_name,
|
||||
self.property_type: {
|
||||
self.condition: self.value
|
||||
}
|
||||
}
|
||||
|
||||
class _AndFilter(_NotionFilter):
|
||||
|
||||
"Combina múltiplos filtros com AND"
|
||||
|
||||
def __init__(self, *filters: _NotionFilter):
|
||||
self.filters = list(filters)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"and": [filter_obj.to_dict() for filter_obj in self.filters]
|
||||
}
|
||||
|
||||
class _OrFilter(_NotionFilter):
|
||||
|
||||
"Combina múltiplos filtros com OR"
|
||||
|
||||
def __init__(self, *filters: _NotionFilter):
|
||||
self.filters = list(filters)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"or": [filter_obj.to_dict() for filter_obj in self.filters]
|
||||
}
|
||||
|
||||
class QueryFilter:
|
||||
|
||||
"Builder principal para criar filtros"
|
||||
|
||||
@staticmethod
|
||||
def and_(*filters: _NotionFilter) -> _AndFilter:
|
||||
"Combina filtros com AND"
|
||||
return _AndFilter(*filters)
|
||||
|
||||
@staticmethod
|
||||
def or_(*filters: _NotionFilter) -> _OrFilter:
|
||||
"Combina filtros com OR"
|
||||
return _OrFilter(*filters)
|
||||
|
||||
@staticmethod
|
||||
def created_time(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"before",
|
||||
"after",
|
||||
"on_or_before",
|
||||
"on_or_after",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[date, Literal[True]]
|
||||
):
|
||||
if isinstance(value, date):
|
||||
property_value = value.strftime("%Y-%m-%d")
|
||||
else:
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "created_time",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def last_edited_time(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"before",
|
||||
"after",
|
||||
"on_or_before",
|
||||
"on_or_after",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[date, Literal[True]]
|
||||
):
|
||||
if isinstance(value, date):
|
||||
property_value = value.strftime("%Y-%m-%d")
|
||||
else:
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "last_edited_time",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def title(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"starts_with",
|
||||
"ends_with",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: str
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "title",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def rich_text(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"starts_with",
|
||||
"ends_with",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: str
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "rich_text",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def number(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"greater_than",
|
||||
"less_than",
|
||||
"greater_than_or_equal_to",
|
||||
"less_than_or_equal_to",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[float, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "number",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def checkbox(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal"
|
||||
],
|
||||
value: Literal[True]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "checkbox",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def select(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "select",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def multi_select(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "multi_select",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def status(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "status",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def dates(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"after",
|
||||
"on_or_before",
|
||||
"on_or_after",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[date, datetime, Literal[True]]
|
||||
):
|
||||
if isinstance(value, date):
|
||||
property_value = value.strftime("%Y-%m-%d")
|
||||
elif isinstance(value, datetime):
|
||||
property_value = value.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
else:
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "date",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def people(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "people",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def files(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Literal[True]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "files",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def url(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"starts_with",
|
||||
"ends_with",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "url",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def email(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"starts_with",
|
||||
"ends_with",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "email",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def phone_number(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"starts_with",
|
||||
"ends_with",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "phone_number",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def relation(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "relation",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def created_by(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "created_by",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def last_edited_by(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[str, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "last_edited_by",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def formula(
|
||||
property_name: str,
|
||||
formula_type: Literal["string", "checkbox", "number", "date"],
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"contains",
|
||||
"does_not_contain",
|
||||
"starts_with",
|
||||
"ends_with",
|
||||
"is_empty",
|
||||
"is_not_empty",
|
||||
"greater_than",
|
||||
"less_than",
|
||||
"greater_than_or_equal_to",
|
||||
"less_than_or_equal_to",
|
||||
"before",
|
||||
"after",
|
||||
"on_or_before",
|
||||
"on_or_after"
|
||||
],
|
||||
value: Union[str, bool, float, date, datetime, Literal[True]]
|
||||
) -> _PropertyFilter:
|
||||
if isinstance(value, date):
|
||||
property_value = value.strftime("%Y-%m-%d")
|
||||
elif isinstance(value, datetime):
|
||||
property_value = value.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
else:
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = f"formula.{formula_type}",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def unique_id(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"equals",
|
||||
"does_not_equal",
|
||||
"greater_than",
|
||||
"less_than",
|
||||
"greater_than_or_equal_to",
|
||||
"less_than_or_equal_to",
|
||||
"is_empty",
|
||||
"is_not_empty"
|
||||
],
|
||||
value: Union[float, Literal[True]]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "unique_id",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def verification(
|
||||
property_name: str,
|
||||
condition: Literal[
|
||||
"status"
|
||||
],
|
||||
value: Literal["verified", "expired", "none", ""]
|
||||
):
|
||||
property_value = value
|
||||
return _PropertyFilter(
|
||||
property_name = property_name,
|
||||
property_type = "verification",
|
||||
condition = condition,
|
||||
value = property_value
|
||||
)
|
||||
|
||||
__all__ = ["QueryFilter"]
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
from typing import Any, Dict, Literal, List
|
||||
|
||||
class _NotionSort:
|
||||
|
||||
"Classe base para classificação do Notion"
|
||||
|
||||
def _sort_to_dict(self) -> Dict[str, Any]:
|
||||
"Converte uma classificação para o formato JSON do Notion"
|
||||
raise NotImplementedError
|
||||
|
||||
def to_dict(self) -> List[Dict[str, Any]]:
|
||||
"Converte uma ou multiplas classificações para o formato JSON do Notion"
|
||||
raise NotImplementedError
|
||||
|
||||
class _PropertySort(_NotionSort):
|
||||
|
||||
"Classificação para uma propriedade específica"
|
||||
|
||||
def __init__(self,
|
||||
property_name: str,
|
||||
direction: Literal["ascending", "descending"]
|
||||
):
|
||||
self.property_name = property_name
|
||||
self.direction = direction
|
||||
|
||||
def _sort_to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"property": self.property_name,
|
||||
"direction": self.direction
|
||||
}
|
||||
|
||||
def to_dict(self) -> List[Dict[str, Any]]:
|
||||
return [self._sort_to_dict()]
|
||||
|
||||
class _MultiSort(_NotionSort):
|
||||
|
||||
"Combina múltiplas classificações com vírgula"
|
||||
|
||||
def __init__(self, *sorts: _NotionSort):
|
||||
self.sorts = sorts
|
||||
|
||||
def to_dict(self) -> List[Dict[str, Any]]:
|
||||
return [sort_obj._sort_to_dict() for sort_obj in self.sorts]
|
||||
|
||||
class QuerySort:
|
||||
|
||||
"Builder principal para criar filtros"
|
||||
|
||||
@staticmethod
|
||||
def and_(*sorts: _NotionSort) -> _MultiSort:
|
||||
"Combina classificações com vírgula"
|
||||
return _MultiSort(*sorts)
|
||||
|
||||
@staticmethod
|
||||
def ascending(
|
||||
property_name: str
|
||||
):
|
||||
return _PropertySort(
|
||||
property_name = property_name,
|
||||
direction = "ascending"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def descending(
|
||||
property_name: str
|
||||
):
|
||||
return _PropertySort(
|
||||
property_name = property_name,
|
||||
direction = "descending"
|
||||
)
|
||||
|
||||
__all__ = ["QuerySort"]
|
||||
Executable
+231
@@ -0,0 +1,231 @@
|
||||
from typing import Dict, Any, Union, Optional, Literal, List, TYPE_CHECKING
|
||||
from datetime import datetime, date
|
||||
from pydantic import validate_call
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..repositories.pages.CreatePage import CreatePage
|
||||
from ..repositories.databases.CreateDatabasePage import CreateDatabasePage
|
||||
|
||||
class SetProperty:
|
||||
|
||||
def __init__(self,
|
||||
CreatePageClass : Union['CreatePage', 'CreateDatabasePage'],
|
||||
properties : Dict[str, Any]
|
||||
) -> None:
|
||||
self._CreatePage = CreatePageClass
|
||||
self._properties = properties
|
||||
|
||||
@validate_call
|
||||
def number(self,
|
||||
name : str,
|
||||
value : Optional[float]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"number": value
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def checkbox(self,
|
||||
name : str,
|
||||
value : Optional[bool]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"checkbox": value
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def start_date(self,
|
||||
name : str,
|
||||
value : Optional[Union[date, datetime]],
|
||||
timezone : str = "Etc/UTC"
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
if type(value) == date:
|
||||
self._properties[name] = {
|
||||
"date": {
|
||||
"start": value.strftime("%Y-%m-%d")
|
||||
}
|
||||
}
|
||||
elif type(value) == datetime:
|
||||
self._properties[name] = {
|
||||
"date": {
|
||||
"start": value.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"time_zone": timezone
|
||||
}
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def end_date(self,
|
||||
name : str,
|
||||
value : Optional[Union[date, datetime]]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
if not self._properties.get(name):
|
||||
raise KeyError("start_date is missing")
|
||||
date_value = None
|
||||
if type(value) == date:
|
||||
date_value = value.strftime("%Y-%m-%d")
|
||||
elif type(value) == datetime:
|
||||
date_value = value.strftime("%Y-%m-%dT%H:%M:%S")
|
||||
self._properties[name]["date"]["end"] = date_value
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def relation(self,
|
||||
name : str,
|
||||
value : Optional[str]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"relation": [
|
||||
{
|
||||
"id": str(value)
|
||||
}
|
||||
]
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def text(self,
|
||||
name : str,
|
||||
value : Optional[str]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"rich_text" : [
|
||||
{
|
||||
"type":"text",
|
||||
"text":{
|
||||
"content": value
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def rich_text(self,
|
||||
name : str,
|
||||
value : Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
value = [value] if isinstance(value, dict) else value
|
||||
self._properties[name] = {
|
||||
"rich_text" : value
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def select(self,
|
||||
name : str,
|
||||
value : Optional[str],
|
||||
color : Optional[Literal[
|
||||
"default",
|
||||
"gray",
|
||||
"brown",
|
||||
"orange",
|
||||
"yellow",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
"pink",
|
||||
"red"
|
||||
]] = None
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
if color:
|
||||
self._properties[name] = {
|
||||
"select" : {
|
||||
"name" : value,
|
||||
"color" : color
|
||||
}
|
||||
}
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"select" : {
|
||||
"name" : value
|
||||
}
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
# @validate_call
|
||||
# def multi_select(self, name : str, value : str):
|
||||
|
||||
# @validate_call
|
||||
# def status(self, name : str, value : str):
|
||||
|
||||
# @validate_call
|
||||
# def media(self, name : str, value : str):
|
||||
|
||||
@validate_call
|
||||
def url(self,
|
||||
name : str,
|
||||
value : Optional[str]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"url" : value
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def email(self,
|
||||
name : str,
|
||||
value : Optional[str]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
if "@" not in value:
|
||||
raise ValueError("Invalid email")
|
||||
self._properties[name] = {
|
||||
"email": str(value)
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def phone(self,
|
||||
name : str,
|
||||
value : Optional[str]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"phone_number": str(value)
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
@validate_call
|
||||
def person(self,
|
||||
name : str,
|
||||
value : Optional[str]
|
||||
):
|
||||
if value is None:
|
||||
return self._CreatePage
|
||||
self._properties[name] = {
|
||||
"people": [
|
||||
{
|
||||
"object": "user",
|
||||
"id": str(value)
|
||||
}
|
||||
]
|
||||
}
|
||||
return self._CreatePage
|
||||
|
||||
# @validate_call
|
||||
# def place(self, name : str, value : str):
|
||||
|
||||
__all__ = ["SetProperty"]
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
from .QueryFilter import QueryFilter as _QueryFilter
|
||||
from .QuerySort import QuerySort as _QuerySort
|
||||
from .SetProperty import SetProperty as _SetProperty
|
||||
|
||||
class _Common:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.QueryFilter = _QueryFilter
|
||||
self.QuerySort = _QuerySort
|
||||
self.SetProperty = _SetProperty
|
||||
|
||||
Common = _Common()
|
||||
__all__ = ["Common"]
|
||||
Reference in New Issue
Block a user