From d09393a00403485745bffd608986091e311edccc Mon Sep 17 00:00:00 2001 From: alex-berlin-tv Date: Fri, 7 Jul 2023 17:16:09 +0200 Subject: [PATCH 1/2] Specify inheritance of APIToken and JWTAuthToken to AuthToken This omits the Pyright warning when an APIToken/JWAuthToken is used in the creation of a new NocoDBRequests instance. --- nocodb/nocodb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nocodb/nocodb.py b/nocodb/nocodb.py index 3d7eb07..1fe801e 100644 --- a/nocodb/nocodb.py +++ b/nocodb/nocodb.py @@ -32,7 +32,7 @@ def get_header(self) -> dict: pass -class APIToken: +class APIToken(AuthToken): def __init__(self, token: str): self.__token = token @@ -40,7 +40,7 @@ def get_header(self) -> dict: return {"xc-token": self.__token} -class JWTAuthToken: +class JWTAuthToken(AuthToken): def __init__(self, token: str): self.__token = token From 0e11dcc827e0f6d80a9fb94efd4a4e4680f109fb Mon Sep 17 00:00:00 2001 From: alex-berlin-tv Date: Tue, 11 Jul 2023 14:40:51 +0200 Subject: [PATCH 2/2] Add a new relation. This implements the "relation row add" POST command of noco. Allowing the user to link to another record in another table using the LinkToAnotherRecord field. --- nocodb/api.py | 26 ++++++++++++++++++++++++-- nocodb/infra/requests_client.py | 16 ++++++++++++++++ nocodb/nocodb.py | 11 +++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/nocodb/api.py b/nocodb/api.py index 296fa21..b0fffdc 100644 --- a/nocodb/api.py +++ b/nocodb/api.py @@ -1,4 +1,5 @@ from enum import Enum +from typing import Optional from urllib.parse import urljoin from .nocodb import NocoDBProject @@ -50,6 +51,27 @@ def get_row_detail_uri( ) )) + def get_row_relation_create_uri( + self, + project: NocoDBProject, + table: str, + relation_type: str, + row_id: int, + column_name: str, + ref_row_id: int, + ) -> str: + return urljoin(self.__base_data_uri, "/".join( + ( + project.org_name, + project.project_name, + table, + str(row_id), + relation_type, + column_name, + str(ref_row_id), + ) + )) + def get_nested_relations_rows_list_uri( self, project: NocoDBProject, @@ -86,7 +108,7 @@ def get_project_tables_uri( )) def get_table_meta_uri( - self, tableId: str, operation: str = None, + self, tableId: str, operation: Optional[str] = None, ) -> str: additional_path = [] if operation is not None: @@ -100,7 +122,7 @@ def get_table_meta_uri( )) def get_column_uri( - self, columnId: str, operation: str = None, + self, columnId: str, operation: Optional[str] = None, ) -> str: additional_path = [] if operation is not None: diff --git a/nocodb/infra/requests_client.py b/nocodb/infra/requests_client.py index 98e63b5..3e43b1d 100644 --- a/nocodb/infra/requests_client.py +++ b/nocodb/infra/requests_client.py @@ -103,6 +103,22 @@ def table_find_one( params=get_query_params(filter_obj, params), ).json() + def table_row_relation_create( + self, + project: NocoDBProject, + table: str, + relation_type: str, + row_id: int, + column_name: str, + ref_row_id: int, + ) -> dict: + return self._request( + "POST", + self.__api_info.get_row_relation_create_uri( + project, table, relation_type, row_id, column_name, ref_row_id + ), + ).json() + def table_row_nested_relations_list( self, project: NocoDBProject, diff --git a/nocodb/nocodb.py b/nocodb/nocodb.py index 1fe801e..6a456b8 100644 --- a/nocodb/nocodb.py +++ b/nocodb/nocodb.py @@ -101,6 +101,17 @@ def table_row_delete( ) -> int: pass + @abstractmethod + def table_row_relation_create( + self, + project: NocoDBProject, + relation_type: str, + row_id: int, + column_name: str, + ref_row_id: int, + ) -> dict: + pass + @abstractmethod def table_row_nested_relations_list( self,