From bb61aa810c87a26d24e90f07d6f933ddf24d768e Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 1 Oct 2024 16:06:06 +0200 Subject: [PATCH] Custom fields --- favro_sync/__init__.py | 10 ++++--- favro_sync/favro_client.py | 7 +++++ favro_sync/favro_data_model.py | 51 +++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/favro_sync/__init__.py b/favro_sync/__init__.py index b7d8acb..f0d3065 100644 --- a/favro_sync/__init__.py +++ b/favro_sync/__init__.py @@ -53,10 +53,12 @@ Limitations: Following features are work in progress: -- [ ] Frontmatter: Update Tags -- [ ] Frontmatter: Updated assigned members -- [ ] Frontmatter: Arbitrary structured data? Read-only. -- [ ] Frontmatter: Dependencies. As vault links in Obsidian mode. +- [ ] Frontmatter: Writable Tags +- [ ] Frontmatter: Writable assigned members +- [ ] Frontmatter: Writable tasks. +- [ ] Frontmatter: Arbitrary structured data (Custom Fields)? Read-only. +- [ ] Frontmatter: Readable Dependencies. As vault links in Obsidian mode. +- [ ] Frontmatter: Writable Dependencies. - [ ] Allow users to toggle Obsidian mode, instead of being default. - [ ] Get the correct last-modified date. - [ ] Improve cache behaviour. User and tags can have much longer cache times. diff --git a/favro_sync/favro_client.py b/favro_sync/favro_client.py index b41a0e3..7547362 100644 --- a/favro_sync/favro_client.py +++ b/favro_sync/favro_client.py @@ -18,6 +18,8 @@ from .favro_data_model import ( TagInfo, UserId, UserInfo, + CustomFieldId, + CustomFieldInfo, ) from .favro_markdown import CardContents @@ -29,6 +31,7 @@ URL_GET_ALL_CARDS = URL_API_ROOT + '/cards' URL_UPDATE_CARD = URL_API_ROOT + '/cards/{card_id}' URL_GET_USER = URL_API_ROOT + '/users/{user_id}' URL_GET_TAG = URL_API_ROOT + '/tags/{tag_id}' +URL_GET_CUSTOM_FIELD = URL_API_ROOT + '/customfields/{custom_field_id}' class CardCache: @@ -164,6 +167,10 @@ class FavroClient: response = self.session.get(URL_GET_TAG.format(tag_id=tag_id.raw_id)) return TagInfo.from_json(response.json()) + def get_custom_field(self, tag_id: CustomFieldId) -> CustomFieldInfo: + response = self.session.get(URL_GET_CUSTOM_FIELD.format(custom_field_id=custom_field_id.raw_id)) + return CustomFieldInfo.from_json(response.json()) + def _invalidate_cache(self, card_id: CardId) -> None: card = self.cache.remove(card_id) if card: diff --git a/favro_sync/favro_data_model.py b/favro_sync/favro_data_model.py index 989aa1a..16cc53e 100644 --- a/favro_sync/favro_data_model.py +++ b/favro_sync/favro_data_model.py @@ -33,6 +33,18 @@ class UserId: class OrganizationId: raw_id: str +@dataclasses.dataclass(frozen=True) +class CustomFieldId: + raw_id: str + +@dataclasses.dataclass(frozen=True) +class WidgetCommonId: + raw_id: str + +@dataclasses.dataclass(frozen=True) +class CustomFieldItemId: + raw_id: str + @dataclasses.dataclass(frozen=True) class CardAssignment: @@ -69,10 +81,6 @@ class TagId: raw_id: str -@dataclasses.dataclass(frozen=True) -class CustomFieldId: - raw_id: str - @dataclasses.dataclass(frozen=True) class TagInfo: @@ -90,6 +98,41 @@ class TagInfo: json.get('color'), ) +@dataclasses.dataclass(frozen=True) +class CustomFieldItem: + """ Custom field item object. + Fields: + - customFieldItemId: The id of the custom field item. + - name: The name of the custom field item. + """ + custom_field_item_id: CustomFieldItemId + name: str + +@dataclasses.dataclass(frozen=True) +class CustomFieldInfo: + """ Custom field object. + + Fields: + - organizationId: The id of the organization that this custom field exists in. + - customFieldId: The id of the custom field. + - widgetCommonId: The shared id of the widget if the custom field is local to that widget. + - type: field type. Refer to allowed custom field types. + - name: name of the custom field. + - enabled: True if the custom field is currently enabled for the organization. + - customFieldItems: The list of items that this custom field can have in case it is a selectable one. + """ + organization_id : OrganizationId + custom_field_id : CustomFieldId + widget_common_id : WidgetCommonId + type: str + name: str + enabled: bool + custom_field_items: list[CustomFieldItem] + + @staticmethod + def from_json(json: dict[str, Any]) -> 'CustomFieldInfo': + pass # TODO + @dataclasses.dataclass(frozen=True) class CustomField: