Skip to content

Commit

Permalink
Rewrite all project rules checker, add a new table in settings for re…
Browse files Browse the repository at this point in the history
…sults and rules
  • Loading branch information
Gustry committed Nov 6, 2023
1 parent f66f83b commit 39c4ac4
Show file tree
Hide file tree
Showing 16 changed files with 1,065 additions and 716 deletions.
10 changes: 10 additions & 0 deletions lizmap/definitions/lizmap_cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__copyright__ = 'Copyright 2023, 3Liz'
__license__ = 'GPL version 3'
__email__ = '[email protected]'

CLOUD_DOMAIN = 'lizmap.com'
CLOUD_NAME = 'Lizmap Cloud'
CLOUD_MAX_PARENT_FOLDER = 2 # TODO Check COG, is-it 3 ?

CLOUD_ONLINE_URL = 'https://docs.lizmap.cloud'
CLOUD_ONLINE_LANGUAGES = ('en', 'fr')
12 changes: 7 additions & 5 deletions lizmap/definitions/online_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from qgis.core import QgsSettings
from qgis.PyQt.QtCore import QLocale, QUrl

from lizmap.definitions.lizmap_cloud import (
CLOUD_ONLINE_LANGUAGES,
CLOUD_ONLINE_URL,
)

DOMAIN = 'https://docs.lizmap.com'
VERSION = 'current'
ONLINE_HELP_LANGUAGES = ('en', 'es', 'it', 'ja', 'pt', 'fi', 'fr')

CLOUD = 'https://docs.lizmap.cloud'
CLOUD_HELP_LANGUAGES = ('en', 'fr')


def current_locale() -> str:
""" Get the main language, with 2 characters only. """
Expand All @@ -25,9 +27,9 @@ def current_locale() -> str:
def online_cloud_help(page: str = '') -> QUrl:
""" Online help URL according to locale and version. """
locale = current_locale()
if locale not in CLOUD_HELP_LANGUAGES:
if locale not in CLOUD_ONLINE_LANGUAGES:
locale = 'en'
return QUrl(f"{CLOUD}/{locale}/{page}")
return QUrl(f"{CLOUD_ONLINE_URL}/{locale}/{page}")


def online_lwc_help(page: str = '', version=VERSION) -> QUrl:
Expand Down
4 changes: 2 additions & 2 deletions lizmap/definitions/qgis_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def key(cls, key):
return KEY + '/' + key

PreventEcw = 'prevent_ecw'
PreventPgAuthId = 'prevent_pg_auth_id'
PreventPgAuthDb = 'prevent_pg_auth_db'
PreventPgService = 'prevent_pg_service'
ForcePgUserPass = 'force_pg_user_password'
PreventNetworkDrive = 'prevent_network_drive'
PreventDrive = 'prevent_drive'
AllowParentFolder = 'allow_parent_folder'
NumberParentFolder = 'number_parent_folder'
BeginnerMode = 'beginner_mode'
15 changes: 0 additions & 15 deletions lizmap/definitions/warnings.py

This file was deleted.

65 changes: 32 additions & 33 deletions lizmap/dialogs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@
)
from qgis.utils import OverrideCursor, iface

from lizmap.definitions.lizmap_cloud import CLOUD_MAX_PARENT_FOLDER, CLOUD_NAME
from lizmap.definitions.qgis_settings import Settings
from lizmap.log_panel import LogPanel
from lizmap.models.check_project import TableCheck
from lizmap.project_checker_tools import (
ALLOW_PARENT_FOLDER,
FORCE_LOCAL_FOLDER,
FORCE_PG_USER_PASS,
PREVENT_AUTH_DB,
PREVENT_ECW,
PREVENT_NETWORK_DRIVE,
PREVENT_OTHER_DRIVE,
PREVENT_SERVICE,
project_trust_layer_metadata,
simplify_provider_side,
use_estimated_metadata,
)
from lizmap.saas import SAAS_MAX_PARENT_FOLDER, SAAS_NAME, fix_ssl
from lizmap.saas import fix_ssl
from lizmap.widgets.check_project import Checks, TableCheck

try:
from qgis.PyQt.QtWebKitWidgets import QWebView
Expand Down Expand Up @@ -177,7 +178,7 @@ def __init__(self, parent=None, is_dev_version=True):
self.button_use_estimated_md.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))

self.button_trust_project.clicked.connect(self.fix_project_trust)
# self.button_trust_project.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))
self.button_trust_project.setIcon(QIcon(':/images/themes/default/mIconQgsProjectFile.svg'))

self.button_simplify_geom.clicked.connect(self.fix_simplify_geom_provider)
self.button_simplify_geom.setIcon(QIcon(":images/themes/default/mIconPostgis.svg"))
Expand Down Expand Up @@ -231,13 +232,13 @@ def __init__(self, parent=None, is_dev_version=True):
)
self.label_file_action.setOpenExternalLinks(True)

self.radio_beginner.setToolTip(
self.radio_beginner.setToolTip(tr(
'If one safeguard is not OK, the Lizmap configuration file is not going to be generated.'
)
self.radio_normal.setToolTip(
))
self.radio_normal.setToolTip(tr(
'If one safeguard is not OK, only a warning will be displayed, not blocking the saving of the Lizmap '
'configuration file.'
)
))

self.radio_force_local_folder.setText(FORCE_LOCAL_FOLDER)
self.radio_force_local_folder.setToolTip(tr(
Expand All @@ -247,7 +248,8 @@ def __init__(self, parent=None, is_dev_version=True):
self.radio_allow_parent_folder.setToolTip(tr(
'Files can be located in a parent folder from {}, up to the setting below.'
).format(self.project.absolutePath()))
self.safe_network_drive.setText(PREVENT_NETWORK_DRIVE)

self.safe_other_drive.setText(PREVENT_OTHER_DRIVE)
self.safe_pg_service.setText(PREVENT_SERVICE)
self.safe_pg_auth_db.setText(PREVENT_AUTH_DB)
self.safe_pg_user_password.setText(FORCE_PG_USER_PASS)
Expand Down Expand Up @@ -275,27 +277,34 @@ 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)

# Network drive
self.safe_network_drive.setChecked(QgsSettings().value(Settings.key(Settings.PreventNetworkDrive), type=bool))
self.safe_network_drive.toggled.connect(self.save_settings)
# 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)

# 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)

# PG Auth DB
self.safe_pg_auth_db.setChecked(QgsSettings().value(Settings.key(Settings.PreventPgAuthId), type=bool))
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)

# 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)

# 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.label_safe_lizmap_cloud.setText(tr("Some safe guards are overridden by {}.").format(SAAS_NAME))
self.label_safe_lizmap_cloud.setText(tr(
"Some safeguards are overridden by {host}. Even in 'normal' mode, some safeguards are becoming 'blocking' "
"with a {host} instance.").format(host=CLOUD_NAME))
msg = (
'<ul>'
'<li>{max_parent}</li>'
Expand All @@ -305,8 +314,8 @@ def __init__(self, parent=None, is_dev_version=True):
'<li>{ecw}</li>'
'</ul>'.format(
max_parent=tr("Maximum of parent folder {} : {}").format(
SAAS_MAX_PARENT_FOLDER, relative_path(SAAS_MAX_PARENT_FOLDER)),
network=PREVENT_NETWORK_DRIVE,
CLOUD_MAX_PARENT_FOLDER, relative_path(CLOUD_MAX_PARENT_FOLDER)),
network=PREVENT_OTHER_DRIVE,
auth_db=PREVENT_AUTH_DB,
user_pass=FORCE_PG_USER_PASS,
ecw=PREVENT_ECW,
Expand All @@ -315,21 +324,11 @@ def __init__(self, parent=None, is_dev_version=True):
self.label_safe_lizmap_cloud.setToolTip(msg)

self.table_checks.setup()
css_path = resources_path('css', 'log.css')
with open(css_path, encoding='utf8') as f:
css = f.read()
self.html_help.document().setDefaultStyleSheet(css)

# self.table_checks.setSelectionMode(QAbstractItemView.SingleSelection)
# self.table_checks.setEditTriggers(QAbstractItemView.NoEditTriggers)
# self.table_checks.setSelectionBehavior(QAbstractItemView.SelectRows)
# self.table_checks.setAlternatingRowColors(True)
# self.table_checks.horizontalHeader().setStretchLastSection(True)
# self.table_checks.horizontalHeader().setVisible(True)
# print("BOB")
#
# self.table_checks.setColumnCount(len(Headers))
# for i, header in enumerate(Headers):
# column = QTableWidgetItem(header.label)
# column.setToolTip(header.tooltip)
# self.table_checks.setHorizontalHeaderItem(i, column)
# print(i)
@property
def check_results(self) -> TableCheck:
return self.table_checks
Expand Down Expand Up @@ -908,7 +907,7 @@ def radio_mode_normal_toggled(self):
widgets = (
self.group_file_layer,
self.safe_number_parent,
self.safe_network_drive,
self.safe_other_drive,
self.safe_pg_service,
self.safe_pg_auth_db,
self.safe_pg_user_password,
Expand All @@ -924,9 +923,9 @@ def save_settings(self):
QgsSettings().setValue(Settings.key(Settings.BeginnerMode), not self.radio_normal.isChecked())
QgsSettings().setValue(Settings.key(Settings.AllowParentFolder), self.radio_allow_parent_folder.isChecked())
QgsSettings().setValue(Settings.key(Settings.NumberParentFolder), self.safe_number_parent.value())
QgsSettings().setValue(Settings.key(Settings.PreventNetworkDrive), self.safe_network_drive.isChecked())
QgsSettings().setValue(Settings.key(Settings.PreventDrive), self.safe_other_drive.isChecked())
QgsSettings().setValue(Settings.key(Settings.PreventPgService), self.safe_pg_service.isChecked())
QgsSettings().setValue(Settings.key(Settings.PreventPgAuthId), self.safe_pg_auth_db.isChecked())
QgsSettings().setValue(Settings.key(Settings.PreventPgAuthDb), self.safe_pg_auth_db.isChecked())
QgsSettings().setValue(Settings.key(Settings.ForcePgUserPass), self.safe_pg_user_password.isChecked())
QgsSettings().setValue(Settings.key(Settings.PreventEcw), self.safe_ecw.isChecked())

Expand Down
3 changes: 0 additions & 3 deletions lizmap/models/__init__.py

This file was deleted.

Loading

0 comments on commit 39c4ac4

Please sign in to comment.