-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
217 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
__pycache__ | ||
testrun.py | ||
test_config.json* | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,107 @@ | ||
from __future__ import annotations | ||
|
||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from nocodb.Table import Table | ||
from nocodb import NocoDB | ||
|
||
|
||
class DataType: | ||
|
||
def __init__(self, uidt: str) -> None: | ||
self.name = uidt | ||
|
||
def __str__(self) -> str: | ||
return self.name | ||
|
||
|
||
class Column: | ||
def __init__(self, **kwargs) -> None: | ||
def __init__(self, noco_db: "NocoDB",**kwargs) -> None: | ||
self.noco_db = noco_db | ||
self.title = kwargs["title"] | ||
self.column_id = kwargs["id"] | ||
self.table_id = kwargs["fk_model_id"] | ||
|
||
self.system = bool(kwargs["system"]) | ||
self.primary_key = bool(kwargs["pk"]) | ||
|
||
self.data_type = Column.DataType.get_data_type(kwargs["uidt"]) | ||
self.metadata = kwargs | ||
|
||
if "colOptions" in kwargs and "fk_related_model_id" in kwargs["colOptions"]: | ||
self.linked_table_id = kwargs["colOptions"]["fk_related_model_id"] | ||
|
||
def get_linked_table(self) -> Table: | ||
if hasattr(self, "linked_table_id"): | ||
return self.noco_db.get_table(self.linked_table_id) | ||
else: | ||
raise Exception("Not linked column!") | ||
|
||
@staticmethod | ||
def get_id_metadata() -> list[dict]: | ||
return [ | ||
{'title': 'Id', 'column_name': 'id', 'uidt': 'ID', | ||
{'title': 'Id', 'column_name': 'id', 'uidt': str(Column.DataType.ID), | ||
'dt': 'int4', 'np': '11', 'ns': '0', 'clen': None, | ||
'pk': True, 'pv': None, 'rqd': True, 'ct': 'int(11)', 'ai': True, | ||
'dtx': 'integer', 'dtxp': '11', }, | ||
{'title': 'Title', 'column_name': 'title', 'uidt': 'SingleLineText', | ||
{'title': 'Title', 'column_name': 'title', 'uidt': str(Column.DataType.SingleLineText), | ||
'dt': 'character varying', 'np': None, 'ns': None, 'clen': '45', | ||
'pk': False, 'pv': True, 'rqd': False, 'ct': 'varchar(45)', 'ai': False, | ||
'dtx': 'specificType', 'dtxp': '45', } | ||
] | ||
|
||
class DataType: | ||
Formula = DataType("Formula") | ||
|
||
LinkToAnotherRecord = DataType("LinkToAnotherRecord") | ||
Links = DataType("Links") | ||
|
||
Lookup = DataType("Lookup") | ||
Rollup = DataType("Rollup") | ||
|
||
Attachment = DataType("Attachment") | ||
AutoNumber = DataType("AutoNumber") | ||
Barcode = DataType("Barcode") | ||
Button = DataType("Button") | ||
Checkbox = DataType("Checkbox") | ||
Collaborator = DataType("Collaborator") | ||
Count = DataType("Count") | ||
CreatedBy = DataType("CreatedBy") | ||
CreatedTime = DataType("CreatedTime") | ||
Currency = DataType("Currency") | ||
Date = DataType("Date") | ||
DateTime = DataType("DateTime") | ||
Decimal = DataType("Decimal") | ||
Duration = DataType("Duration") | ||
Email = DataType("Email") | ||
ForeignKey = DataType("ForeignKey") | ||
GeoData = DataType("GeoData") | ||
Geometry = DataType("Geometry") | ||
ID = DataType("ID") | ||
JSON = DataType("JSON") | ||
LastModifiedBy = DataType("LastModifiedBy") | ||
LastModifiedTime = DataType("LastModifiedTime") | ||
LongText = DataType("LongText") | ||
MultiSelect = DataType("MultiSelect") | ||
Number = DataType("Number") | ||
Percent = DataType("Percent") | ||
PhoneNumber = DataType("PhoneNumber") | ||
QrCode = DataType("QrCode") | ||
Rating = DataType("Rating") | ||
SingleLineText = DataType("SingleLineText") | ||
SingleSelect = DataType("SingleSelect") | ||
SpecificDBType = DataType("SpecificDBType") | ||
Time = DataType("Time") | ||
URL = DataType("URL") | ||
User = DataType("User") | ||
Year = DataType("Year") | ||
|
||
@classmethod | ||
def get_data_type(cls, uidt: str) -> DataType: | ||
if hasattr(cls, uidt): | ||
return getattr(cls, uidt) | ||
else: | ||
raise Exception(f"Invalid datatype {uidt}") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.