Skip to content

Commit

Permalink
handling the error of unspported version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gpetrak committed Nov 8, 2024
1 parent 6286df0 commit 7435c31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/qgis_geonode/apiclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ def get_geonode_client(
connection_settings: "ConnectionSettings",
) -> typing.Optional["BaseGeonodeClient"]:
version = connection_settings.geonode_version

result = None
if version is not None and version != UNSUPPORTED_REMOTE:
class_path = select_supported_client(connection_settings.geonode_version)
module_path, class_name = class_path.rpartition(".")[::2]
imported_module = importlib.import_module(module_path)
class_type = getattr(imported_module, class_name)
result = class_type.from_connection_settings(connection_settings)
else:
result = None
if class_path != None:
module_path, class_name = class_path.rpartition(".")[::2]
imported_module = importlib.import_module(module_path)
class_type = getattr(imported_module, class_name)
result = class_type.from_connection_settings(connection_settings)
return result


def select_supported_client(geonode_version: packaging_version.Version) -> str:
if geonode_version.major == 4:

result = None
if geonode_version.major >= 4 and geonode_version.major < 5:
result = "qgis_geonode.apiclient.geonode_api_v2.GeoNodeApiClient"

return result
11 changes: 8 additions & 3 deletions src/qgis_geonode/gui/connection_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,14 @@ def handle_discovery_test(self, task_result: bool):
task_result, self.discovery_task
)
if geonode_version is not None:
self.remote_geonode_version = geonode_version
message = "Connection is valid"
level = qgis.core.Qgis.Info
if geonode_version.major < 4 or geonode_version.major >= 5:
message = "This GeoNode version is not supported by this version of the plugin"
level = qgis.core.Qgis.Critical
self.remote_geonode_version = network.UNSUPPORTED_REMOTE
else:
self.remote_geonode_version = geonode_version
message = "Connection is valid"
level = qgis.core.Qgis.Info
else:
message = "Connection is not valid"
level = qgis.core.Qgis.Critical
Expand Down

0 comments on commit 7435c31

Please sign in to comment.