|
1 |
| -from labkey.utils import json_dumps, ServerContext |
| 1 | +from .server_context import ServerContext |
| 2 | +from labkey.utils import json_dumps |
2 | 3 |
|
3 | 4 |
|
4 |
| -def create(server_context, name, container_path=None, description=None, folderType=None, isWorkbook=None, title=None): |
5 |
| - # type: (ServerContext, str, str, str, str, bool, str) -> dict |
| 5 | +def create( |
| 6 | + server_context: ServerContext, |
| 7 | + name: str, |
| 8 | + container_path: str = None, |
| 9 | + description: str = None, |
| 10 | + folder_type: str = None, |
| 11 | + is_workbook: bool = None, |
| 12 | + title: str = None, |
| 13 | +) -> dict: |
6 | 14 | """
|
7 | 15 | Create a container in LabKey.
|
8 | 16 |
|
9 | 17 | :param server_context: A LabKey server context. See utils.create_server_context.
|
10 | 18 | :param name: The name of the container.
|
11 | 19 | :param container_path: the path of where you want to create the container.
|
12 | 20 | :param description: a description for the container.
|
13 |
| - :param folderType: the desired folder type for the container. |
14 |
| - :param isWorkbook: sets whether the container is a workbook. |
| 21 | + :param folder_type: the desired folder type for the container. |
| 22 | + :param is_workbook: sets whether the container is a workbook. |
15 | 23 | :param title: the title for the container.
|
16 | 24 | :return:
|
17 | 25 | """
|
18 |
| - headers = {'Content-Type': 'application/json'} |
19 |
| - url = server_context.build_url('core', 'createContainer.api', container_path) |
| 26 | + headers = {"Content-Type": "application/json"} |
| 27 | + url = server_context.build_url("core", "createContainer.api", container_path) |
20 | 28 | payload = {
|
21 |
| - 'description': description, |
22 |
| - 'folderType': folderType, |
23 |
| - 'isWorkbook': isWorkbook, |
24 |
| - 'name': name, |
25 |
| - 'title': title, |
| 29 | + "description": description, |
| 30 | + "folderType": folder_type, |
| 31 | + "isWorkbook": is_workbook, |
| 32 | + "name": name, |
| 33 | + "title": title, |
26 | 34 | }
|
27 | 35 | return server_context.make_request(url, json_dumps(payload), headers=headers)
|
28 | 36 |
|
29 | 37 |
|
30 |
| -def delete(server_context, container_path=None): |
31 |
| - # type: (ServerContext, str) |
| 38 | +def delete(server_context: ServerContext, container_path: str = None) -> any: |
32 | 39 | """
|
33 | 40 | Deletes a container at the given container_path, or at the server_context's container path
|
34 | 41 | :param server_context: A LabKey server context. See utils.create_server_context.
|
35 | 42 | :param container_path: The path of the container to delete.
|
36 | 43 | :return:
|
37 | 44 | """
|
38 |
| - headers = {'Content-Type': 'application/json'} |
39 |
| - url = server_context.build_url('core', 'deleteContainer.api', container_path) |
| 45 | + headers = {"Content-Type": "application/json"} |
| 46 | + url = server_context.build_url("core", "deleteContainer.api", container_path) |
40 | 47 | return server_context.make_request(url, None, headers=headers)
|
| 48 | + |
| 49 | + |
| 50 | +class ContainerWrapper: |
| 51 | + """ |
| 52 | + Wrapper for all of the API methods exposed in the container module. Used by the APIWrapper class. |
| 53 | + """ |
| 54 | + |
| 55 | + def __init__(self, server_context: ServerContext): |
| 56 | + self.server_context = server_context |
| 57 | + |
| 58 | + def create( |
| 59 | + self, |
| 60 | + name: str, |
| 61 | + container_path: str = None, |
| 62 | + description: str = None, |
| 63 | + folder_type: str = None, |
| 64 | + is_workbook: bool = None, |
| 65 | + title: str = None, |
| 66 | + ): |
| 67 | + return create( |
| 68 | + self.server_context, name, container_path, description, folder_type, is_workbook, title |
| 69 | + ) |
| 70 | + |
| 71 | + def delete(self, container_path: str = None): |
| 72 | + return delete(self.server_context, container_path) |
0 commit comments