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
aa7b70df
Commit
aa7b70df
authored
Jul 04, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python 3 fixes and pymongo test
parent
f6132626
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
117 additions
and
5 deletions
+117
-5
.travis.yml
.travis.yml
+1
-0
view.py
flask_admin/contrib/pymongo/view.py
+4
-3
test_basic.py
flask_admin/tests/mongoengine/test_basic.py
+6
-0
test_basic.py
flask_admin/tests/peeweemodel/test_basic.py
+6
-0
__init__.py
flask_admin/tests/pymongo/__init__.py
+17
-0
test_basic.py
flask_admin/tests/pymongo/test_basic.py
+81
-0
test_base.py
flask_admin/tests/test_base.py
+2
-2
No files found.
.travis.yml
View file @
aa7b70df
...
@@ -2,6 +2,7 @@ language: python
...
@@ -2,6 +2,7 @@ language: python
python
:
python
:
-
"
2.6"
-
"
2.6"
-
"
2.7"
-
"
2.7"
-
"
3.3"
install
:
"
pip
install
-r
requirements.txt
--use-mirrors"
install
:
"
pip
install
-r
requirements.txt
--use-mirrors"
...
...
flask_admin/contrib/pymongo/view.py
View file @
aa7b70df
...
@@ -10,6 +10,7 @@ from flask.ext.admin._compat import string_types
...
@@ -10,6 +10,7 @@ from flask.ext.admin._compat import string_types
from
flask.ext.admin.babel
import
gettext
,
ngettext
,
lazy_gettext
from
flask.ext.admin.babel
import
gettext
,
ngettext
,
lazy_gettext
from
flask.ext.admin.model
import
BaseModelView
from
flask.ext.admin.model
import
BaseModelView
from
flask.ext.admin.actions
import
action
from
flask.ext.admin.actions
import
action
from
flask.ext.admin.helpers
import
get_form_data
from
.filters
import
BasePyMongoFilter
from
.filters
import
BasePyMongoFilter
from
.tools
import
parse_like_term
from
.tools
import
parse_like_term
...
@@ -237,13 +238,14 @@ class ModelView(BaseModelView):
...
@@ -237,13 +238,14 @@ class ModelView(BaseModelView):
:param id:
:param id:
Model ID
Model ID
"""
"""
print
(
'get'
,
id
)
return
self
.
coll
.
find_one
({
'_id'
:
self
.
_get_valid_id
(
id
)})
return
self
.
coll
.
find_one
({
'_id'
:
self
.
_get_valid_id
(
id
)})
def
edit_form
(
self
,
obj
):
def
edit_form
(
self
,
obj
):
"""
"""
Create edit form from the MongoDB document
Create edit form from the MongoDB document
"""
"""
return
self
.
_edit_form_class
(
**
obj
)
return
self
.
_edit_form_class
(
get_form_data
(),
**
obj
)
def
create_model
(
self
,
form
):
def
create_model
(
self
,
form
):
"""
"""
...
@@ -338,5 +340,4 @@ class ModelView(BaseModelView):
...
@@ -338,5 +340,4 @@ class ModelView(BaseModelView):
count
,
count
,
count
=
count
))
count
=
count
))
except
Exception
as
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'
)
flask_admin/tests/mongoengine/test_basic.py
View file @
aa7b70df
from
nose.tools
import
eq_
,
ok_
from
nose.tools
import
eq_
,
ok_
from
nose.plugins.skip
import
SkipTest
# Skip test on PY3
from
flask.ext.admin._compat
import
PY2
if
not
PY2
:
raise
SkipTest
(
'MongoEngine is not Python 3 compatible'
)
from
wtforms
import
fields
from
wtforms
import
fields
...
...
flask_admin/tests/peeweemodel/test_basic.py
View file @
aa7b70df
from
nose.tools
import
eq_
,
ok_
from
nose.tools
import
eq_
,
ok_
from
nose.plugins.skip
import
SkipTest
# Skip test on PY3
from
flask.ext.admin._compat
import
PY2
if
not
PY2
:
raise
SkipTest
(
'Peewee is not Python 3 compatible'
)
import
peewee
import
peewee
...
...
flask_admin/tests/pymongo/__init__.py
0 → 100644
View file @
aa7b70df
import
pymongo
from
flask
import
Flask
from
flask.ext.admin
import
Admin
def
setup
():
app
=
Flask
(
__name__
)
app
.
config
[
'SECRET_KEY'
]
=
'1'
app
.
config
[
'CSRF_ENABLED'
]
=
False
conn
=
pymongo
.
Connection
()
db
=
conn
.
tests
admin
=
Admin
(
app
)
return
app
,
db
,
admin
flask_admin/tests/pymongo/test_basic.py
0 → 100644
View file @
aa7b70df
from
nose.tools
import
eq_
,
ok_
from
wtforms
import
form
,
fields
from
flask.ext.admin.contrib.pymongo
import
ModelView
from
.
import
setup
class
TestForm
(
form
.
Form
):
test1
=
fields
.
TextField
(
'Test1'
)
test2
=
fields
.
TextField
(
'Test2'
)
class
TestView
(
ModelView
):
column_list
=
(
'test1'
,
'test2'
,
'test3'
,
'test4'
)
column_sortable_list
=
(
'test1'
,
'test2'
)
form
=
TestForm
def
test_model
():
app
,
db
,
admin
=
setup
()
view
=
TestView
(
db
.
test
,
'Test'
)
admin
.
add_view
(
view
)
# Drop existing data (if any)
db
.
test
.
remove
()
eq_
(
view
.
name
,
'Test'
)
eq_
(
view
.
endpoint
,
'testview'
)
ok_
(
'test1'
in
view
.
_sortable_columns
)
ok_
(
'test2'
in
view
.
_sortable_columns
)
ok_
(
view
.
_create_form_class
is
not
None
)
ok_
(
view
.
_edit_form_class
is
not
None
)
eq_
(
view
.
_search_supported
,
False
)
eq_
(
view
.
_filters
,
None
)
# Make some test clients
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/admin/testview/'
)
eq_
(
rv
.
status_code
,
200
)
rv
=
client
.
get
(
'/admin/testview/new/'
)
eq_
(
rv
.
status_code
,
200
)
rv
=
client
.
post
(
'/admin/testview/new/'
,
data
=
dict
(
test1
=
'test1large'
,
test2
=
'test2'
))
eq_
(
rv
.
status_code
,
302
)
model
=
db
.
test
.
find
()[
0
]
print
(
model
)
eq_
(
model
[
'test1'
],
'test1large'
)
eq_
(
model
[
'test2'
],
'test2'
)
rv
=
client
.
get
(
'/admin/testview/'
)
eq_
(
rv
.
status_code
,
200
)
ok_
(
'test1large'
in
rv
.
data
.
decode
(
'utf-8'
))
url
=
'/admin/testview/edit/?id=
%
s'
%
model
[
'_id'
]
rv
=
client
.
get
(
url
)
eq_
(
rv
.
status_code
,
200
)
rv
=
client
.
post
(
url
,
data
=
dict
(
test1
=
'test1small'
,
test2
=
'test2large'
))
eq_
(
rv
.
status_code
,
302
)
print
(
db
.
test
.
find
()[
0
])
model
=
db
.
test
.
find
()[
0
]
eq_
(
model
[
'test1'
],
'test1small'
)
eq_
(
model
[
'test2'
],
'test2large'
)
url
=
'/admin/testview/delete/?id=
%
s'
%
model
[
'_id'
]
rv
=
client
.
post
(
url
)
eq_
(
rv
.
status_code
,
302
)
eq_
(
db
.
test
.
count
(),
0
)
flask_admin/tests/test_base.py
View file @
aa7b70df
...
@@ -352,5 +352,5 @@ def test_menu_links():
...
@@ -352,5 +352,5 @@ def test_menu_links():
rv
=
client
.
get
(
'/admin/'
)
rv
=
client
.
get
(
'/admin/'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'TestMenuLink1'
in
data
.
decode
(
'utf-8'
)
)
ok_
(
'TestMenuLink1'
in
data
)
ok_
(
'TestMenuLink2'
in
data
.
decode
(
'utf-8'
)
)
ok_
(
'TestMenuLink2'
in
data
)
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