1616from ..tasks import network_task
1717from .. import apiclient , network , utils
1818from ..apiclient .base import BaseGeonodeClient
19+ from ..apiclient import is_api_client_supported
1920from ..conf import ConnectionSettings , WfsVersion , settings_manager , plugin_metadata
2021from ..utils import tr
2122from packaging import version as packaging_version
@@ -43,9 +44,6 @@ class ConnectionDialog(QtWidgets.QDialog, DialogUi):
4344 detected_capabilities_lw : QtWidgets .QListWidget
4445
4546 connection_id : uuid .UUID
46- remote_geonode_version : typing .Optional [
47- typing .Union [packaging_version .Version , str ]
48- ]
4947 discovery_task : typing .Optional [network_task .NetworkRequestTask ]
5048 geonode_client : BaseGeonodeClient = None
5149
@@ -69,7 +67,6 @@ def __init__(self, connection_settings: typing.Optional[ConnectionSettings] = No
6967 self ._populate_wfs_version_combobox ()
7068 if connection_settings is not None :
7169 self .connection_id = connection_settings .id
72- self .remote_geonode_version = connection_settings .geonode_version
7370 self .name_le .setText (connection_settings .name )
7471 self .url_le .setText (connection_settings .base_url )
7572 self .authcfg_acs .setConfigId (connection_settings .auth_config )
@@ -78,15 +75,12 @@ def __init__(self, connection_settings: typing.Optional[ConnectionSettings] = No
7875 connection_settings .wfs_version
7976 )
8077 self .wfs_version_cb .setCurrentIndex (wfs_version_index )
81- if self .remote_geonode_version == network .UNSUPPORTED_REMOTE :
82- utils .show_message (
83- self .bar ,
84- tr ("Invalid configuration. Correct GeoNode URL and/or test again." ),
85- level = qgis .core .Qgis .Critical ,
86- )
78+
79+ self .detected_version_gb .setEnabled (False )
80+ self .buttonBox .button (QtWidgets .QDialogButtonBox .Ok ).setEnabled (False )
81+
8782 else :
8883 self .connection_id = uuid .uuid4 ()
89- self .remote_geonode_version = None
9084 self .update_connection_details ()
9185 # self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
9286 ok_signals = [
@@ -157,7 +151,6 @@ def get_connection_settings(self) -> ConnectionSettings:
157151 base_url = self .url_le .text ().strip ().rstrip ("#/" ),
158152 auth_config = self .authcfg_acs .configId (),
159153 page_size = self .page_size_sb .value (),
160- geonode_version = self .remote_geonode_version ,
161154 wfs_version = self .wfs_version_cb .currentData (),
162155 )
163156
@@ -166,38 +159,22 @@ def test_connection(self):
166159 widget .setEnabled (False )
167160
168161 current_settings = self .get_connection_settings ()
169- self .discovery_task = network_task .NetworkRequestTask (
170- [
171- network .RequestToPerform (
172- QtCore .QUrl (f"{ current_settings .base_url } /version.txt" )
173- )
174- ],
175- network_task_timeout = current_settings .network_requests_timeout ,
176- authcfg = current_settings .auth_config ,
177- description = "Connect to a GeoNode client" ,
178- )
179- self .discovery_task .task_done .connect (self .handle_discovery_test )
180- utils .show_message (self .bar , tr ("Connecting..." ), add_loading_widget = True )
181- qgis .core .QgsApplication .taskManager ().addTask (self .discovery_task )
182162
183- def handle_discovery_test (self , task_result : bool ):
163+ # Replace old version.txt request with /api/v2/ check
164+ success = is_api_client_supported (current_settings .base_url )
165+
166+ self .handle_discovery_test (success )
167+
168+ def handle_discovery_test (self , is_supported : bool ):
184169 self .enable_post_test_connection_buttons ()
185- geonode_version = network .handle_discovery_test (
186- task_result , self .discovery_task
187- )
188- if geonode_version is not None :
189- if apiclient .validate_version (geonode_version ) == False :
190- message = "This GeoNode version is not supported..."
191- level = qgis .core .Qgis .Critical
192- self .remote_geonode_version = network .UNSUPPORTED_REMOTE
193- else :
194- self .remote_geonode_version = geonode_version
195- message = "Connection is valid"
196- level = qgis .core .Qgis .Info
170+
171+ if is_supported :
172+ message = "Connection is valid"
173+ level = qgis .core .Qgis .Info
197174 else :
198- message = "Connection is not valid "
175+ message = "This GeoNode instance does not support the API client. "
199176 level = qgis .core .Qgis .Critical
200- self . remote_geonode_version = network . UNSUPPORTED_REMOTE
177+
201178 utils .show_message (self .bar , message , level )
202179 self .update_connection_details ()
203180
@@ -236,20 +213,24 @@ def handle_wfs_version_detection_test(self, task_result: bool):
236213 self .wfs_version_cb .setCurrentIndex (index )
237214
238215 def update_connection_details (self ):
239- invalid_version = (
240- self .remote_geonode_version is None
241- or self .remote_geonode_version == network .UNSUPPORTED_REMOTE
242- )
216+ # Determine if API is reachable
217+ api_supported = is_api_client_supported (self .url_le .text ().strip ().rstrip ("#/" ))
218+
243219 self .detected_capabilities_lw .clear ()
244220 self .detected_version_le .clear ()
245- if not invalid_version :
246- # Enable the detected_version_db and OK button
221+
222+ if api_supported :
223+ # Enable the detected_version group box and OK button
247224 self .detected_version_gb .setEnabled (True )
248225 self .buttonBox .button (QtWidgets .QDialogButtonBox .Ok ).setEnabled (True )
249226
250227 current_settings = self .get_connection_settings ()
251228 client : BaseGeonodeClient = apiclient .get_geonode_client (current_settings )
252- self .detected_version_le .setText (str (current_settings .geonode_version ))
229+
230+ # No version stored; just show "v2 API available"
231+ self .detected_version_le .setText ("API v2 available" )
232+
233+ # Show capabilities from client
253234 self .detected_capabilities_lw .insertItems (
254235 0 , [cap .name for cap in client .capabilities ]
255236 )
0 commit comments