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
f8d1b965
Commit
f8d1b965
authored
Aug 14, 2015
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement 3 buttons on edit and create, minor ui changes
parent
5ed6dccf
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
33 additions
and
20 deletions
+33
-20
base.py
flask_admin/model/base.py
+8
-2
lib.html
flask_admin/templates/bootstrap2/admin/lib.html
+4
-3
create.html
flask_admin/templates/bootstrap2/admin/model/create.html
+3
-2
edit.html
flask_admin/templates/bootstrap2/admin/model/edit.html
+4
-3
create.html
...admin/templates/bootstrap2/admin/model/modals/create.html
+1
-1
lib.html
flask_admin/templates/bootstrap3/admin/lib.html
+1
-1
create.html
flask_admin/templates/bootstrap3/admin/model/create.html
+3
-2
edit.html
flask_admin/templates/bootstrap3/admin/model/edit.html
+4
-3
create.html
...admin/templates/bootstrap3/admin/model/modals/create.html
+1
-1
test_basic.py
flask_admin/tests/sqla/test_basic.py
+4
-2
No files found.
flask_admin/model/base.py
View file @
f8d1b965
...
@@ -1658,13 +1658,16 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -1658,13 +1658,16 @@ class BaseModelView(BaseView, ActionsMixin):
flash
(
gettext
(
'Record was successfully created.'
))
flash
(
gettext
(
'Record was successfully created.'
))
if
'_add_another'
in
request
.
form
:
if
'_add_another'
in
request
.
form
:
return
redirect
(
request
.
url
)
return
redirect
(
request
.
url
)
el
se
:
el
if
'_continue_editing'
in
request
.
form
:
# if we have a valid model, try to go to the edit view
# if we have a valid model, try to go to the edit view
if
model
is
not
True
:
if
model
is
not
True
:
url
=
self
.
get_url
(
'.edit_view'
,
id
=
self
.
get_pk_value
(
model
),
url
=
return_url
)
url
=
self
.
get_url
(
'.edit_view'
,
id
=
self
.
get_pk_value
(
model
),
url
=
return_url
)
else
:
else
:
url
=
return_url
url
=
return_url
return
redirect
(
url
)
return
redirect
(
url
)
else
:
# save button
return
redirect
(
return_url
)
form_opts
=
FormOpts
(
widget_args
=
self
.
form_widget_args
,
form_opts
=
FormOpts
(
widget_args
=
self
.
form_widget_args
,
form_rules
=
self
.
_form_create_rules
)
form_rules
=
self
.
_form_create_rules
)
...
@@ -1706,9 +1709,12 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -1706,9 +1709,12 @@ class BaseModelView(BaseView, ActionsMixin):
if
self
.
validate_form
(
form
):
if
self
.
validate_form
(
form
):
if
self
.
update_model
(
form
,
model
):
if
self
.
update_model
(
form
,
model
):
flash
(
gettext
(
'Record was successfully saved.'
))
flash
(
gettext
(
'Record was successfully saved.'
))
if
'_continue_editing'
in
request
.
form
:
if
'_add_another'
in
request
.
form
:
return
redirect
(
self
.
get_url
(
'.create_view'
,
url
=
return_url
))
elif
'_continue_editing'
in
request
.
form
:
return
redirect
(
request
.
url
)
return
redirect
(
request
.
url
)
else
:
else
:
# save button
return
redirect
(
return_url
)
return
redirect
(
return_url
)
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
...
...
flask_admin/templates/bootstrap2/admin/lib.html
View file @
f8d1b965
...
@@ -194,14 +194,15 @@
...
@@ -194,14 +194,15 @@
{% endmacro %}
{% endmacro %}
{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %}
{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %}
<div
class=
"control-group"
>
<hr>
<div
class=
"control-group pull-right"
>
<div
class=
"controls"
>
<div
class=
"controls"
>
<input
type=
"submit"
class=
"btn btn-primary
btn-large
"
value=
"{{ _gettext('Save') }}"
/>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"{{ _gettext('Save') }}"
/>
{% if extra %}
{% if extra %}
{{ extra }}
{{ extra }}
{% endif %}
{% endif %}
{% if cancel_url %}
{% if cancel_url %}
<a
href=
"{{ cancel_url }}"
class=
"btn btn-
large btn-
danger"
{%
if
is_modal
%}
data-dismiss=
"modal"
{%
endif
%}
>
{{ _gettext('Cancel') }}
</a>
<a
href=
"{{ cancel_url }}"
class=
"btn btn-danger"
{%
if
is_modal
%}
data-dismiss=
"modal"
{%
endif
%}
>
{{ _gettext('Cancel') }}
</a>
{% endif %}
{% endif %}
</div>
</div>
</div>
</div>
...
...
flask_admin/templates/bootstrap2/admin/model/create.html
View file @
f8d1b965
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/lib.html' as lib with context %}
{% macro extra() %}
{% macro extra() %}
<input
name=
"_add_another"
type=
"submit"
class=
"btn btn-large"
value=
"{{ _gettext('Save and Add') }}"
/>
<input
name=
"_add_another"
type=
"submit"
class=
"btn"
value=
"{{ _gettext('Save and Add Another') }}"
/>
<input
name=
"_continue_editing"
type=
"submit"
class=
"btn"
value=
"{{ _gettext('Save and Continue Editing') }}"
/>
{% endmacro %}
{% endmacro %}
{% block head %}
{% block head %}
...
@@ -22,7 +23,7 @@
...
@@ -22,7 +23,7 @@
</ul>
</ul>
{% endblock %}
{% endblock %}
{{ lib.render_form(form,
return_url,
extra(), form_opts=form_opts) }}
{{ lib.render_form(form,
cancel_url=None, extra=
extra(), form_opts=form_opts) }}
{% endblock %}
{% endblock %}
{% block tail %}
{% block tail %}
...
...
flask_admin/templates/bootstrap2/admin/model/edit.html
View file @
f8d1b965
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/lib.html' as lib with context %}
{% macro extra() %}
{% macro extra() %}
<input
name=
"_continue_editing"
type=
"submit"
class=
"btn btn-large"
value=
"{{ _gettext('Save and Continue') }}"
/>
<input
name=
"_add_another"
type=
"submit"
class=
"btn"
value=
"{{ _gettext('Save and Add Another') }}"
/>
<input
name=
"_continue_editing"
type=
"submit"
class=
"btn"
value=
"{{ _gettext('Save and Continue Editing') }}"
/>
{% endmacro %}
{% endmacro %}
{% block head %}
{% block head %}
...
@@ -26,13 +27,13 @@
...
@@ -26,13 +27,13 @@
</li>
</li>
{%- if admin_view.can_view_details -%}
{%- if admin_view.can_view_details -%}
<li>
<li>
<a
href=
"{{ get_url('.details_view', id=model.id, url=return_url) }}"
>
{{ _gettext('
View Record
') }}
</a>
<a
href=
"{{ get_url('.details_view', id=model.id, url=return_url) }}"
>
{{ _gettext('
Details
') }}
</a>
</li>
</li>
{%- endif -%}
{%- endif -%}
</ul>
</ul>
{% endblock %}
{% endblock %}
{{ lib.render_form(form,
return_url, extra(),
form_opts) }}
{{ lib.render_form(form,
cancel_url=None, extra=extra(), form_opts=
form_opts) }}
{% endblock %}
{% endblock %}
{% block tail %}
{% block tail %}
...
...
flask_admin/templates/bootstrap2/admin/model/modals/create.html
View file @
f8d1b965
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/lib.html' as lib with context %}
{% block body %}
{% block body %}
{# "save and
continue
" button is removed from modal (it won't function properly) #}
{# "save and
add
" button is removed from modal (it won't function properly) #}
{{ lib.render_form(form, return_url, extra=None, form_opts=form_opts,
{{ lib.render_form(form, return_url, extra=None, form_opts=form_opts,
action=url_for('.create_view', url=return_url),
action=url_for('.create_view', url=return_url),
is_modal=True) }}
is_modal=True) }}
...
...
flask_admin/templates/bootstrap3/admin/lib.html
View file @
f8d1b965
...
@@ -186,7 +186,7 @@
...
@@ -186,7 +186,7 @@
{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %}
{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %}
<hr>
<hr>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-md-offset-2 col-md-10 submit-row"
>
<div
class=
"col-md-offset-2 col-md-10 submit-row
text-right
"
>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"{{ _gettext('Save') }}"
/>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"{{ _gettext('Save') }}"
/>
{% if extra %}
{% if extra %}
{{ extra }}
{{ extra }}
...
...
flask_admin/templates/bootstrap3/admin/model/create.html
View file @
f8d1b965
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/lib.html' as lib with context %}
{% macro extra() %}
{% macro extra() %}
<input
name=
"_add_another"
type=
"submit"
class=
"btn btn-default"
value=
"{{ _gettext('Save and Add') }}"
/>
<input
name=
"_add_another"
type=
"submit"
class=
"btn btn-default"
value=
"{{ _gettext('Save and Add Another') }}"
/>
<input
name=
"_continue_editing"
type=
"submit"
class=
"btn btn-default"
value=
"{{ _gettext('Save and Continue Editing') }}"
/>
{% endmacro %}
{% endmacro %}
{% block head %}
{% block head %}
...
@@ -22,7 +23,7 @@
...
@@ -22,7 +23,7 @@
</ul>
</ul>
{% endblock %}
{% endblock %}
{{ lib.render_form(form,
return_url,
extra(), form_opts=form_opts) }}
{{ lib.render_form(form,
cancel_url=None, extra=
extra(), form_opts=form_opts) }}
{% endblock %}
{% endblock %}
{% block tail %}
{% block tail %}
...
...
flask_admin/templates/bootstrap3/admin/model/edit.html
View file @
f8d1b965
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% import 'admin/lib.html' as lib with context %}
{% macro extra() %}
{% macro extra() %}
<input
name=
"_continue_editing"
type=
"submit"
class=
"btn btn-default"
value=
"{{ _gettext('Save and Continue') }}"
/>
<input
name=
"_add_another"
type=
"submit"
class=
"btn btn-default"
value=
"{{ _gettext('Save and Add Another') }}"
/>
<input
name=
"_continue_editing"
type=
"submit"
class=
"btn btn-default"
value=
"{{ _gettext('Save and Continue Editing') }}"
/>
{% endmacro %}
{% endmacro %}
{% block head %}
{% block head %}
...
@@ -26,13 +27,13 @@
...
@@ -26,13 +27,13 @@
</li>
</li>
{%- if admin_view.can_view_details -%}
{%- if admin_view.can_view_details -%}
<li>
<li>
<a
href=
"{{ get_url('.details_view', id=model.id, url=return_url) }}"
>
{{ _gettext('
View Record
') }}
</a>
<a
href=
"{{ get_url('.details_view', id=model.id, url=return_url) }}"
>
{{ _gettext('
Details
') }}
</a>
</li>
</li>
{%- endif -%}
{%- endif -%}
</ul>
</ul>
{% endblock %}
{% endblock %}
{{ lib.render_form(form,
return_url, extra(),
form_opts) }}
{{ lib.render_form(form,
cancel_url=None, extra=extra(), form_opts=
form_opts) }}
{% endblock %}
{% endblock %}
{% block tail %}
{% block tail %}
...
...
flask_admin/templates/bootstrap3/admin/model/modals/create.html
View file @
f8d1b965
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
{% block header_text %}
<h3>
{{ _gettext('Create New Record') }}
</h3>
{% endblock %}
{% block header_text %}
<h3>
{{ _gettext('Create New Record') }}
</h3>
{% endblock %}
</div>
</div>
<div
class=
"modal-body"
>
<div
class=
"modal-body"
>
{# "save and
continue
" button is removed from modal (it won't function properly) #}
{# "save and
add
" button is removed from modal (it won't function properly) #}
{{ lib.render_form(form, return_url, extra=None, form_opts=form_opts,
{{ lib.render_form(form, return_url, extra=None, form_opts=form_opts,
action=url_for('.create_view', url=return_url),
action=url_for('.create_view', url=return_url),
is_modal=True) }}
is_modal=True) }}
...
...
flask_admin/tests/sqla/test_basic.py
View file @
f8d1b965
...
@@ -1824,7 +1824,8 @@ def test_safe_redirect():
...
@@ -1824,7 +1824,8 @@ def test_safe_redirect():
client
=
app
.
test_client
()
client
=
app
.
test_client
()
rv
=
client
.
post
(
'/admin/model1/new/?url=http://localhost/admin/model2view/'
,
rv
=
client
.
post
(
'/admin/model1/new/?url=http://localhost/admin/model2view/'
,
data
=
dict
(
test1
=
'test1large'
,
test2
=
'test2'
))
data
=
dict
(
test1
=
'test1large'
,
test2
=
'test2'
,
_continue_editing
=
'Save and Continue Editing'
))
eq_
(
rv
.
status_code
,
302
)
eq_
(
rv
.
status_code
,
302
)
assert_true
(
rv
.
location
.
startswith
(
'http://localhost/admin/model1/edit/'
))
assert_true
(
rv
.
location
.
startswith
(
'http://localhost/admin/model1/edit/'
))
...
@@ -1832,7 +1833,8 @@ def test_safe_redirect():
...
@@ -1832,7 +1833,8 @@ def test_safe_redirect():
assert_true
(
'id=1'
in
rv
.
location
)
assert_true
(
'id=1'
in
rv
.
location
)
rv
=
client
.
post
(
'/admin/model1/new/?url=http://google.com/evil/'
,
rv
=
client
.
post
(
'/admin/model1/new/?url=http://google.com/evil/'
,
data
=
dict
(
test1
=
'test1large'
,
test2
=
'test2'
))
data
=
dict
(
test1
=
'test1large'
,
test2
=
'test2'
,
_continue_editing
=
'Save and Continue Editing'
))
eq_
(
rv
.
status_code
,
302
)
eq_
(
rv
.
status_code
,
302
)
assert_true
(
rv
.
location
.
startswith
(
'http://localhost/admin/model1/edit/'
))
assert_true
(
rv
.
location
.
startswith
(
'http://localhost/admin/model1/edit/'
))
...
...
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