Skip to content

Commit

Permalink
feat: write created illustration folder link to trello card
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyqu committed Jun 15, 2024
1 parent f6a8b5a commit 9a023c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
21 changes: 10 additions & 11 deletions src/focalboard/focalboard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,17 @@ def get_custom_fields(self, card_id: str) -> objects.CardCustomFields:
card_fields._data = card_labels
return card_fields

def set_card_custom_field(self, card_id, field_alias, value):
def set_card_custom_field(self, card: objects.TrelloCard, field_alias, value):
board_id = self.board_id
field_id = self.custom_fields_config[field_alias]
data = {
"updatedFields": {
"properties": {
field_id: value
}
"properties": card._fields_properties
}
}
data["updatedFields"]["properties"][field_id] = value
code = self._make_patch_request(
f"api/v2/boards/{board_id}/blocks/{card_id}", payload=data
f"api/v2/boards/{board_id}/blocks/{card.id}", payload=data
)
logger.debug(f"set_card_custom_field: {code}")

Expand Down Expand Up @@ -317,12 +316,12 @@ def get_cards(self, list_ids=None, board_id=None):
card = objects.TrelloCard.from_focalboard_dict(card_dict)
card.url = urljoin(self.url, f"{board_id}/{view_id}/{card.id}")
card.labels = []
for label_id in card_dict["fields"]["properties"].get(label_prop, []):
for label_id in card._fields_properties.get(label_prop, []):
for label in labels:
if label.id == label_id:
card.labels.append(label)
try:
due = card_dict["fields"]["properties"].get(due_prop, '{}')
due = card._fields_properties.get(due_prop, '{}')
due_ts = json.loads(due).get('to')
if due_ts:
card.due = datetime.fromtimestamp(due_ts // 1000)
Expand All @@ -331,17 +330,17 @@ def get_cards(self, list_ids=None, board_id=None):
print(e)
# TODO: move this to app state
for trello_list in lists:
if trello_list.id == card_dict["fields"]["properties"].get(
if trello_list.id == card._fields_properties.get(
list_prop, ""
):
card.lst = trello_list
break
else:
logger.error(f"List name not found for {card}")
# TODO: move this to app state
if len(card_dict["fields"]["properties"].get(member_prop, [])) > 0:
if len(card._fields_properties.get(member_prop, [])) > 0:
for member in members:
if member.id in card_dict["fields"]["properties"].get(
if member.id in card._fields_properties.get(
member_prop, []
):
card.members.append(member)
Expand Down Expand Up @@ -393,7 +392,7 @@ def _make_request(self, uri, payload={}):

def _make_patch_request(self, uri, payload={}):
response = requests.patch(
urljoin(self.url, uri), params=payload, headers=self.headers
urljoin(self.url, uri), json=payload, headers=self.headers
)
logger.debug(f"{response.url}")
return response.status_code, response.json()
2 changes: 1 addition & 1 deletion src/jobs/create_folders_for_illustrators_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _create_folders(
)
if app_context.trello_client.deprecated:
app_context.focalboard_client.set_card_custom_field(
card.id,
card,
TrelloCustomFieldTypeAlias.COVER,
card_fields.cover,
)
Expand Down
3 changes: 3 additions & 0 deletions src/trello/trello_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def __init__(self):
# TODO: move this to app state
self.lst = None
self.members = []
# focalboard fields
self._fields_properties = None

self._ok = True

Expand Down Expand Up @@ -263,6 +265,7 @@ def from_focalboard_dict(cls, data):
try:
card.id = data["id"]
card.name = html.escape(data["title"])
card._fields_properties = data["fields"]["properties"]
except Exception as e:
card._ok = False
logger.error(f"Bad card json {data}: {e}")
Expand Down

0 comments on commit 9a023c2

Please sign in to comment.