Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
7b1a999e
Commit
7b1a999e
authored
Jun 13, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pymongo backend fixes
parent
510fd4db
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
15 deletions
+13
-15
simple.py
examples/pymongo/simple.py
+2
-4
base.py
flask_admin/base.py
+6
-6
view.py
flask_admin/contrib/pymongo/view.py
+5
-5
No files found.
examples/pymongo/simple.py
View file @
7b1a999e
...
@@ -8,7 +8,7 @@ from wtforms import form, fields
...
@@ -8,7 +8,7 @@ from wtforms import form, fields
from
flask.ext.admin.form
import
Select2Widget
from
flask.ext.admin.form
import
Select2Widget
from
flask.ext.admin.contrib.pymongo
import
ModelView
,
filters
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
# Create application
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -98,9 +98,7 @@ class TweetView(ModelView):
...
@@ -98,9 +98,7 @@ class TweetView(ModelView):
# Correct user_id reference before saving
# Correct user_id reference before saving
def
on_model_change
(
self
,
form
,
model
):
def
on_model_change
(
self
,
form
,
model
):
user_id
=
model
.
get
(
'user_id'
)
user_id
=
model
.
get
(
'user_id'
)
model
[
'user_id'
]
=
ObjectId
(
user_id
)
if
isinstance
(
user_id
,
basestring
):
model
[
'user_id'
]
=
ObjectId
(
user_id
)
return
model
return
model
...
...
flask_admin/base.py
View file @
7b1a999e
...
@@ -170,7 +170,7 @@ class BaseView(_compat.with_metaclass(AdminViewMeta, BaseClass)):
...
@@ -170,7 +170,7 @@ class BaseView(_compat.with_metaclass(AdminViewMeta, BaseClass)):
# Default view
# Default view
if
self
.
_default_view
is
None
:
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
):
def
create_blueprint
(
self
,
admin
):
"""
"""
...
@@ -522,7 +522,7 @@ class Admin(object):
...
@@ -522,7 +522,7 @@ class Admin(object):
return request.args.get('lang', 'en')
return request.args.get('lang', 'en')
"""
"""
if
self
.
locale_selector_func
is
not
None
:
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
self
.
locale_selector_func
=
f
...
@@ -569,12 +569,12 @@ class Admin(object):
...
@@ -569,12 +569,12 @@ class Admin(object):
for
p
in
admins
:
for
p
in
admins
:
if
p
.
endpoint
==
self
.
endpoint
:
if
p
.
endpoint
==
self
.
endpoint
:
raise
Exception
(
'Cannot have two Admin() instances with same'
raise
Exception
(
u
'Cannot have two Admin() instances with same'
' endpoint name.'
)
u
' endpoint name.'
)
if
p
.
url
==
self
.
url
and
p
.
subdomain
==
self
.
subdomain
:
if
p
.
url
==
self
.
url
and
p
.
subdomain
==
self
.
subdomain
:
raise
Exception
(
'Cannot assign two Admin() instances with same'
raise
Exception
(
u
'Cannot assign two Admin() instances with same'
' URL and subdomain to the same application.'
)
u
' URL and subdomain to the same application.'
)
admins
.
append
(
self
)
admins
.
append
(
self
)
self
.
app
.
extensions
[
'admin'
]
=
admins
self
.
app
.
extensions
[
'admin'
]
=
admins
...
...
flask_admin/contrib/pymongo/view.py
View file @
7b1a999e
...
@@ -206,7 +206,7 @@ class ModelView(BaseModelView):
...
@@ -206,7 +206,7 @@ class ModelView(BaseModelView):
if
sort_column
:
if
sort_column
:
sort_by
=
[(
sort_column
,
pymongo
.
DESCENDING
if
sort_desc
else
pymongo
.
ASCENDING
)]
sort_by
=
[(
sort_column
,
pymongo
.
DESCENDING
if
sort_desc
else
pymongo
.
ASCENDING
)]
else
:
else
:
order
=
self
.
get_default_order
()
order
=
self
.
_
get_default_order
()
if
order
:
if
order
:
sort_by
=
[(
order
[
0
],
pymongo
.
DESCENDING
if
order
[
1
]
else
pymongo
.
ASCENDING
)]
sort_by
=
[(
order
[
0
],
pymongo
.
DESCENDING
if
order
[
1
]
else
pymongo
.
ASCENDING
)]
...
@@ -256,7 +256,7 @@ class ModelView(BaseModelView):
...
@@ -256,7 +256,7 @@ class ModelView(BaseModelView):
model
=
form
.
data
model
=
form
.
data
self
.
on_model_change
(
form
,
model
)
self
.
on_model_change
(
form
,
model
)
self
.
coll
.
insert
(
model
)
self
.
coll
.
insert
(
model
)
except
Exception
,
ex
:
except
Exception
as
ex
:
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
str
(
ex
)),
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
'error'
)
logging
.
exception
(
'Failed to create model'
)
logging
.
exception
(
'Failed to create model'
)
...
@@ -281,7 +281,7 @@ class ModelView(BaseModelView):
...
@@ -281,7 +281,7 @@ class ModelView(BaseModelView):
pk
=
self
.
get_pk_value
(
model
)
pk
=
self
.
get_pk_value
(
model
)
self
.
coll
.
update
({
'_id'
:
pk
},
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
)),
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
'error'
)
logging
.
exception
(
'Failed to update model'
)
logging
.
exception
(
'Failed to update model'
)
...
@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
...
@@ -307,7 +307,7 @@ class ModelView(BaseModelView):
self
.
on_model_delete
(
model
)
self
.
on_model_delete
(
model
)
self
.
coll
.
remove
({
'_id'
:
pk
})
self
.
coll
.
remove
({
'_id'
:
pk
})
return
True
return
True
except
Exception
,
ex
:
except
Exception
as
ex
:
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
str
(
ex
)),
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
'error'
)
logging
.
exception
(
'Failed to delete model'
)
logging
.
exception
(
'Failed to delete model'
)
...
@@ -337,6 +337,6 @@ class ModelView(BaseModelView):
...
@@ -337,6 +337,6 @@ class ModelView(BaseModelView):
'
%(count)
s models were successfully deleted.'
,
'
%(count)
s models were successfully deleted.'
,
count
,
count
,
count
=
count
))
count
=
count
))
except
Exception
,
ex
:
except
Exception
as
ex
:
flash
(
gettext
(
'Failed to delete models.
%(error)
s'
,
error
=
str
(
ex
)),
flash
(
gettext
(
'Failed to delete models.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
'error'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment