otlmow-template 0.11rc1__py3-none-any.whl → 0.11rc2__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.
@@ -52,10 +52,12 @@ class SubsetTemplateCreator:
52
52
  os.makedirs(tempdir)
53
53
  test = ntpath.basename(path_to_template_file_and_extension)
54
54
  temporary_path = Path(tempdir) / test
55
+ await sleep(0)
55
56
  instantiated_attributes = (await self.generate_basic_template(
56
57
  path_to_subset=path_to_subset, temporary_path=temporary_path, ignore_relations=ignore_relations,
57
58
  path_to_template_file_and_extension=path_to_template_file_and_extension,
58
59
  filter_attributes_by_subset=filter_attributes_by_subset, **kwargs))
60
+ await sleep(0)
59
61
  extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
60
62
  if extension == '.xlsx':
61
63
  await self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
@@ -117,14 +119,15 @@ class SubsetTemplateCreator:
117
119
  extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
118
120
  instantiated_attributes = []
119
121
  if path_is_split is False or extension == '.xlsx':
120
- instantiated_attributes = converter.from_file_to_objects(file_path=temporary_path,
122
+ instantiated_attributes = await converter.from_file_to_objects(file_path=temporary_path,
121
123
  path_to_subset=path_to_subset)
122
- return instantiated_attributes
124
+ return list(instantiated_attributes)
123
125
 
124
126
  @classmethod
125
127
  @async_to_sync_wraps
126
128
  async def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
127
129
  instantiated_attributes: list, temporary_path, **kwargs):
130
+ await sleep(0)
128
131
  generate_choice_list = kwargs.get('generate_choice_list', False)
129
132
  add_geo_artefact = kwargs.get('add_geo_artefact', False)
130
133
  add_attribute_info = kwargs.get('add_attribute_info', False)
@@ -138,16 +141,24 @@ class SubsetTemplateCreator:
138
141
  # Volgorde is belangrijk! Eerst rijen verwijderen indien nodig dan choice list toevoegen,
139
142
  # staat namelijk vast op de kolom en niet het attribuut in die kolom
140
143
  if add_geo_artefact is False:
144
+ await sleep(0)
141
145
  cls.remove_geo_artefact_excel(workbook=wb)
142
146
  if generate_choice_list:
143
- cls.add_choice_list_excel(workbook=wb, instantiated_attributes=instantiated_attributes,
147
+ await sleep(0)
148
+ await cls.add_choice_list_excel(workbook=wb, instantiated_attributes=instantiated_attributes,
144
149
  path_to_subset=path_to_subset)
150
+ await sleep(0)
145
151
  cls.add_mock_data_excel(workbook=wb, rows_of_examples=amount_of_examples)
152
+ await cls.add_type_uri_choice_list_in_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
146
153
  if highlight_deprecated_attributes:
154
+ await sleep(0)
147
155
  cls.check_for_deprecated_attributes(workbook=wb, instantiated_attributes=instantiated_attributes)
148
156
  if add_attribute_info:
149
- cls.add_attribute_info_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
150
- cls.design_workbook_excel(workbook=wb)
157
+ await sleep(0)
158
+ await cls.add_attribute_info_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
159
+ await sleep(0)
160
+ await cls.design_workbook_excel(workbook=wb)
161
+ await sleep(0)
151
162
  wb.save(path_to_template_file_and_extension)
152
163
  file_location = os.path.dirname(temporary_path)
153
164
  [f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
@@ -184,24 +195,71 @@ class SubsetTemplateCreator:
184
195
  return converter_path / 'settings_otlmow_converter.json'
185
196
 
186
197
  @classmethod
187
- def design_workbook_excel(cls, workbook):
198
+ @async_to_sync_wraps
199
+ async def add_type_uri_choice_list_in_excel(cls, workbook, instantiated_attributes):
200
+ for sheet in workbook:
201
+ await sleep(0)
202
+ if sheet.title == 'Keuzelijsten':
203
+ break
204
+ type_uri_found = False
205
+ for row in sheet.iter_rows(min_row=1, max_row=1):
206
+ for cell in row:
207
+ if cell.value == 'typeURI':
208
+ type_uri_found = True
209
+ break
210
+ if type_uri_found:
211
+ break
212
+ if not type_uri_found:
213
+ continue
214
+
215
+ await sleep(0)
216
+ sheet_name = sheet.title
217
+ type_uri = ''
218
+ if sheet_name.startswith('http'):
219
+ type_uri = sheet_name
220
+ else:
221
+ split_name = sheet_name.split("#")
222
+ subclass_name = split_name[1]
223
+
224
+ possible_classes = [x for x in instantiated_attributes if x.typeURI.endswith(subclass_name)]
225
+ if len(possible_classes) == 1:
226
+ type_uri = possible_classes[0].typeURI
227
+
228
+ if type_uri == '':
229
+ continue
230
+
231
+ data_validation = DataValidation(type="list", formula1=f'"{type_uri}"', allow_blank=True)
232
+ await sleep(0)
233
+ for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=1):
234
+ for cell in rows:
235
+ column = cell.column
236
+ sheet.add_data_validation(data_validation)
237
+ data_validation.add(f'{get_column_letter(column)}2:{get_column_letter(column)}1000')
238
+
239
+ @classmethod
240
+ @async_to_sync_wraps
241
+ async def design_workbook_excel(cls, workbook):
188
242
  for sheet in workbook:
189
243
  dim_holder = DimensionHolder(worksheet=sheet)
190
244
  for col in range(sheet.min_column, sheet.max_column + 1):
245
+ await sleep(0)
191
246
  dim_holder[get_column_letter(col)] = ColumnDimension(sheet, min=col, max=col, width=25)
192
247
  sheet.column_dimensions = dim_holder
193
248
 
194
249
  @classmethod
195
- def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
250
+ @async_to_sync_wraps
251
+ async def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
196
252
  dotnotation_module = DotnotationHelper()
197
253
  for sheet in workbook:
198
254
  if sheet == workbook['Keuzelijsten']:
199
255
  break
200
256
  filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
257
+ await sleep(0)
201
258
  single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
202
259
  sheet.insert_rows(1)
203
260
  for rows in sheet.iter_rows(min_row=2, max_row=2, min_col=1):
204
261
  for cell in rows:
262
+ await sleep(0)
205
263
  if cell.value == 'typeURI':
206
264
  value = 'De URI van het object volgens https://www.w3.org/2001/XMLSchema#anyURI .'
207
265
  elif cell.value.find('[DEPRECATED]') != -1:
@@ -264,16 +322,19 @@ class SubsetTemplateCreator:
264
322
  sheet.delete_cols(cell.column)
265
323
 
266
324
  @classmethod
267
- def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path):
325
+ @async_to_sync_wraps
326
+ async def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path):
268
327
  choice_list_dict = {}
269
328
  dotnotation_module = DotnotationHelper()
270
329
  for sheet in workbook:
330
+ await sleep(0)
271
331
  if sheet == workbook['Keuzelijsten']:
272
332
  break
273
333
  filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
274
334
  single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
275
335
  for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=2):
276
336
  for cell in rows:
337
+ await sleep(0)
277
338
  if cell.value.find('[DEPRECATED]') != -1:
278
339
  strip = cell.value.split(' ')
279
340
  dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
@@ -281,7 +342,7 @@ class SubsetTemplateCreator:
281
342
  else:
282
343
  dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
283
344
  cell.value)
284
-
345
+ await sleep(0)
285
346
  if issubclass(dotnotation_attribute.field, KeuzelijstField):
286
347
  name = dotnotation_attribute.field.naam
287
348
  valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items()
@@ -296,12 +357,14 @@ class SubsetTemplateCreator:
296
357
  allowBlank=True)
297
358
  sheet.add_data_validation(data_val)
298
359
  data_val.add(f'{get_column_letter(cell.column)}2:{get_column_letter(cell.column)}1000')
360
+
361
+ await sleep(0)
299
362
  if issubclass(dotnotation_attribute.field, BooleanField):
300
- data_validation = DataValidation(type="list", formula1='"TRUE,FALSE,-"', allow_blank=True)
363
+ data_validation = DataValidation(type="list", formula1='"TRUE,FALSE,"', allow_blank=True)
301
364
  column = cell.column
302
365
  sheet.add_data_validation(data_validation)
303
366
  data_validation.add(f'{get_column_letter(column)}2:{get_column_letter(column)}1000')
304
- sheet.add_data_validation(data_validation)
367
+
305
368
 
306
369
  @classmethod
307
370
  def add_mock_data_excel(cls, workbook, rows_of_examples: int):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: otlmow_template
3
- Version: 0.11rc1
3
+ Version: 0.11rc2
4
4
  Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
@@ -1,10 +1,10 @@
1
1
  otlmow_template/CsvTemplateCreator.py,sha256=PQq2zGmliWk0N9bhYNB7ZEa8PWV16OTbvoHh3--qCMs,7538
2
2
  otlmow_template/ExcelTemplateCreator.py,sha256=wW-7Uq2Gzr1vHYMO1I7TtqZSBTVFFSWotHvjwzCelV4,10853
3
- otlmow_template/SubsetTemplateCreator.py,sha256=DpTwiRJihigmCpZSmT1Iz3-2Gep0EBpyygXjVwxPfnY,25524
3
+ otlmow_template/SubsetTemplateCreator.py,sha256=bm_09LyZc4IY1jxx2ptJZ0553W8QeUYuqHF34rvN0Yc,27819
4
4
  otlmow_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
6
- otlmow_template-0.11rc1.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
7
- otlmow_template-0.11rc1.dist-info/METADATA,sha256=lfKPmGuFW-3zyPkYuOtkakBPAaCMRNOjKNj6-neRkTY,44040
8
- otlmow_template-0.11rc1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
- otlmow_template-0.11rc1.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
10
- otlmow_template-0.11rc1.dist-info/RECORD,,
6
+ otlmow_template-0.11rc2.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
7
+ otlmow_template-0.11rc2.dist-info/METADATA,sha256=nBwN3iqwVAHEq7K2V9jQATSzADad0WkKAzXLfAInj9c,44040
8
+ otlmow_template-0.11rc2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
+ otlmow_template-0.11rc2.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
10
+ otlmow_template-0.11rc2.dist-info/RECORD,,