Commit 731d14c1 authored by Serge Koval's avatar Serge Koval

SQLAlchemy fixes, flake8 fixes

parent ae01e5f4
......@@ -19,7 +19,7 @@ class GeoJSONField(JSONField):
super(GeoJSONField, self).__init__(label, validators, **kwargs)
self.web_srid = 4326
self.srid = srid
if self.srid is -1:
if self.srid == -1:
self.transform_srid = self.web_srid
else:
self.transform_srid = self.srid
......@@ -30,7 +30,7 @@ class GeoJSONField(JSONField):
if self.raw_data:
return self.raw_data[0]
if type(self.data) is geoalchemy2.elements.WKBElement:
if self.srid is -1:
if self.srid == -1:
return self.session.scalar(func.ST_AsGeoJson(self.data))
else:
return self.session.scalar(
......@@ -43,7 +43,7 @@ class GeoJSONField(JSONField):
def process_formdata(self, valuelist):
super(GeoJSONField, self).process_formdata(valuelist)
if str(self.data) is '':
if str(self.data) == '':
self.data = None
if self.data is not None:
web_shape = self.session.scalar(
......
......@@ -17,8 +17,10 @@ def geom_formatter(view, value):
"data-tile-layer-url": view.tile_layer_url,
"data-tile-layer-attribution": view.tile_layer_attribution
})
if value.srid is -1:
if value.srid == -1:
value.srid = 4326
geojson = view.session.query(view.model).with_entities(func.ST_AsGeoJSON(value)).scalar()
return Markup('<textarea %s>%s</textarea>' % (params, geojson))
......
......@@ -364,8 +364,8 @@ class ModelView(BaseModelView):
# Check type
if (field_type not in self.allowed_search_types):
raise Exception('Can only search on text columns. ' +
'Failed to setup search for "%s"' % p)
raise Exception('Can only search on text columns. ' +
'Failed to setup search for "%s"' % p)
self._search_fields.append(p)
......
......@@ -221,8 +221,8 @@ class ModelView(BaseModelView):
# Check type
if not isinstance(p, (CharField, TextField)):
raise Exception('Can only search on text columns. ' +
'Failed to setup search for "%s"' % p)
raise Exception('Can only search on text columns. ' +
'Failed to setup search for "%s"' % p)
self._search_fields.append(p)
......
......@@ -3,7 +3,7 @@ import warnings
import inspect
from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy.orm.base import manager_of_class
from sqlalchemy.orm.base import manager_of_class, instance_state
from sqlalchemy.orm import joinedload, aliased
from sqlalchemy.sql.expression import desc
from sqlalchemy import Boolean, Table, func, or_
......@@ -1115,6 +1115,10 @@ class ModelView(BaseModelView):
"""
try:
model = self._manager.new_instance()
# TODO: We need a better way to create model instances and stay compatible with SQLAlchemy __init__() behavior
state = instance_state(model)
self._manager.dispatch.init(state, [], {})
form.populate_obj(model)
self.session.add(model)
self._on_model_change(form, model, True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment