smartsheet-tools 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,12 @@
1
1
  from datetime import datetime
2
2
  import re
3
3
  from smartsheet.models import Cell, Row, Folder, Sheet
4
+ from smartsheet.models import Column
4
5
 
5
6
  # Cache for column types to minimize API calls when correcting date formats
6
7
  _COLUMN_TYPE_CACHE = {}
8
+ _TITLE_TO_ID_CACHE = {}
9
+ _ID_TO_INDEX_CACHE = {}
7
10
 
8
11
  def norm(v):
9
12
  if v is None:
@@ -18,11 +21,15 @@ def disp_or_val(cell):
18
21
 
19
22
  def title_to_index(sheet):
20
23
  # authoritative positions from Smartsheet (not Python enumerate order)
21
- return {c.title: c.index for c in sheet.columns}
24
+ if sheet.id not in _TITLE_TO_ID_CACHE:
25
+ _TITLE_TO_ID_CACHE[sheet.id] = {c.title: c.index for c in sheet.columns}
26
+ return _TITLE_TO_ID_CACHE[sheet.id]
22
27
 
23
28
  def index_to_id(sheet):
24
29
  # authoritative positions from Smartsheet (not Python enumerate order)
25
- return {c.index: c.id for c in sheet.columns}
30
+ if sheet.id not in _ID_TO_INDEX_CACHE:
31
+ _ID_TO_INDEX_CACHE[sheet.id] = {c.index: c.id for c in sheet.columns}
32
+ return _ID_TO_INDEX_CACHE[sheet.id]
26
33
 
27
34
  def id_to_index(sheet):
28
35
  # authoritative positions from Smartsheet (not Python enumerate order)
@@ -92,18 +99,18 @@ def correct_date_format(isoformat_datetime, column_id, sheet_obj):
92
99
  return isoformat_datetime
93
100
  return None
94
101
 
95
- def new_cell(column_id, value=None, strict=False, formula=None):
102
+ def new_cell(column_id=None, value=None, strict=False, formula=None):
96
103
  new_cell = Cell()
97
- new_cell.column_id = column_id
104
+ if column_id is not None:
105
+ new_cell.column_id = column_id
98
106
  if formula is not None:
99
107
  new_cell.formula = formula
100
108
  else:
101
109
  new_cell.value = value
102
- if strict:
103
- new_cell.strict = True
110
+ new_cell.strict = strict
104
111
  return new_cell
105
112
 
106
- def new_row(cells=None, id=None, parent_id=None, to_top=False):
113
+ def new_row(cells=None, id=None, parent_id=None, to_top=False, locked=False):
107
114
  new_row = Row()
108
115
  if cells:
109
116
  new_row.cells = cells
@@ -113,6 +120,8 @@ def new_row(cells=None, id=None, parent_id=None, to_top=False):
113
120
  new_row.parent_id = parent_id
114
121
  if to_top:
115
122
  new_row.to_top = to_top
123
+ if locked:
124
+ new_row.locked = locked
116
125
  return new_row
117
126
 
118
127
  def walk_folder_for_sheets(smartsheet_client, folder_id):
@@ -143,4 +152,25 @@ def walk_workspace_for_folders(smartsheet_client, workspace_id):
143
152
 
144
153
  def walk_sheet_names_from_workspace(smartsheet_client, workspace_id):
145
154
  for sheet in walk_workspace_for_sheets(smartsheet_client, workspace_id):
146
- yield sheet.name
155
+ yield sheet.name
156
+
157
+ def new_column(column_type, title, index=None, id=None, options=None, symbol=None, primary=False, hidden=False, locked=False):
158
+ new_column = Column()
159
+
160
+ new_column.type = column_type
161
+ new_column.title = title
162
+ if index is not None:
163
+ new_column.index = index
164
+ if id is not None:
165
+ new_column.id = id
166
+ if options is not None and column_type in ("PICKLIST", "MULTI_PICKLIST"):
167
+ new_column.options = options
168
+ if symbol is not None and column_type == "CHECKBOX":
169
+ new_column.symbol = symbol
170
+ if primary:
171
+ new_column.primary = True
172
+ if hidden:
173
+ new_column.hidden = True
174
+ if locked:
175
+ new_column.locked = True
176
+ return new_column
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smartsheet_tools
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: A collection of convenience functions to aid with transitioning from simple-smartsheet to the SDK API and common tasks
5
5
  Author: Ashton Pooley
6
6
  Author-email: Ashton Pooley <ashton@ashi.digital>
@@ -0,0 +1,6 @@
1
+ smartsheet_tools/__init__.py,sha256=v93h3pS1UQAW5yWFo-5jVsKIshscWYh9U93ExT99HYY,6402
2
+ smartsheet_tools-0.0.5.dist-info/licenses/LICENSE,sha256=xshMXNQ83e1x1bG3-9fQ5U8hnMaJsv79ke3xuKmI2PI,31914
3
+ smartsheet_tools-0.0.5.dist-info/METADATA,sha256=rJFnnTevc8RA4aLpHdtCIgHp-H5ytTCZFH-_nGWdOE0,834
4
+ smartsheet_tools-0.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ smartsheet_tools-0.0.5.dist-info/top_level.txt,sha256=UXKUTK6mn1resx7hDN-MqSLi6ZnojUbkJ44VzmNmYi8,17
6
+ smartsheet_tools-0.0.5.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- smartsheet_tools/__init__.py,sha256=-0zRzn_7MUDL4sFfNzXRWTJj0MUY7NZ96O_5rSTmJiE,5268
2
- smartsheet_tools-0.0.3.dist-info/licenses/LICENSE,sha256=xshMXNQ83e1x1bG3-9fQ5U8hnMaJsv79ke3xuKmI2PI,31914
3
- smartsheet_tools-0.0.3.dist-info/METADATA,sha256=X_Tkf-hEspLuLBHreCq65BOSeKaBKi258LkNiL8sab8,834
4
- smartsheet_tools-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- smartsheet_tools-0.0.3.dist-info/top_level.txt,sha256=UXKUTK6mn1resx7hDN-MqSLi6ZnojUbkJ44VzmNmYi8,17
6
- smartsheet_tools-0.0.3.dist-info/RECORD,,