Commit 7b1a999e authored by Serge S. Koval's avatar Serge S. Koval

pymongo backend fixes

parent 510fd4db
......@@ -8,7 +8,7 @@ from wtforms import form, fields
from flask.ext.admin.form import Select2Widget
from flask.ext.admin.contrib.pymongo import ModelView, filters
from flask.ext.admin.model import InlineFormField, InlineFieldList
from flask.ext.admin.model.fields import InlineFormField, InlineFieldList
# Create application
app = Flask(__name__)
......@@ -98,9 +98,7 @@ class TweetView(ModelView):
# Correct user_id reference before saving
def on_model_change(self, form, model):
user_id = model.get('user_id')
if isinstance(user_id, basestring):
model['user_id'] = ObjectId(user_id)
model['user_id'] = ObjectId(user_id)
return model
......
......@@ -170,7 +170,7 @@ class BaseView(_compat.with_metaclass(AdminViewMeta, BaseClass)):
# Default view
if self._default_view is None:
raise Exception('Attempted to instantiate admin view %s without default view' % self.__class__.__name__)
raise Exception(u'Attempted to instantiate admin view %s without default view' % self.__class__.__name__)
def create_blueprint(self, admin):
"""
......@@ -522,7 +522,7 @@ class Admin(object):
return request.args.get('lang', 'en')
"""
if self.locale_selector_func is not None:
raise Exception('Can not add locale_selector second time.')
raise Exception(u'Can not add locale_selector second time.')
self.locale_selector_func = f
......@@ -569,12 +569,12 @@ class Admin(object):
for p in admins:
if p.endpoint == self.endpoint:
raise Exception('Cannot have two Admin() instances with same'
' endpoint name.')
raise Exception(u'Cannot have two Admin() instances with same'
u' endpoint name.')
if p.url == self.url and p.subdomain == self.subdomain:
raise Exception('Cannot assign two Admin() instances with same'
' URL and subdomain to the same application.')
raise Exception(u'Cannot assign two Admin() instances with same'
u' URL and subdomain to the same application.')
admins.append(self)
self.app.extensions['admin'] = admins
......
......@@ -206,7 +206,7 @@ class ModelView(BaseModelView):
if sort_column:
sort_by = [(sort_column, pymongo.DESCENDING if sort_desc else pymongo.ASCENDING)]
else:
order = self.get_default_order()
order = self._get_default_order()
if order:
sort_by = [(order[0], pymongo.DESCENDING if order[1] else pymongo.ASCENDING)]
......@@ -256,7 +256,7 @@ class ModelView(BaseModelView):
model = form.data
self.on_model_change(form, model)
self.coll.insert(model)
except Exception, ex:
except Exception as ex:
flash(gettext('Failed to create model. %(error)s', error=str(ex)),
'error')
logging.exception('Failed to create model')
......@@ -281,7 +281,7 @@ class ModelView(BaseModelView):
pk = self.get_pk_value(model)
self.coll.update({'_id': pk}, model)
except Exception, ex:
except Exception as ex:
flash(gettext('Failed to update model. %(error)s', error=str(ex)),
'error')
logging.exception('Failed to update model')
......@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
self.on_model_delete(model)
self.coll.remove({'_id': pk})
return True
except Exception, ex:
except Exception as ex:
flash(gettext('Failed to delete model. %(error)s', error=str(ex)),
'error')
logging.exception('Failed to delete model')
......@@ -337,6 +337,6 @@ class ModelView(BaseModelView):
'%(count)s models were successfully deleted.',
count,
count=count))
except Exception, ex:
except Exception as ex:
flash(gettext('Failed to delete models. %(error)s', error=str(ex)),
'error')
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