Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "create_column" method to the boards resource #108

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ Getting started

monday.items.create_item(board_id='12345678', group_id='today', item_name='Do a thing')

**Available methods:** #### Items Resource (monday.items) -
``create_item(board_id, group_id, item_name, column_values=None, create_labels_if_missing=False)``
- Create an item on a board in the given group with name item_name.
**Available methods:**

- ``create_subitem(parent_item_id, subitem_name, column_values=None, create_labels_if_missing=False)``
- Create a subitem underneath a given parent item. Monday API will
Items Resource (monday.items)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- ``create_item(board_id, group_id, item_name, column_values=None, create_labels_if_missing=False)`` - Create an item on a board in the given group with name item_name.

- ``create_subitem(parent_item_id, subitem_name, column_values=None, create_labels_if_missing=False)`` - Create a subitem underneath a given parent item. Monday API will
return an error if the board you’re trying to add to does not have a
subitems column/at least one subitem created.

Expand Down Expand Up @@ -124,6 +125,11 @@ Boards Resource (monday.boards)
- ``create_board(board_name, board_kind, workspace_id)`` - Create board
with the given name and kind by (and optional) workspace id.

- ``create_column(board_id, column_title, column_description, column_type)`` - Create a new column
on a given board, with the given name, description, (and optional) column_type.
The column type defaults to text if not provided.


Users Resource (monday.users)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
3 changes: 3 additions & 0 deletions monday/graphqlclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def _send(self, query, variables):
files = [
('variables[file]', (variables['file'], open(variables['file'], 'rb')))
]
else:
headers['Content-Type'] = 'application/json'
payload = json.dumps({'query': query, "variables": json.dumps(variables)}).encode('utf-8')

try:
response = requests.request("POST", self.endpoint, headers=headers, data=payload, files=files)
Expand Down
22 changes: 21 additions & 1 deletion monday/query_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
# Eventually I will organize this file better but you know what today is not that day.

# ITEM RESOURCE QUERIES
def create_column_in_board(board_id, title, description, column_type):
# List of acceptable types 2023-04-17: https://asset.cloudinary.com/monday-platform-dev/cde9c7ca84b78ec7dde46cc5c8588946
query = '''mutation
{
create_column (
board_id: %s,
title: "%s",
description: "%s",
column_type: %s
) {
id
title
description
}
}''' % (board_id, title, description, column_type)
return query



def mutate_item_query(board_id, group_id, item_name, column_values,
create_labels_if_missing):
# Monday does not allow passing through non-JSON null values here,
Expand Down Expand Up @@ -308,7 +327,8 @@ def get_board_items_query(board_id: Union[str, int], limit: Optional[int] = None
name
column_values {
id
text
title
text
type
value
}
Expand Down
6 changes: 6 additions & 0 deletions monday/resources/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get_board_items_query,
get_columns_by_board_query,
create_board_by_workspace_query,
create_column_in_board,
)
from monday.resources.types import BoardKind, BoardState, BoardsOrderBy

Expand Down Expand Up @@ -33,3 +34,8 @@ def fetch_columns_by_board_id(self, board_ids):
def create_board(self, board_name: str, board_kind: BoardKind, workspace_id: int = None):
query = create_board_by_workspace_query(board_name, board_kind, workspace_id)
return self.client.execute(query)

def create_column(self, board_id, title, description, column_type='text'):
query = create_column_in_board(board_id, title, description, column_type)
return self.client.execute(query)
# TODO check all possible column types
3 changes: 3 additions & 0 deletions monday/tests/test_case_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ def setUp(self):
self.team_ids = [105939, 105940, 105941]
self.notification_text = "This is an awesome notification."
self.notification_target_type = "Project"
self.column_description = "some decription"
self.column_type = "text"


13 changes: 12 additions & 1 deletion monday/tests/test_group_resource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from monday.tests.test_case_resource import BaseTestCase
from monday.query_joins import get_groups_by_board_query, get_items_by_group_query, create_group_query, \
duplicate_group_query, archive_group_query, delete_group_query
duplicate_group_query, archive_group_query, delete_group_query, create_column_in_board


class GroupTestCase(BaseTestCase):
Expand Down Expand Up @@ -45,3 +45,14 @@ def test_archive_group_query(self):
self.assertIn(str(self.board_id), query)
self.assertIn(str(self.group_id), query)

def test_create_column_in_board(self):
query = create_column_in_board(
board_id=self.board_id,
title=self.column_id,
description=self.column_description,
column_type=self.column_type
)
self.assertIn(str(self.board_id), query)
self.assertIn(str(self.column_id), query)
self.assertIn(str(self.column_description), query)
self.assertIn(str(self.column_type), query)