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
8d690ae9
Commit
8d690ae9
authored
Mar 01, 2015
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix python 3 compatibility issue, trim trailing space
parent
72cce208
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
fileadmin.py
flask_admin/contrib/fileadmin.py
+11
-11
test_fileadmin.py
flask_admin/tests/fileadmin/test_fileadmin.py
+1
-1
No files found.
flask_admin/contrib/fileadmin.py
View file @
8d690ae9
...
...
@@ -122,7 +122,7 @@ class FileAdmin(BaseView, ActionsMixin):
"""
Base form class. Will be used to create the upload, rename, edit, and delete form.
Allows enabling CSRF validation and useful if you want to have custom
Allows enabling CSRF validation and useful if you want to have custom
contructor or override some fields.
Example::
...
...
@@ -205,7 +205,7 @@ class FileAdmin(BaseView, ActionsMixin):
directories, etc)
"""
return
self
.
base_url
def
get_upload_form
(
self
):
"""
Upload form class for file upload view.
...
...
@@ -219,10 +219,10 @@ class FileAdmin(BaseView, ActionsMixin):
"""
upload
=
fields
.
FileField
(
lazy_gettext
(
'File to upload'
))
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
UploadForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
admin
=
kwargs
[
'admin'
]
def
validate_upload
(
self
,
field
):
if
not
self
.
upload
.
data
:
raise
validators
.
ValidationError
(
gettext
(
'File required.'
))
...
...
@@ -245,7 +245,7 @@ class FileAdmin(BaseView, ActionsMixin):
(
validators
.
required
(),))
return
EditForm
def
get_name_form
(
self
):
"""
Create form class for renaming and mkdir views.
...
...
@@ -280,7 +280,7 @@ class FileAdmin(BaseView, ActionsMixin):
path
=
fields
.
HiddenField
(
validators
=
[
validators
.
Required
()])
return
DeleteForm
def
upload_form
(
self
):
"""
Instantiate file upload form and return it.
...
...
@@ -293,7 +293,7 @@ class FileAdmin(BaseView, ActionsMixin):
# https://bitbucket.org/danjac/flask-wtf/issue/12/fieldlist-filefield-does-not-follow
formdata
=
request
.
form
.
copy
()
# as request.form is immutable
formdata
.
update
(
request
.
files
)
# admin=self allows the form to use self.is_file_allowed
return
upload_form_class
(
formdata
,
admin
=
self
)
elif
request
.
files
:
...
...
@@ -314,7 +314,7 @@ class FileAdmin(BaseView, ActionsMixin):
return
name_form_class
(
request
.
args
)
else
:
return
name_form_class
()
def
edit_form
(
self
):
"""
Instantiate file editing form and return it.
...
...
@@ -699,7 +699,7 @@ class FileAdmin(BaseView, ActionsMixin):
flash
(
gettext
(
'Failed to create directory:
%(error)
s'
,
error
=
ex
),
'error'
)
else
:
helpers
.
flash_errors
(
form
,
message
=
'Failed to create directory:
%(error)
s'
)
return
self
.
render
(
self
.
mkdir_template
,
form
=
form
,
dir_url
=
dir_url
)
...
...
@@ -717,7 +717,7 @@ class FileAdmin(BaseView, ActionsMixin):
else
:
return_url
=
self
.
get_url
(
'.index'
)
if
self
.
validate_form
(
form
):
if
self
.
validate_form
(
form
):
# Get path and verify if it is valid
base_path
,
full_path
,
path
=
self
.
_normalize_path
(
path
)
...
...
@@ -847,7 +847,7 @@ class FileAdmin(BaseView, ActionsMixin):
helpers
.
flash_errors
(
form
,
message
=
'Failed to edit file.
%(error)
s'
)
try
:
with
open
(
full_path
,
'r'
)
as
f
:
with
open
(
full_path
,
'r
b
'
)
as
f
:
content
=
f
.
read
()
except
IOError
:
flash
(
gettext
(
"Error reading
%(name)
s."
,
name
=
path
),
'error'
)
...
...
flask_admin/tests/fileadmin/test_fileadmin.py
View file @
8d690ae9
...
...
@@ -34,7 +34,7 @@ def test_file_admin():
rv
=
client
.
get
(
'/admin/myfileadmin/'
)
eq_
(
rv
.
status_code
,
200
)
ok_
(
'path=dummy.txt'
in
rv
.
data
.
decode
(
'utf-8'
))
# edit
rv
=
client
.
get
(
'/admin/myfileadmin/edit/?path=dummy.txt'
)
eq_
(
rv
.
status_code
,
200
)
...
...
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