Skip to content

Commit

Permalink
Merge pull request #536 from Gustry/translations
Browse files Browse the repository at this point in the history
Translations
  • Loading branch information
Gustry authored Dec 8, 2023
2 parents 6c7682a + e996dfd commit f7549a7
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 436 deletions.
34 changes: 20 additions & 14 deletions lizmap/dialogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, parent=None, is_dev_version=True):
"To know how to fix these checks, either use the tooltip (by hovering your mouse pointer on the table "
"row) in the last column <strong>'{column_name}'</strong>, or check the documentation in the next tab "
"<strong>'{tab_name}'</strong> for all errors which can be reported."
).format(column_name=Headers.Error.label, tab_name=self.tab_log.tabText(1))
).format(column_name=Headers().error.label, tab_name=self.tab_log.tabText(1))
)
auto_fix_panel = self.mOptionsListWidget.item(Panels.AutoFix).text()
self.label_autofix.setText(tr(
Expand Down Expand Up @@ -309,30 +309,32 @@ def __init__(self, parent=None, is_dev_version=True):
self.safe_number_parent.setValue(QgsSettings().value(Settings.key(Settings.NumberParentFolder), type=int))
self.safe_number_parent.valueChanged.connect(self.save_settings)

self.checks = Checks()

# Other drive
self.safe_other_drive.setChecked(QgsSettings().value(Settings.key(Settings.PreventDrive), type=bool))
self.safe_other_drive.toggled.connect(self.save_settings)
self.safe_other_drive.setToolTip(Checks.PreventDrive.description)
self.safe_other_drive.setToolTip(self.checks.PreventDrive.description)

# PG Service
self.safe_pg_service.setChecked(QgsSettings().value(Settings.key(Settings.PreventPgService), type=bool))
self.safe_pg_service.toggled.connect(self.save_settings)
self.safe_pg_service.setToolTip(Checks.PgService.description)
self.safe_pg_service.setToolTip(self.checks.PgService.description)

# PG Auth DB
self.safe_pg_auth_db.setChecked(QgsSettings().value(Settings.key(Settings.PreventPgAuthDb), type=bool))
self.safe_pg_auth_db.toggled.connect(self.save_settings)
self.safe_pg_auth_db.setToolTip(Checks.AuthenticationDb.description)
self.safe_pg_auth_db.setToolTip(self.checks.AuthenticationDb.description)

# User password
self.safe_pg_user_password.setChecked(QgsSettings().value(Settings.key(Settings.ForcePgUserPass), type=bool))
self.safe_pg_user_password.toggled.connect(self.save_settings)
self.safe_pg_user_password.setToolTip(Checks.PgForceUserPass.description)
self.safe_pg_user_password.setToolTip(self.checks.PgForceUserPass.description)

# ECW
self.safe_ecw.setChecked(QgsSettings().value(Settings.key(Settings.PreventEcw), type=bool))
self.safe_ecw.toggled.connect(self.save_settings)
self.safe_ecw.setToolTip(Checks.PreventEcw.description)
self.safe_ecw.setToolTip(self.checks.PreventEcw.description)

msg = tr(
"Some safeguards are overridden by {host}. Even in 'normal' mode, some safeguards are becoming 'blocking' "
Expand Down Expand Up @@ -438,17 +440,21 @@ def visit_settings_panel(self):

def auto_fix_tooltip(self, lizmap_cloud):
""" Set some tooltips on these auto-fix buttons, according to Lizmap Cloud status. """
self.label_pg_ssl.setToolTip(Checks.SSLConnection.html_tooltip(lizmap_cloud))
self.button_convert_ssl.setToolTip(Checks.SSLConnection.html_tooltip(lizmap_cloud))
tooltip = self.checks.SSLConnection.html_tooltip(lizmap_cloud)
self.label_pg_ssl.setToolTip(tooltip)
self.button_convert_ssl.setToolTip(tooltip)

self.label_pg_estimated.setToolTip(Checks.EstimatedMetadata.html_tooltip(lizmap_cloud))
self.button_use_estimated_md.setToolTip(Checks.EstimatedMetadata.html_tooltip(lizmap_cloud))
tooltip = self.checks.EstimatedMetadata.html_tooltip(lizmap_cloud)
self.label_pg_estimated.setToolTip(tooltip)
self.button_use_estimated_md.setToolTip(tooltip)

self.label_trust_project.setToolTip(Checks.TrustProject.html_tooltip(lizmap_cloud))
self.button_trust_project.setToolTip(Checks.TrustProject.html_tooltip(lizmap_cloud))
tooltip = self.checks.TrustProject.html_tooltip(lizmap_cloud)
self.label_trust_project.setToolTip(tooltip)
self.button_trust_project.setToolTip(tooltip)

self.label_simplify.setToolTip(Checks.SimplifyGeometry.html_tooltip(lizmap_cloud))
self.button_simplify_geom.setToolTip(Checks.SimplifyGeometry.html_tooltip(lizmap_cloud))
tooltip = self.checks.SimplifyGeometry.html_tooltip(lizmap_cloud)
self.label_simplify.setToolTip(tooltip)
self.button_simplify_geom.setToolTip(tooltip)

def has_auto_fix(self) -> bool:
""" Return if an auto-fix is enabled. """
Expand Down
49 changes: 27 additions & 22 deletions lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,15 @@ def __init__(self, iface, lwc_version: LwcVersions = None):
temp_dir = Path(tempfile.gettempdir()).joinpath('QGIS_Lizmap')
if not temp_dir.exists():
temp_dir.mkdir()
file_handler = logging.FileHandler(temp_dir.joinpath("lizmap.log"))
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
add_logging_handler_once(LOGGER, file_handler)
LOGGER.debug(
"The directory <a href='file://{0}'>{0}</a> is currently used for file logging.".format(temp_dir))

if not to_bool(os.getenv("CI"), default_value=False):
file_handler = logging.FileHandler(temp_dir.joinpath("lizmap.log"))
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
add_logging_handler_once(LOGGER, file_handler)
LOGGER.debug(
"The directory <a href='file://{0}'>{0}</a> is currently used for file logging.".format(temp_dir))

# All logs
def write_log_message(message, tag, level):
Expand Down Expand Up @@ -2916,7 +2918,7 @@ def project_config_file(
Severities,
SourceLayer,
)

checks = Checks()
valid, _ = self.check_project_validity()

if with_gui:
Expand All @@ -2933,13 +2935,13 @@ def project_config_file(
for name, count in duplicated_in_cfg.items():
if count >= 2:
source = '"{}" → "'.format(name) + tr("count {} layers").format(count)
self.dlg.check_results.add_error(Error(source, Checks.DuplicatedLayerNameOrGroup))
self.dlg.check_results.add_error(Error(source, checks.DuplicatedLayerNameOrGroup))

# Layer ID as short name
if lwc_version >= LwcVersions.Lizmap_3_6:
use_layer_id, _ = self.project.readEntry('WMSUseLayerIDs', '/')
if to_bool(use_layer_id, False):
self.dlg.check_results.add_error(Error(Path(self.project.fileName()).name, Checks.WmsUseLayerIds))
self.dlg.check_results.add_error(Error(Path(self.project.fileName()).name, checks.WmsUseLayerIds))

target_status = self.dlg.server_combo.currentData(ServerComboData.LwcBranchStatus.value)
if not target_status:
Expand Down Expand Up @@ -3017,16 +3019,18 @@ def project_config_file(

self.dlg.log_panel.append("<br>")

severities = Severities()

for layer, error in results.items():

# Severity depends on beginner mode
severity = Severities.Blocking if beginner_mode else Severities.Important
severity = severities.blocking if beginner_mode else severities.important
# But override severities for Lizmap Cloud
# Because even with a 'normal' user, it won't work
override = (
Checks.PreventEcw, Checks.PgForceUserPass, Checks.AuthenticationDb, Checks.PreventDrive)
checks.PreventEcw, checks.PgForceUserPass, checks.AuthenticationDb, checks.PreventDrive)
if error in override:
severity = Severities.Blocking
severity = severities.bocking

self.dlg.check_results.add_error(
Error(
Expand Down Expand Up @@ -3059,7 +3063,7 @@ def project_config_file(
self.dlg.check_results.add_error(
Error(
layer.name,
Checks.SSLConnection,
checks.SSLConnection,
source_type=SourceLayer(layer.name, layer.layer_id),
)
)
Expand All @@ -3070,15 +3074,15 @@ def project_config_file(
self.dlg.check_results.add_error(
Error(
layer.name,
Checks.MissingPk,
checks.MissingPk,
source_type=SourceLayer(layer.name, layer.layer_id),
)
)
for layer in int8:
self.dlg.check_results.add_error(
Error(
layer.name,
Checks.PkInt8,
checks.PkInt8,
source_type=SourceLayer(layer.name, layer.layer_id),
)
)
Expand All @@ -3100,7 +3104,7 @@ def project_config_file(
self.dlg.check_results.add_error(
Error(
layer.name,
Checks.SimplifyGeometry,
checks.SimplifyGeometry,
source_type=SourceLayer(layer.name, layer.layer_id),
)
)
Expand All @@ -3111,14 +3115,14 @@ def project_config_file(
self.dlg.check_results.add_error(
Error(
layer.name,
Checks.EstimatedMetadata,
checks.EstimatedMetadata,
source_type=SourceLayer(layer.name, layer.layer_id),
)
)
self.dlg.enabled_estimated_md_button(True)

if not project_trust_layer_metadata(self.project):
self.dlg.check_results.add_error(Error(Path(self.project.fileName()).name, Checks.TrustProject))
self.dlg.check_results.add_error(Error(Path(self.project.fileName()).name, checks.TrustProject))
self.dlg.enabled_trust_project(True)

# Not blocking, we change it in the background
Expand Down Expand Up @@ -3576,7 +3580,7 @@ def check_project_validity(self):
self.dlg.check_results.add_error(
Error(
Path(self.project.fileName()).name,
Checks.OgcValid,
Checks().OgcValid,
)
)

Expand Down Expand Up @@ -3697,9 +3701,10 @@ def save_cfg_file(
server_metadata = self.dlg.server_combo.currentData(ServerComboData.JsonMetadata.value)
self.dlg.check_results.truncate()
beginner_mode = QgsSettings().value(Settings.key(Settings.BeginnerMode), True, bool)
severities = Severities()
self.dlg.html_help.setHtml(
Checks.html(
severity=Severities.Blocking if beginner_mode else Severities.Important,
Checks().html(
severity=severities.blocking if beginner_mode else severities.important,
lizmap_cloud=is_lizmap_cloud(server_metadata)
)
)
Expand Down
19 changes: 10 additions & 9 deletions lizmap/project_checker_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,33 @@ def project_safeguards_checks(
# Do not use homePath, it's not designed for this if the user has set a custom home path
project_home = Path(project.absolutePath())
results = {}
checks = Checks()

for layer in project.mapLayers().values():

if isinstance(layer, QgsRasterLayer):
if layer.source().lower().endswith('ecw') and prevent_ecw:
results[SourceLayer(layer.name(), layer.id())] = Checks.PreventEcw
results[SourceLayer(layer.name(), layer.id())] = checks.PreventEcw

if is_vector_pg(layer):
# Make a copy by using a string, so we are sure to have user or password
datasource = QgsDataSourceUri(layer.source())
if datasource.authConfigId() != '' and prevent_auth_id:
results[SourceLayer(layer.name(), layer.id())] = Checks.AuthenticationDb
results[SourceLayer(layer.name(), layer.id())] = checks.AuthenticationDb

# We can continue
continue

if datasource.service() != '' and prevent_service:
results[SourceLayer(layer.name(), layer.id())] = Checks.PgService
results[SourceLayer(layer.name(), layer.id())] = checks.PgService

# We can continue
continue

if not datasource.service():
if datasource.host().endswith(CLOUD_DOMAIN) or force_pg_user_pass:
if not datasource.username() or not datasource.password():
results[SourceLayer(layer.name(), layer.id())] = Checks.PgForceUserPass
results[SourceLayer(layer.name(), layer.id())] = checks.PgForceUserPass

# We can continue
continue
Expand All @@ -107,7 +108,7 @@ def project_safeguards_checks(
# For instance, H: and C:

if lizmap_cloud or prevent_other_drive:
results[SourceLayer(layer.name(), layer.id())] = Checks.PreventDrive
results[SourceLayer(layer.name(), layer.id())] = checks.PreventDrive
continue

# Not sure what to do for now...
Expand All @@ -117,11 +118,11 @@ def project_safeguards_checks(
if allow_parent_folder:
# The user allow parent folder, so we check against the string provided in the function call
if parent_folder in relative_path:
results[SourceLayer(layer.name(), layer.id())] = Checks.PreventParentFolder
results[SourceLayer(layer.name(), layer.id())] = checks.PreventParentFolder
else:
# The user wants only local files, we only check for ".."
if '..' in relative_path:
results[SourceLayer(layer.name(), layer.id())] = Checks.PreventParentFolder
results[SourceLayer(layer.name(), layer.id())] = checks.PreventParentFolder

return results

Expand Down Expand Up @@ -348,12 +349,12 @@ def trailing_layer_group_name(layer_tree: QgsLayerTreeNode, project, results: Li
layer = project.mapLayer(child.layerId())
if layer.name().strip() != layer.name():
results.append(
Error(layer.name(), Checks.LeadingTrailingSpaceLayerGroupName, SourceLayer(layer.name(), layer.id())))
Error(layer.name(), Checks().LeadingTrailingSpaceLayerGroupName, SourceLayer(layer.name(), layer.id())))
else:
child = cast_to_group(child)
if child.name().strip() != child.name():
results.append(
Error(child.name(), Checks.LeadingTrailingSpaceLayerGroupName, SourceGroup))
Error(child.name(), Checks().LeadingTrailingSpaceLayerGroupName, SourceGroup))

# Recursive call
results = trailing_layer_group_name(child, project, results)
Expand Down
7 changes: 4 additions & 3 deletions lizmap/test/test_table_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ def test(self):
self.assertEqual(table.verticalHeader().count(), 0)

self.assertEqual(table.rowCount(), 0)
checks = Checks()

table.add_error(Error('my-tailor-is-rich', Checks.DuplicatedLayerNameOrGroup))
table.add_error(Error('home-sweet-home', Checks.DuplicatedLayerNameOrGroup))
table.add_error(Error('home-sweet-home', Checks.MissingPk))
table.add_error(Error('my-tailor-is-rich', checks.DuplicatedLayerNameOrGroup))
table.add_error(Error('home-sweet-home', checks.DuplicatedLayerNameOrGroup))
table.add_error(Error('home-sweet-home', checks.MissingPk))
self.assertEqual(table.rowCount(), 3)

expected = [
Expand Down
Loading

0 comments on commit f7549a7

Please sign in to comment.