Skip to content

Commit

Permalink
Fix #47 changing entry points to carto.com domain.
Browse files Browse the repository at this point in the history
Resolve some deprecated warnings.
  • Loading branch information
elesdoar committed Sep 16, 2016
1 parent 268a4ff commit ff03111
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<a name="0.2.6"></a>
### 0.2.6 (2016-09-16)

#### Fixes

* Fix #47 changing entry points to carto.com domain.
* Resolve some deprecated warnings.

<a name="0.2.5"></a>
### 0.2.5 (2016-07-08)

Expand Down
3 changes: 2 additions & 1 deletion cartodb/cartodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}'
Expand Down
2 changes: 1 addition & 1 deletion dialogs/NewSQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
31 changes: 20 additions & 11 deletions layers/CartoDBLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ff03111

Please sign in to comment.