1
0

Custom fields

This commit is contained in:
Jon Michael Aanes 2024-10-01 16:06:06 +02:00
parent ce10f41330
commit bb61aa810c
3 changed files with 60 additions and 8 deletions

View File

@ -53,10 +53,12 @@ Limitations:
Following features are work in progress: Following features are work in progress:
- [ ] Frontmatter: Update Tags - [ ] Frontmatter: Writable Tags
- [ ] Frontmatter: Updated assigned members - [ ] Frontmatter: Writable assigned members
- [ ] Frontmatter: Arbitrary structured data? Read-only. - [ ] Frontmatter: Writable tasks.
- [ ] Frontmatter: Dependencies. As vault links in Obsidian mode. - [ ] 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. - [ ] Allow users to toggle Obsidian mode, instead of being default.
- [ ] Get the correct last-modified date. - [ ] Get the correct last-modified date.
- [ ] Improve cache behaviour. User and tags can have much longer cache times. - [ ] Improve cache behaviour. User and tags can have much longer cache times.

View File

@ -18,6 +18,8 @@ from .favro_data_model import (
TagInfo, TagInfo,
UserId, UserId,
UserInfo, UserInfo,
CustomFieldId,
CustomFieldInfo,
) )
from .favro_markdown import CardContents 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_UPDATE_CARD = URL_API_ROOT + '/cards/{card_id}'
URL_GET_USER = URL_API_ROOT + '/users/{user_id}' URL_GET_USER = URL_API_ROOT + '/users/{user_id}'
URL_GET_TAG = URL_API_ROOT + '/tags/{tag_id}' URL_GET_TAG = URL_API_ROOT + '/tags/{tag_id}'
URL_GET_CUSTOM_FIELD = URL_API_ROOT + '/customfields/{custom_field_id}'
class CardCache: class CardCache:
@ -164,6 +167,10 @@ class FavroClient:
response = self.session.get(URL_GET_TAG.format(tag_id=tag_id.raw_id)) response = self.session.get(URL_GET_TAG.format(tag_id=tag_id.raw_id))
return TagInfo.from_json(response.json()) 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: def _invalidate_cache(self, card_id: CardId) -> None:
card = self.cache.remove(card_id) card = self.cache.remove(card_id)
if card: if card:

View File

@ -33,6 +33,18 @@ class UserId:
class OrganizationId: class OrganizationId:
raw_id: str 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) @dataclasses.dataclass(frozen=True)
class CardAssignment: class CardAssignment:
@ -69,10 +81,6 @@ class TagId:
raw_id: str raw_id: str
@dataclasses.dataclass(frozen=True)
class CustomFieldId:
raw_id: str
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class TagInfo: class TagInfo:
@ -90,6 +98,41 @@ class TagInfo:
json.get('color'), 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) @dataclasses.dataclass(frozen=True)
class CustomField: class CustomField: