Skip to content

Commit

Permalink
Merge pull request #117 from opengisch/modelfilter
Browse files Browse the repository at this point in the history
possiblity to pass model list that is excluded from language search
  • Loading branch information
signedav authored Nov 5, 2024
2 parents ea13cc6 + 168cb78 commit eac8ec9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions modelbaker/dbconnector/db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ def get_translation_handling(self) -> tuple[bool, str]:
"""
return False, ""

def get_available_languages(self) -> list[str]:
def get_available_languages(self, irrelevant_models: list[str]) -> list[str]:
"""
Returns a list of available languages in the t_ili2db_nls table.
Returns a list of available languages in the t_ili2db_nls table and ignores the values for the irrelevant models
"""
return []

Expand Down
11 changes: 8 additions & 3 deletions modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,17 +1235,22 @@ def set_ili2db_sequence_value(self, value):
def get_translation_handling(self) -> tuple[bool, str]:
return self._table_exists(GPKG_NLS_TABLE) and self._lang != "", self._lang

def get_available_languages(self):
def get_available_languages(self, irrelevant_models=[]):
if not self._table_exists(GPKG_NLS_TABLE):
return []

cursor = self.conn.cursor()
cursor.execute(
"""SELECT DISTINCT
lang
FROM "{}";
FROM "{t_ili2db_nls}"
WHERE substr(iliElement, 0, instr(iliElement, '.')) NOT IN ({model_list})
;
""".format(
GPKG_NLS_TABLE
t_ili2db_nls=GPKG_NLS_TABLE,
model_list=",".join(
[f"'{modelname}'" for modelname in irrelevant_models]
),
)
)
records = cursor.fetchall()
Expand Down
11 changes: 9 additions & 2 deletions modelbaker/dbconnector/mssql_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,16 +1246,23 @@ def set_ili2db_sequence_value(self, value):
def get_translation_handling(self) -> tuple[bool, str]:
return self._table_exists(NLS_TABLE) and self._lang != "", self._lang

def get_available_languages(self):
def get_available_languages(self, irrelevant_models=[]):
if self.schema and self._table_exists(NLS_TABLE):
cur = self.conn.cursor()
cur.execute(
"""
SELECT DISTINCT
lang
FROM {schema}.t_ili2db_nls
WHERE
left(iliElement, charindex('.', iliElement)-1) NOT IN ({model_list})
"""
).format(schema=self.schema)
).format(
schema=self.schema,
model_list=",".join(
[f"'{modelname}'" for modelname in irrelevant_models]
),
)

return [row.lang for row in cur.fetchall()]
return []
12 changes: 10 additions & 2 deletions modelbaker/dbconnector/pg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ def get_schemas(self):
def get_translation_handling(self) -> tuple[bool, str]:
return self._table_exists(PG_NLS_TABLE) and self._lang != "", self._lang

def get_available_languages(self):
def get_available_languages(self, irrelevant_models=[]):
if self.schema and self._table_exists(PG_NLS_TABLE):
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute(
Expand All @@ -1380,8 +1380,16 @@ def get_available_languages(self):
SELECT DISTINCT
lang
FROM {schema}.t_ili2db_nls
WHERE
split_part(iliElement,'.',1) NOT IN ({model_list})
"""
).format(schema=sql.Identifier(self.schema))
).format(
schema=sql.Identifier(self.schema),
model_list=sql.SQL(", ").join(
sql.Placeholder() * len(irrelevant_models)
),
),
irrelevant_models,
)
return [row["lang"] for row in cur.fetchall()]
return []

0 comments on commit eac8ec9

Please sign in to comment.