dsw-database 4.20.1__py2.py3-none-any.whl → 4.22.0__py2.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.
@@ -9,9 +9,9 @@ BuildInfo = namedtuple(
9
9
  )
10
10
 
11
11
  BUILD_INFO = BuildInfo(
12
- version='v4.20.1~0e2ea82',
13
- built_at='2025-07-23 08:04:38Z',
14
- sha='0e2ea82aa69b9aae205f7715cf9606bbf75f9f20',
12
+ version='v4.22.0~dffe6c1',
13
+ built_at='2025-09-02 13:01:38Z',
14
+ sha='dffe6c10e47b8795a0d27d495d1c0c0a5d4a76fb',
15
15
  branch='HEAD',
16
- tag='v4.20.1',
16
+ tag='v4.22.0',
17
17
  )
dsw/database/database.py CHANGED
@@ -13,9 +13,10 @@ from dsw.config.model import DatabaseConfig
13
13
 
14
14
  from .model import DBDocumentTemplate, DBDocumentTemplateFile, \
15
15
  DBDocumentTemplateAsset, DBDocument, DBComponent, \
16
- DocumentState, DBTenantConfig, DBTenantLimits, DBSubmission, \
16
+ DocumentState, DBTenantLimits, DBSubmission, \
17
17
  DBInstanceConfigMail, DBQuestionnaireSimple, \
18
- DBUserEntity, DBLocale
18
+ DBUserEntity, DBLocale, DBDocumentTemplateFormat, \
19
+ DBDocumentTemplateStep
19
20
 
20
21
  LOG = logging.getLogger(__name__)
21
22
 
@@ -44,8 +45,6 @@ class Database:
44
45
  'WHERE d.questionnaire_uuid = %s AND d.tenant_uuid = %s;')
45
46
  SELECT_QTN_SIMPLE = ('SELECT qtn.* FROM questionnaire qtn '
46
47
  'WHERE qtn.uuid = %s AND qtn.tenant_uuid = %s;')
47
- SELECT_TENANT_CONFIG = ('SELECT * FROM tenant_config '
48
- 'WHERE uuid = %(tenant_uuid)s LIMIT 1;')
49
48
  SELECT_TENANT_LIMIT = ('SELECT uuid, storage FROM tenant_limit_bundle '
50
49
  'WHERE uuid = %(tenant_uuid)s LIMIT 1;')
51
50
  UPDATE_DOCUMENT_STATE = 'UPDATE document SET state = %s, worker_log = %s WHERE uuid = %s;'
@@ -55,6 +54,10 @@ class Database:
55
54
  'file_size = %s WHERE uuid = %s;')
56
55
  SELECT_TEMPLATE = ('SELECT * FROM document_template '
57
56
  'WHERE id = %s AND tenant_uuid = %s LIMIT 1;')
57
+ SELECT_TEMPLATE_FORMATS = ('SELECT * FROM document_template_format '
58
+ 'WHERE document_template_id = %s AND tenant_uuid = %s;')
59
+ SELECT_TEMPLATE_STEPS = ('SELECT * FROM document_template_format_step '
60
+ 'WHERE document_template_id = %s AND tenant_uuid = %s;')
58
61
  SELECT_TEMPLATE_FILES = ('SELECT * FROM document_template_file '
59
62
  'WHERE document_template_id = %s AND tenant_uuid = %s;')
60
63
  SELECT_TEMPLATE_ASSETS = ('SELECT * FROM document_template_asset '
@@ -152,16 +155,6 @@ class Database:
152
155
  return None
153
156
  return DBDocument.from_dict_row(result[0])
154
157
 
155
- @tenacity.retry(
156
- reraise=True,
157
- wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
158
- stop=tenacity.stop_after_attempt(RETRY_QUERY_TRIES),
159
- before=tenacity.before_log(LOG, logging.DEBUG),
160
- after=tenacity.after_log(LOG, logging.DEBUG),
161
- )
162
- def fetch_tenant_config(self, tenant_uuid: str) -> DBTenantConfig | None:
163
- return self.get_tenant_config(tenant_uuid)
164
-
165
158
  @tenacity.retry(
166
159
  reraise=True,
167
160
  wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
@@ -195,10 +188,47 @@ class Database:
195
188
  query=self.SELECT_TEMPLATE,
196
189
  params=(template_id, tenant_uuid),
197
190
  )
198
- result = cursor.fetchall()
199
- if len(result) != 1:
191
+ dt_result = cursor.fetchall()
192
+ if len(dt_result) != 1:
200
193
  return None
201
- return DBDocumentTemplate.from_dict_row(result[0])
194
+ template = DBDocumentTemplate.from_dict_row(dt_result[0])
195
+
196
+ cursor.execute(
197
+ query=self.SELECT_TEMPLATE_FORMATS,
198
+ params=(template_id, tenant_uuid),
199
+ )
200
+ formats_result = cursor.fetchall()
201
+ formats = sorted([
202
+ DBDocumentTemplateFormat.from_dict_row(x) for x in formats_result
203
+ ], key=lambda x: x.name)
204
+ cursor.execute(
205
+ query=self.SELECT_TEMPLATE_STEPS,
206
+ params=(template_id, tenant_uuid),
207
+ )
208
+ print(f'Format results: {formats_result}')
209
+ print(f'Formats: {formats}')
210
+ steps_result = cursor.fetchall()
211
+ steps = sorted([
212
+ DBDocumentTemplateStep.from_dict_row(x) for x in steps_result
213
+ ], key=lambda x: x.position)
214
+ print(f'Steps results: {formats_result}')
215
+ print(f'Steps: {steps}')
216
+ steps_dict: dict[str, list[dict]] = {}
217
+ for step in steps:
218
+ if step.format_uuid not in steps_dict:
219
+ steps_dict[step.format_uuid] = []
220
+ steps_dict[step.format_uuid].append({
221
+ 'name': step.name,
222
+ 'options': step.options,
223
+ })
224
+ for format_obj in formats:
225
+ template.formats.append({
226
+ 'uuid': format_obj.uuid,
227
+ 'name': format_obj.name,
228
+ 'steps': steps_dict.get(format_obj.uuid, []),
229
+ })
230
+ print(template.formats)
231
+ return template
202
232
 
203
233
  @tenacity.retry(
204
234
  reraise=True,
@@ -375,29 +405,6 @@ class Database:
375
405
  row = cursor.fetchone()
376
406
  return row[0]
377
407
 
378
- @tenacity.retry(
379
- reraise=True,
380
- wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
381
- stop=tenacity.stop_after_attempt(RETRY_QUERY_TRIES),
382
- before=tenacity.before_log(LOG, logging.DEBUG),
383
- after=tenacity.after_log(LOG, logging.DEBUG),
384
- )
385
- def get_tenant_config(self, tenant_uuid: str) -> DBTenantConfig | None:
386
- if not self._check_table_exists(table_name='tenant_config'):
387
- return None
388
- with self.conn_query.new_cursor(use_dict=True) as cursor:
389
- try:
390
- cursor.execute(
391
- query=self.SELECT_TENANT_CONFIG,
392
- params={'tenant_uuid': tenant_uuid},
393
- )
394
- result = cursor.fetchone()
395
- return DBTenantConfig.from_dict_row(data=result)
396
- except Exception as e:
397
- LOG.warning('Could not retrieve tenant_config for tenant "%s": %s',
398
- tenant_uuid, str(e))
399
- return None
400
-
401
408
  @tenacity.retry(
402
409
  reraise=True,
403
410
  wait=tenacity.wait_exponential(multiplier=RETRY_QUERY_MULTIPLIER),
dsw/database/model.py CHANGED
@@ -96,7 +96,7 @@ class DBDocumentTemplate:
96
96
  readme: str
97
97
  license: str
98
98
  allowed_packages: dict
99
- formats: dict
99
+ formats: list
100
100
  phase: str
101
101
  created_at: datetime.datetime
102
102
  updated_at: datetime.datetime
@@ -127,7 +127,7 @@ class DBDocumentTemplate:
127
127
  readme=data['readme'],
128
128
  license=data['license'],
129
129
  allowed_packages=data['allowed_packages'],
130
- formats=data['formats'],
130
+ formats=[],
131
131
  phase=data['phase'],
132
132
  created_at=data['created_at'],
133
133
  updated_at=data['updated_at'],
@@ -135,6 +135,54 @@ class DBDocumentTemplate:
135
135
  )
136
136
 
137
137
 
138
+ @dataclasses.dataclass
139
+ class DBDocumentTemplateFormat:
140
+ document_template_id: str
141
+ uuid: str
142
+ name: str
143
+ icon: str
144
+ created_at: datetime.datetime
145
+ updated_at: datetime.datetime
146
+ tenant_uuid: str
147
+
148
+ @staticmethod
149
+ def from_dict_row(data: dict) -> 'DBDocumentTemplateFormat':
150
+ return DBDocumentTemplateFormat(
151
+ document_template_id=data['document_template_id'],
152
+ uuid=str(data['uuid']),
153
+ name=data['name'],
154
+ icon=data['icon'],
155
+ created_at=data['created_at'],
156
+ updated_at=data['updated_at'],
157
+ tenant_uuid=str(data.get('tenant_uuid', NULL_UUID)),
158
+ )
159
+
160
+
161
+ @dataclasses.dataclass
162
+ class DBDocumentTemplateStep:
163
+ document_template_id: str
164
+ format_uuid: str
165
+ position: int
166
+ name: str
167
+ options: dict[str, str]
168
+ created_at: datetime.datetime
169
+ updated_at: datetime.datetime
170
+ tenant_uuid: str
171
+
172
+ @staticmethod
173
+ def from_dict_row(data: dict) -> 'DBDocumentTemplateStep':
174
+ return DBDocumentTemplateStep(
175
+ document_template_id=data['document_template_id'],
176
+ format_uuid=str(data['format_uuid']),
177
+ position=data['position'],
178
+ name=data['name'],
179
+ options=data['options'],
180
+ created_at=data['created_at'],
181
+ updated_at=data['updated_at'],
182
+ tenant_uuid=str(data.get('tenant_uuid', NULL_UUID)),
183
+ )
184
+
185
+
138
186
  @dataclasses.dataclass
139
187
  class DBDocumentTemplateFile:
140
188
  document_template_id: str
@@ -216,55 +264,6 @@ class PersistentCommand:
216
264
  )
217
265
 
218
266
 
219
- @dataclasses.dataclass
220
- class DBTenantConfig:
221
- uuid: str
222
- organization: dict | None
223
- authentication: dict | None
224
- privacy_and_support: dict | None
225
- dashboard: dict | None
226
- look_and_feel: dict | None
227
- registry: dict | None
228
- knowledge_model: dict | None
229
- questionnaire: dict | None
230
- submission: dict | None
231
- owl: dict | None
232
- mail_config_uuid: str | None
233
- created_at: datetime.datetime
234
- updated_at: datetime.datetime
235
-
236
- @property
237
- def app_title(self) -> str | None:
238
- if self.look_and_feel is None:
239
- return None
240
- return self.look_and_feel.get('appTitle', None)
241
-
242
- @property
243
- def support_email(self) -> str | None:
244
- if self.privacy_and_support is None:
245
- return None
246
- return self.privacy_and_support.get('supportEmail', None)
247
-
248
- @staticmethod
249
- def from_dict_row(data: dict):
250
- return DBTenantConfig(
251
- uuid=str(data['uuid']),
252
- organization=data.get('organization', None),
253
- authentication=data.get('authentication', None),
254
- privacy_and_support=data.get('privacy_and_support', None),
255
- dashboard=data.get('dashboard_and_login_screen', None),
256
- look_and_feel=data.get('look_and_feel', None),
257
- registry=data.get('registry', None),
258
- knowledge_model=data.get('knowledge_model', None),
259
- questionnaire=data.get('questionnaire', None),
260
- submission=data.get('submission', None),
261
- owl=data.get('owl', None),
262
- mail_config_uuid=data.get('mail_config_uuid', None),
263
- created_at=data['created_at'],
264
- updated_at=data['updated_at'],
265
- )
266
-
267
-
268
267
  @dataclasses.dataclass
269
268
  class DBTenantLimits:
270
269
  tenant_uuid: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsw-database
3
- Version: 4.20.1
3
+ Version: 4.22.0
4
4
  Summary: Library for managing DSW database
5
5
  Author-email: Marek Suchánek <marek.suchanek@ds-wizard.org>
6
6
  License: Apache License 2.0
@@ -11,16 +11,16 @@ Keywords: dsw,database
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.11
15
14
  Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Topic :: Database
17
17
  Classifier: Topic :: Utilities
18
- Requires-Python: <4,>=3.11
18
+ Requires-Python: <4,>=3.12
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: psycopg[binary]
22
22
  Requires-Dist: tenacity
23
- Requires-Dist: dsw-config==4.20.1
23
+ Requires-Dist: dsw-config==4.22.0
24
24
  Dynamic: license-file
25
25
 
26
26
  # Data Stewardship Wizard: Database
@@ -0,0 +1,9 @@
1
+ dsw/database/__init__.py,sha256=58ZXZ8i4xzAvvjUdqt8lvdv28hD0yzY_xxI6n9deynw,55
2
+ dsw/database/build_info.py,sha256=LEKGaMjtEl5mbW--jDiDsVBjM3eCcpa-JHkt1-_6hHk,381
3
+ dsw/database/database.py,sha256=2hXcU-txscH6qtKz1CT_JHIChdH4G_PgSNcIA6s4Tv8,27457
4
+ dsw/database/model.py,sha256=ECUNCxbzRuy8dPjEWY1dAkaY1AmdobH6DPGBQPZaaKY,13552
5
+ dsw_database-4.22.0.dist-info/licenses/LICENSE,sha256=rDtJ4LdsXvf_euOpGD0Q86P78K4JyM5m4yfYz9wZ750,11346
6
+ dsw_database-4.22.0.dist-info/METADATA,sha256=EAp6xHhi-1Y6uhPOK82yailN3cYdzZ-cCmWeYsejzmQ,1843
7
+ dsw_database-4.22.0.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
8
+ dsw_database-4.22.0.dist-info/top_level.txt,sha256=7SfbsHFoJ_vlAgG6C-xzETETwYO71dBrGnod8uMFnjw,4
9
+ dsw_database-4.22.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- dsw/database/__init__.py,sha256=58ZXZ8i4xzAvvjUdqt8lvdv28hD0yzY_xxI6n9deynw,55
2
- dsw/database/build_info.py,sha256=ZPEl_TE1xRrecv0DidwcjMbWKR5jnVrzoo-ZMOoF_Z0,381
3
- dsw/database/database.py,sha256=fsj9RoEQcISU7XZQ7YNlMJKVIaHqjjFejeDO0tzAKIA,27116
4
- dsw/database/model.py,sha256=4Co0j4gLWI6r1wuOxylApOfZfCE9ZGXawA7A8JKUsHk,13828
5
- dsw_database-4.20.1.dist-info/licenses/LICENSE,sha256=rDtJ4LdsXvf_euOpGD0Q86P78K4JyM5m4yfYz9wZ750,11346
6
- dsw_database-4.20.1.dist-info/METADATA,sha256=WUo3vLfJmOGsdn9KEmbm5SZNii1isyHsg9Pg5ChQScg,1843
7
- dsw_database-4.20.1.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
8
- dsw_database-4.20.1.dist-info/top_level.txt,sha256=7SfbsHFoJ_vlAgG6C-xzETETwYO71dBrGnod8uMFnjw,4
9
- dsw_database-4.20.1.dist-info/RECORD,,