dsw-database 4.21.0__tar.gz → 4.22.1__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsw-database
3
- Version: 4.21.0
3
+ Version: 4.22.1
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
@@ -20,7 +20,7 @@ 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.21.0
23
+ Requires-Dist: dsw-config==4.22.1
24
24
  Dynamic: license-file
25
25
 
26
26
  # Data Stewardship Wizard: Database
@@ -9,9 +9,9 @@ BuildInfo = namedtuple(
9
9
  )
10
10
 
11
11
  BUILD_INFO = BuildInfo(
12
- version='v4.21.0~12713f1',
13
- built_at='2025-08-05 09:21:07Z',
14
- sha='12713f1988c2a33d5c40dd2cb899cdac7be35668',
12
+ version='v4.22.1~13699ca',
13
+ built_at='2025-09-04 06:55:38Z',
14
+ sha='13699ca0f74ff51a24bd76e242a89ef434b74658',
15
15
  branch='HEAD',
16
- tag='v4.21.0',
16
+ tag='v4.22.1',
17
17
  )
@@ -15,7 +15,8 @@ from .model import DBDocumentTemplate, DBDocumentTemplateFile, \
15
15
  DBDocumentTemplateAsset, DBDocument, DBComponent, \
16
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
 
@@ -53,6 +54,10 @@ class Database:
53
54
  'file_size = %s WHERE uuid = %s;')
54
55
  SELECT_TEMPLATE = ('SELECT * FROM document_template '
55
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;')
56
61
  SELECT_TEMPLATE_FILES = ('SELECT * FROM document_template_file '
57
62
  'WHERE document_template_id = %s AND tenant_uuid = %s;')
58
63
  SELECT_TEMPLATE_ASSETS = ('SELECT * FROM document_template_asset '
@@ -183,10 +188,47 @@ class Database:
183
188
  query=self.SELECT_TEMPLATE,
184
189
  params=(template_id, tenant_uuid),
185
190
  )
186
- result = cursor.fetchall()
187
- if len(result) != 1:
191
+ dt_result = cursor.fetchall()
192
+ if len(dt_result) != 1:
188
193
  return None
189
- 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
190
232
 
191
233
  @tenacity.retry(
192
234
  reraise=True,
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsw-database
3
- Version: 4.21.0
3
+ Version: 4.22.1
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
@@ -20,7 +20,7 @@ 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.21.0
23
+ Requires-Dist: dsw-config==4.22.1
24
24
  Dynamic: license-file
25
25
 
26
26
  # Data Stewardship Wizard: Database
@@ -1,3 +1,3 @@
1
1
  psycopg[binary]
2
2
  tenacity
3
- dsw-config==4.21.0
3
+ dsw-config==4.22.1
@@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'
4
4
 
5
5
  [project]
6
6
  name = 'dsw-database'
7
- version = "4.21.0"
7
+ version = "4.22.1"
8
8
  description = 'Library for managing DSW database'
9
9
  readme = 'README.md'
10
10
  keywords = ['dsw', 'database']
@@ -26,7 +26,7 @@ dependencies = [
26
26
  'psycopg[binary]',
27
27
  'tenacity',
28
28
  # DSW
29
- "dsw-config==4.21.0",
29
+ "dsw-config==4.22.1",
30
30
  ]
31
31
 
32
32
  [project.urls]
File without changes
File without changes
File without changes
File without changes