From ff0311134274572e34deccac56a53de76010e0ac Mon Sep 17 00:00:00 2001 From: "Michael A. Salgado" Date: Fri, 16 Sep 2016 11:59:18 -0500 Subject: [PATCH] Fix #47 changing entry points to carto.com domain. Resolve some deprecated warnings. --- CHANGELOG.md | 8 ++++++++ cartodb/cartodbapi.py | 3 ++- dialogs/NewSQL.py | 2 +- layers/CartoDBLayer.py | 31 ++++++++++++++++++++----------- metadata.txt | 5 ++++- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f851a1..a32b1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ + +### 0.2.6 (2016-09-16) + +#### Fixes + +* Fix #47 changing entry points to carto.com domain. +* Resolve some deprecated warnings. + ### 0.2.5 (2016-07-08) diff --git a/cartodb/cartodbapi.py b/cartodb/cartodbapi.py index c3987f0..5f1263f 100644 --- a/cartodb/cartodbapi.py +++ b/cartodb/cartodbapi.py @@ -238,7 +238,8 @@ def returnFetchContent(self, reply): # qDebug('Error: ' + str(reply.error())) # qDebug('Status: ' + str(reply.rawHeader('Location'))) - if reply.rawHeader('Location') == 'http://cartodb.com/noneuser.html': + if reply.rawHeader('Location') == 'http://cartodb.com/noneuser.html' or \ + reply.rawHeader('Location') == 'http://carto.com/noneuser.html': response = '{"error": "User not found"}' elif reply.error() == QNetworkReply.AuthenticationRequiredError: response = '{"error": "Confirm user credentials"}' diff --git a/dialogs/NewSQL.py b/dialogs/NewSQL.py index fe27f83..3934373 100644 --- a/dialogs/NewSQL.py +++ b/dialogs/NewSQL.py @@ -183,7 +183,7 @@ def testQuery(self): return sql = 'SELECT count(cartodb_id) num, ST_Union(the_geom) the_geom FROM (' + sql + ') a' - cartoUrl = 'http://{}.cartodb.com/api/v2/sql?format=GeoJSON&q={}&api_key={}'.format(self.currentUser, sql, self.currentApiKey) + cartoUrl = 'http://{}.carto.com/api/v2/sql?format=GeoJSON&q={}&api_key={}'.format(self.currentUser, sql, self.currentApiKey) response = urlopen(cartoUrl) result = json.loads(response.read()) diff --git a/layers/CartoDBLayer.py b/layers/CartoDBLayer.py index c9c5f3c..55284f3 100644 --- a/layers/CartoDBLayer.py +++ b/layers/CartoDBLayer.py @@ -21,7 +21,7 @@ from PyQt4.QtCore import Qt, QDate, QObject, QEventLoop, pyqtSignal, qDebug -from qgis.core import QgsFeatureRequest, QgsVectorLayer, QgsMessageLog, QgsDataSourceURI +from qgis.core import QGis, QgsFeatureRequest, QgsVectorLayer, QgsMessageLog, QgsDataSourceURI from osgeo import ogr from urllib import urlopen @@ -82,7 +82,7 @@ def _loadData(self, sql, geoJSON=None, spatiaLite=None): readonly = True if spatiaLite is None: if geoJSON is None: - cartoUrl = 'http://{}.cartodb.com/api/v2/sql?format=GeoJSON&q={}&api_key={}'.format(self.user, sql, self._apiKey) + cartoUrl = 'http://{}.carto.com/api/v2/sql?format=GeoJSON&q={}&api_key={}'.format(self.user, sql, self._apiKey) response = urlopen(cartoUrl) geoJSON = response.read() else: @@ -180,16 +180,22 @@ def _uneditableFields(self): except CartoDBException as e: QgsMessageLog.logMessage('Error - ' + str(e), 'CartoDB Plugin', QgsMessageLog.CRITICAL) + setEditorType = None + if QGis.QGIS_VERSION_INT < 21400: + setEditorType = self.setEditorWidgetV2 + else: + setEditorType = self.editFormConfig().setWidgetType + self.setFieldEditable(self.fieldNameIndex('cartodb_id'), False) - self.setEditorWidgetV2(self.fieldNameIndex('cartodb_id'), 'Hidden') + setEditorType(self.fieldNameIndex('cartodb_id'), 'Hidden') if self.fieldNameIndex('updated_at') != -1: self.setFieldEditable(self.fieldNameIndex('updated_at'), False) - self.setEditorWidgetV2(self.fieldNameIndex('updated_at'), 'Hidden') + setEditorType(self.fieldNameIndex('updated_at'), 'Hidden') if self.fieldNameIndex('created_at') != -1: self.setFieldEditable(self.fieldNameIndex('created_at'), False) - self.setEditorWidgetV2(self.fieldNameIndex('created_at'), 'Hidden') + setEditorType(self.fieldNameIndex('created_at'), 'Hidden') self.setFieldEditable(self.fieldNameIndex('OGC_FID'), False) self.setFieldEditable(self.fieldNameIndex('GEOMETRY'), False) @@ -242,6 +248,7 @@ def _updateAttributes(self, changedAttributeValues): sql = sql + " WHERE cartodb_id = " + unicode(feature['cartodb_id']) sql = sql.encode('utf-8') + qDebug('SQL Update: ' + sql) res = self._updateSQL(sql, 'Some error ocurred getting tables') if isinstance(res, dict) and res['total_rows'] == 1: self.iface.messageBar().pushMessage('Info', @@ -298,15 +305,16 @@ def _addFeatures(self, addedFeatures): fieldsStr = fieldsStr + field.name() valuesStr = valuesStr + "'" + unicode(value) + "'" addComma = True - if addComma: - fieldsStr = fieldsStr + ", " - valuesStr = valuesStr + ", " - fieldsStr = fieldsStr + "the_geom" - valuesStr = valuesStr + "ST_GeomFromText('" + feature.geometry().exportToWkt() + "', 4326)" + if feature.geometry() is not None: + if addComma: + fieldsStr = fieldsStr + ", " + valuesStr = valuesStr + ", " - sql = sql + fieldsStr + ") VALUES (" + valuesStr + ") RETURNING cartodb_id" + fieldsStr = fieldsStr + "the_geom" + valuesStr = valuesStr + "ST_GeomFromText('" + feature.geometry().exportToWkt() + "', 4326)" + sql = sql + fieldsStr + ") VALUES (" + valuesStr + ") RETURNING cartodb_id" nullableFields = ['cartodb_id'] if feature.fieldNameIndex("created_at") != -1: @@ -359,6 +367,7 @@ def _updateSQL(self, sql, errorMsg): return res except CartoDBException as e: QgsMessageLog.logMessage(errorMsg + ' - ' + str(e), 'CartoDB Plugin', QgsMessageLog.CRITICAL) + QgsMessageLog.logMessage('SQL: ' + str(sql), 'CartoDB Plugin', QgsMessageLog.CRITICAL) self.iface.messageBar().pushMessage('Error!!', errorMsg, level=self.iface.messageBar().CRITICAL, duration=10) return e diff --git a/metadata.txt b/metadata.txt index 1875e23..60ee94c 100644 --- a/metadata.txt +++ b/metadata.txt @@ -2,7 +2,7 @@ name=CartoDB description=CartoDB Plugin for QGis. It allows to view, create, edit or delete data from your CartoDB account using your favorite opensource desktop GIS: QGIS. category=Web -version=0.2.5 +version=0.2.6 qgisMinimumVersion=2.4 icon=images/icon.png author=Kudos Ltda. and contributors @@ -24,6 +24,9 @@ about= - certifi email=michaelsalgado@gkudos.com changelog= + 0.2.6 + - Fix some errors changing entry points to carto.com domain. + - Resolve some deprecated warnings. 0.2.5 - Fix problems with domain changes. 0.2.4