Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .cspell/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,21 @@ Marek
Suchánek
Kazuki
Yamamoto

# Things appearing in VCR cassettes
stylesheet
flexbox
Vtnp
Hgotu
komanec
krystof
krystofkomanec
DNkov
martinkova
jmartinkova
odend
heighta
xurl
nosniff


26 changes: 13 additions & 13 deletions packages/dsw-database/dsw/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class Database:
'file_name = %s, content_type = %s, worker_log = %s, '
'file_size = %s WHERE uuid = %s;')
SELECT_TEMPLATE = ('SELECT * FROM document_template '
'WHERE id = %s AND tenant_uuid = %s LIMIT 1;')
'WHERE uuid = %s AND tenant_uuid = %s LIMIT 1;')
SELECT_TEMPLATE_FORMATS = ('SELECT * FROM document_template_format '
'WHERE document_template_id = %s AND tenant_uuid = %s;')
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
SELECT_TEMPLATE_STEPS = ('SELECT * FROM document_template_format_step '
'WHERE document_template_id = %s AND tenant_uuid = %s;')
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
SELECT_TEMPLATE_FILES = ('SELECT * FROM document_template_file '
'WHERE document_template_id = %s AND tenant_uuid = %s;')
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
SELECT_TEMPLATE_ASSETS = ('SELECT * FROM document_template_asset '
'WHERE document_template_id = %s AND tenant_uuid = %s;')
'WHERE document_template_uuid = %s AND tenant_uuid = %s;')
CHECK_TABLE_EXISTS = ('SELECT EXISTS(SELECT * FROM information_schema.tables'
' WHERE table_name = %(table_name)s)')
SELECT_MAIL_CONFIG = ('SELECT * FROM instance_config_mail '
Expand Down Expand Up @@ -177,12 +177,12 @@ def fetch_tenant_limits(self, tenant_uuid: str) -> model.DBTenantLimits | None:
after=tenacity.after_log(LOG, logging.DEBUG),
)
def fetch_template(
self, template_id: str, tenant_uuid: str,
self, template_uuid: str, tenant_uuid: str,
) -> model.DBDocumentTemplate | None:
with self.conn_query.new_cursor(use_dict=True) as cursor:
cursor.execute(
query=self.SELECT_TEMPLATE,
params=(template_id, tenant_uuid),
params=(template_uuid, tenant_uuid),
)
dt_result = cursor.fetchall()
if len(dt_result) != 1:
Expand All @@ -191,15 +191,15 @@ def fetch_template(

cursor.execute(
query=self.SELECT_TEMPLATE_FORMATS,
params=(template_id, tenant_uuid),
params=(template_uuid, tenant_uuid),
)
formats_result = cursor.fetchall()
formats = sorted([
model.DBDocumentTemplateFormat.from_dict_row(x) for x in formats_result
], key=lambda x: x.name)
cursor.execute(
query=self.SELECT_TEMPLATE_STEPS,
params=(template_id, tenant_uuid),
params=(template_uuid, tenant_uuid),
)
steps_result = cursor.fetchall()
steps = sorted([
Expand Down Expand Up @@ -229,12 +229,12 @@ def fetch_template(
after=tenacity.after_log(LOG, logging.DEBUG),
)
def fetch_template_files(
self, template_id: str, tenant_uuid: str,
self, template_uuid: str, tenant_uuid: str,
) -> list[model.DBDocumentTemplateFile]:
with self.conn_query.new_cursor(use_dict=True) as cursor:
cursor.execute(
query=self.SELECT_TEMPLATE_FILES,
params=(template_id, tenant_uuid),
params=(template_uuid, tenant_uuid),
)
return [model.DBDocumentTemplateFile.from_dict_row(x) for x in cursor.fetchall()]

Expand All @@ -246,12 +246,12 @@ def fetch_template_files(
after=tenacity.after_log(LOG, logging.DEBUG),
)
def fetch_template_assets(
self, template_id: str, tenant_uuid: str,
self, template_uuid: str, tenant_uuid: str,
) -> list[model.DBDocumentTemplateAsset]:
with self.conn_query.new_cursor(use_dict=True) as cursor:
cursor.execute(
query=self.SELECT_TEMPLATE_ASSETS,
params=(template_id, tenant_uuid),
params=(template_uuid, tenant_uuid),
)
return [model.DBDocumentTemplateAsset.from_dict_row(x) for x in cursor.fetchall()]

Expand Down
40 changes: 22 additions & 18 deletions packages/dsw-database/dsw/database/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DBDocument:
project_uuid: str | None
project_event_uuid: str | None
project_replies_hash: str
document_template_id: str
document_template_uuid: str
format_uuid: str
file_name: str
content_type: str
Expand All @@ -72,7 +72,7 @@ def from_dict_row(data: dict):
project_uuid=str(project_uuid) if project_uuid else None,
project_event_uuid=str(event_uuid) if event_uuid else None,
project_replies_hash=data['project_replies_hash'],
document_template_id=data['document_template_id'],
document_template_uuid=data['document_template_uuid'],
format_uuid=str(data['format_uuid']),
created_by=str(data['created_by']),
retrieved_at=data['retrieved_at'],
Expand All @@ -88,7 +88,7 @@ def from_dict_row(data: dict):

@dataclasses.dataclass
class DBDocumentTemplate:
id: str
uuid: str
name: str
organization_id: str
template_id: str
Expand Down Expand Up @@ -116,10 +116,14 @@ def is_released(self):
def is_deprecated(self):
return self.phase == DocumentTemplatePhase.DEPRECATED

@property
def coordinates(self) -> str:
return f'{self.organization_id}:{self.template_id}:{self.version}'

@staticmethod
def from_dict_row(data: dict) -> 'DBDocumentTemplate':
return DBDocumentTemplate(
id=data['id'],
uuid=data['uuid'],
name=data['name'],
organization_id=data['organization_id'],
template_id=data['template_id'],
Expand All @@ -139,7 +143,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplate':

@dataclasses.dataclass
class DBDocumentTemplateFormat:
document_template_id: str
document_template_uuid: str
uuid: str
name: str
icon: str
Expand All @@ -150,7 +154,7 @@ class DBDocumentTemplateFormat:
@staticmethod
def from_dict_row(data: dict) -> 'DBDocumentTemplateFormat':
return DBDocumentTemplateFormat(
document_template_id=data['document_template_id'],
document_template_uuid=data['document_template_uuid'],
uuid=str(data['uuid']),
name=data['name'],
icon=data['icon'],
Expand All @@ -162,7 +166,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplateFormat':

@dataclasses.dataclass
class DBDocumentTemplateStep:
document_template_id: str
document_template_uuid: str
format_uuid: str
position: int
name: str
Expand All @@ -174,7 +178,7 @@ class DBDocumentTemplateStep:
@staticmethod
def from_dict_row(data: dict) -> 'DBDocumentTemplateStep':
return DBDocumentTemplateStep(
document_template_id=data['document_template_id'],
document_template_uuid=data['document_template_uuid'],
format_uuid=str(data['format_uuid']),
position=data['position'],
name=data['name'],
Expand All @@ -187,7 +191,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplateStep':

@dataclasses.dataclass
class DBDocumentTemplateFile:
document_template_id: str
document_template_uuid: str
uuid: str
file_name: str
content: str
Expand All @@ -198,7 +202,7 @@ class DBDocumentTemplateFile:
@staticmethod
def from_dict_row(data: dict) -> 'DBDocumentTemplateFile':
return DBDocumentTemplateFile(
document_template_id=data['document_template_id'],
document_template_uuid=data['document_template_uuid'],
uuid=str(data['uuid']),
file_name=data['file_name'],
content=data['content'],
Expand All @@ -210,7 +214,7 @@ def from_dict_row(data: dict) -> 'DBDocumentTemplateFile':

@dataclasses.dataclass
class DBDocumentTemplateAsset:
document_template_id: str
document_template_uuid: str
uuid: str
file_name: str
content_type: str
Expand All @@ -222,7 +226,7 @@ class DBDocumentTemplateAsset:
@staticmethod
def from_dict_row(data: dict) -> 'DBDocumentTemplateAsset':
return DBDocumentTemplateAsset(
document_template_id=data['document_template_id'],
document_template_uuid=data['document_template_uuid'],
uuid=str(data['uuid']),
file_name=data['file_name'],
content_type=data['content_type'],
Expand Down Expand Up @@ -334,8 +338,8 @@ class DBProjectSimple:
name: str
visibility: str
sharing: str
package_id: str
document_template_id: str
knowledge_package_uuid: str
document_template_uuid: str
format_uuid: str
created_by: str
created_at: datetime.datetime
Expand All @@ -352,8 +356,8 @@ def from_dict_row(data: dict):
name=data['name'],
visibility=data['visibility'],
sharing=data['sharing'],
package_id=data['package_id'],
document_template_id=data['document_template_id'],
knowledge_package_uuid=data['knowledge_package_uuid'],
document_template_uuid=data['document_template_uuid'],
format_uuid=str(data['format_uuid']),
created_by=str(data['created_by']),
created_at=data['created_at'],
Expand All @@ -370,8 +374,8 @@ def to_dict(self) -> dict:
'name': self.name,
'visibility': self.visibility,
'sharing': self.sharing,
'package_id': self.package_id,
'document_template_id': self.document_template_id,
'knowledge_package_uuid': self.knowledge_package_uuid,
'document_template_uuid': self.document_template_uuid,
'format_uuid': self.format_uuid,
'created_by': self.created_by,
'created_at': self.created_at.isoformat(timespec='milliseconds'),
Expand Down
4 changes: 2 additions & 2 deletions packages/dsw-document-worker/dsw/document_worker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ def load(data: dict):
class TemplatesConfig:
templates: list[TemplateConfig]

def get_config(self, template_id: str) -> TemplateConfig | None:
def get_config(self, template_coordinates: str) -> TemplateConfig | None:
for template in self.templates:
if any(template_id.startswith(prefix) for prefix in template.ids):
if any(template_coordinates.startswith(prefix) for prefix in template.ids):
return template
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ def __init__(self, *, uuid: str, name: str, document_template_id: str, format_uu
created_by: User | None, created_at: datetime.datetime):
self.uuid = uuid
self.name = name
self.document_template_id = document_template_id
self.document_template_uuid = document_template_id
self.format_uuid = format_uuid
self.created_by = created_by
self.created_at = created_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _add_j2_enhancements(self):
self.j2_env.filters.update(filters)
self.j2_env.tests.update(tests)
template_cfg = Context.get().app.cfg.templates.get_config(
self.template.template_id,
self.template.coordinates,
)
self.j2_env.globals.update({'rdflib': rdflib, 'json': json})
if template_cfg is not None:
Expand Down
Loading
Loading