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
66874b8d
Commit
66874b8d
authored
Sep 11, 2015
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1046 from pawl/move_file_admin_templates
File-admin - combine mkdir, rename, edit, and upload templates
parents
4c0bf96c
92a20bd7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
93 additions
and
213 deletions
+93
-213
fileadmin.py
flask_admin/contrib/fileadmin.py
+54
-14
edit.html
flask_admin/templates/bootstrap2/admin/file/edit.html
+0
-40
form.html
flask_admin/templates/bootstrap2/admin/file/form.html
+3
-23
form.html
flask_admin/templates/bootstrap2/admin/file/modals/form.html
+16
-0
rename.html
flask_admin/templates/bootstrap2/admin/file/rename.html
+0
-30
edit.html
flask_admin/templates/bootstrap3/admin/file/edit.html
+0
-45
form.html
flask_admin/templates/bootstrap3/admin/file/form.html
+3
-28
form.html
flask_admin/templates/bootstrap3/admin/file/modals/form.html
+17
-0
rename.html
flask_admin/templates/bootstrap3/admin/file/rename.html
+0
-33
No files found.
flask_admin/contrib/fileadmin.py
View file @
66874b8d
...
...
@@ -103,21 +103,41 @@ class FileAdmin(BaseView, ActionsMixin):
File upload template
"""
upload_modal_template
=
'admin/file/modals/form.html'
"""
File upload template for modal dialog
"""
mkdir_template
=
'admin/file/form.html'
"""
Directory creation (mkdir) template
"""
rename_template
=
'admin/file/rename.html'
mkdir_modal_template
=
'admin/file/modals/form.html'
"""
Directory creation (mkdir) template for modal dialog
"""
rename_template
=
'admin/file/form.html'
"""
Rename template
"""
edit_template
=
'admin/file/edit.html'
rename_modal_template
=
'admin/file/modals/form.html'
"""
Rename template for modal dialog
"""
edit_template
=
'admin/file/form.html'
"""
Edit template
"""
edit_modal_template
=
'admin/file/modals/form.html'
"""
Edit template for modal dialog
"""
form_base_class
=
form
.
BaseForm
"""
Base form class. Will be used to create the upload, rename, edit, and delete form.
...
...
@@ -660,7 +680,12 @@ class FileAdmin(BaseView, ActionsMixin):
except
Exception
as
ex
:
flash
(
gettext
(
'Failed to save file:
%(error)
s'
,
error
=
ex
),
'error'
)
return
self
.
render
(
self
.
upload_template
,
form
=
form
,
if
self
.
upload_modal
and
request
.
args
.
get
(
'modal'
):
template
=
self
.
upload_modal_template
else
:
template
=
self
.
upload_template
return
self
.
render
(
template
,
form
=
form
,
header_text
=
gettext
(
'Upload File'
),
modal
=
request
.
args
.
get
(
'modal'
))
...
...
@@ -721,9 +746,13 @@ class FileAdmin(BaseView, ActionsMixin):
else
:
helpers
.
flash_errors
(
form
,
message
=
'Failed to create directory:
%(error)
s'
)
return
self
.
render
(
self
.
mkdir_template
,
form
=
form
,
dir_url
=
dir_url
,
header_text
=
gettext
(
'Create Directory'
),
modal
=
request
.
args
.
get
(
'modal'
))
if
self
.
mkdir_modal
and
request
.
args
.
get
(
'modal'
):
template
=
self
.
mkdir_modal_template
else
:
template
=
self
.
mkdir_template
return
self
.
render
(
template
,
form
=
form
,
dir_url
=
dir_url
,
header_text
=
gettext
(
'Create Directory'
))
@
expose
(
'/delete/'
,
methods
=
(
'POST'
,))
def
delete
(
self
):
...
...
@@ -817,12 +846,15 @@ class FileAdmin(BaseView, ActionsMixin):
else
:
helpers
.
flash_errors
(
form
,
message
=
'Failed to rename:
%(error)
s'
)
return
self
.
render
(
self
.
rename_template
,
form
=
form
,
path
=
op
.
dirname
(
path
),
name
=
op
.
basename
(
path
),
dir_url
=
return_url
,
modal
=
request
.
args
.
get
(
'modal'
))
if
self
.
rename_modal
and
request
.
args
.
get
(
'modal'
):
template
=
self
.
rename_modal_template
else
:
template
=
self
.
rename_template
return
self
.
render
(
template
,
form
=
form
,
path
=
op
.
dirname
(
path
),
name
=
op
.
basename
(
path
),
dir_url
=
return_url
,
header_text
=
gettext
(
'Rename
%(name)
s'
,
name
=
op
.
basename
(
path
)))
@
expose
(
'/edit/'
,
methods
=
(
'GET'
,
'POST'
))
def
edit
(
self
):
...
...
@@ -889,9 +921,17 @@ class FileAdmin(BaseView, ActionsMixin):
else
:
form
.
content
.
data
=
content
return
self
.
render
(
self
.
edit_template
,
dir_url
=
dir_url
,
path
=
path
,
if
error
:
return
redirect
(
next_url
)
if
self
.
edit_modal
and
request
.
args
.
get
(
'modal'
):
template
=
self
.
edit_modal_template
else
:
template
=
self
.
edit_template
return
self
.
render
(
template
,
dir_url
=
dir_url
,
path
=
path
,
form
=
form
,
error
=
error
,
modal
=
request
.
args
.
get
(
'modal'
))
header_text
=
gettext
(
'Editing
%(path)
s'
,
path
=
path
))
@
expose
(
'/action/'
,
methods
=
(
'POST'
,))
def
action_view
(
self
):
...
...
flask_admin/templates/bootstrap2/admin/file/edit.html
deleted
100644 → 0
View file @
4c0bf96c
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% macro check_error(error) %}
{% if error %}
<span>
{{ _gettext('This file cannot be edited for now.') }}
</span>
{% else %}
{{ caller() }}
{% endif %}
{% endmacro %}
{% block body %}
{% call check_error(error) %}
{%- if modal -%}
{# content added to modal-content #}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{%- else -%}
{% block header_text -%}
<h3>
{{ _gettext('Editing %(path)s', path=path) }}
<h3>
{%- endblock %}
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endcall %}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fill the header of modal dynamically
$
(
'.modal-header h3'
).
html
(
'{{ self.header_text() }}'
);
// fixes "remote modal shows same content every time"
$
(
'.modal'
).
on
(
'hidden'
,
function
()
{
$
(
this
).
removeData
(
'modal'
);
});
</script>
{%- endif -%}
{% endblock %}
flask_admin/templates/bootstrap2/admin/file/form.html
View file @
66874b8d
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{%- else -%}
<h3>
{{ header_text }}
</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fill the header of modal dynamically
$
(
'.modal-header h3'
).
html
(
'{{ header_text }}'
);
// fixes "remote modal shows same content every time"
$
(
'.modal'
).
on
(
'hidden'
,
function
()
{
$
(
this
).
removeData
(
'modal'
);
});
</script>
{%- endif -%}
{% block header %}
<h3>
{{ header_text }}
</h3>
{% endblock %}
{{ lib.render_form(form, dir_url) }}
{% endblock %}
flask_admin/templates/bootstrap2/admin/file/modals/form.html
0 → 100644
View file @
66874b8d
{% import 'admin/static.html' as admin_static with context %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{# content added to modal-content #}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{% endblock %}
{% block tail %}
<script
src=
"{{ admin_static.url(filename='admin/js/bs2_modal.js', v='1.0.0') }}"
></script>
<script>
// fill the header of modal dynamically
$
(
'.modal-header h3'
).
html
(
'{% block header %}{{ header_text }}{% endblock %}'
);
</script>
{% endblock %}
flask_admin/templates/bootstrap2/admin/file/rename.html
deleted
100644 → 0
View file @
4c0bf96c
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{%- else -%}
<h3>
{% block header_text -%}
{{ _gettext('Rename %(name)s', name=name) }}
{%- endblock %}
</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fill the header of modal dynamically
$
(
'.modal-header h3'
).
html
(
'{{ self.header_text() }}'
);
// fixes "remote modal shows same content every time"
$
(
'.modal'
).
on
(
'hidden'
,
function
()
{
$
(
this
).
removeData
(
'modal'
);
});
</script>
{%- endif -%}
{% endblock %}
flask_admin/templates/bootstrap3/admin/file/edit.html
deleted
100644 → 0
View file @
4c0bf96c
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% macro check_error(error) %}
{% if error %}
<span>
{{ _gettext('This file cannot be edited for now.') }}
</span>
{% else %}
{{ caller() }}
{% endif %}
{% endmacro %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
{% block header_text %}
<h3>
{{ _gettext('Editing %(path)s', path=path) }}
</h3>
{% endblock %}
</div>
<div
class=
"modal-body"
>
{% call check_error(error) %}
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
{% endcall %}
</div>
{%- else -%}
{{ self.header_text() }}
{% call check_error(error) %}
{{ lib.render_form(form, dir_url) }}
{% endcall %}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fixes "remote modal shows same content every time", avoiding the flicker
$
(
'body'
).
on
(
'hidden.bs.modal'
,
'.modal'
,
function
()
{
$
(
this
).
removeData
(
'bs.modal'
).
find
(
".modal-content"
).
empty
();
});
</script>
{%- endif -%}
{% endblock %}
flask_admin/templates/bootstrap3/admin/file/form.html
View file @
66874b8d
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
<h3>
{{ header_text }}
</h3>
</div>
<div
class=
"modal-body"
>
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
</div>
{%- else -%}
<h3>
{{ header_text }}
</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fixes "remote modal shows same content every time", avoiding the flicker
$
(
'body'
).
on
(
'hidden.bs.modal'
,
'.modal'
,
function
()
{
$
(
this
).
removeData
(
'bs.modal'
).
find
(
".modal-content"
).
empty
();
});
</script>
{%- endif -%}
{% block header %}
<h3>
{{ header_text }}
</h3>
{% endblock %}
{{ lib.render_form(form, dir_url) }}
{% endblock %}
flask_admin/templates/bootstrap3/admin/file/modals/form.html
0 → 100644
View file @
66874b8d
{% import 'admin/static.html' as admin_static with context %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{# content added to modal-content #}
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
{% block header %}
<h3>
{{ header_text }}
</h3>
{% endblock %}
</div>
<div
class=
"modal-body"
>
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
</div>
{% endblock %}
{% block tail %}
<script
src=
"{{ admin_static.url(filename='admin/js/bs3_modal.js', v='1.0.0') }}"
></script>
{% endblock %}
flask_admin/templates/bootstrap3/admin/file/rename.html
deleted
100644 → 0
View file @
4c0bf96c
{%- if not modal -%}
{% extends 'admin/master.html' %}
{%- endif -%}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{%- if modal -%}
{# content added to modal-content #}
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
{% block header_text %}
<h3>
{{ _gettext('Rename %(name)s', name=name) }}
</h3>
{% endblock %}
</div>
<div
class=
"modal-body"
>
{{ lib.render_form(form, dir_url, action=request.url, is_modal=True) }}
</div>
{%- else -%}
<h3>
{{ self.header_text() }}
</h3>
{{ lib.render_form(form, dir_url) }}
{%- endif -%}
{% endblock %}
{% block tail %}
{%- if modal -%}
<script>
// fixes "remote modal shows same content every time", avoiding the flicker
$
(
'body'
).
on
(
'hidden.bs.modal'
,
'.modal'
,
function
()
{
$
(
this
).
removeData
(
'bs.modal'
).
find
(
".modal-content"
).
empty
();
});
</script>
{%- endif -%}
{% endblock %}
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