Commit f8d1b965 authored by Paul Brown's avatar Paul Brown

implement 3 buttons on edit and create, minor ui changes

parent 5ed6dccf
......@@ -1658,13 +1658,16 @@ class BaseModelView(BaseView, ActionsMixin):
flash(gettext('Record was successfully created.'))
if '_add_another' in request.form:
return redirect(request.url)
else:
elif '_continue_editing' in request.form:
# if we have a valid model, try to go to the edit view
if model is not True:
url = self.get_url('.edit_view', id=self.get_pk_value(model), url=return_url)
else:
url = return_url
return redirect(url)
else:
# save button
return redirect(return_url)
form_opts = FormOpts(widget_args=self.form_widget_args,
form_rules=self._form_create_rules)
......@@ -1706,9 +1709,12 @@ class BaseModelView(BaseView, ActionsMixin):
if self.validate_form(form):
if self.update_model(form, model):
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)
else:
# save button
return redirect(return_url)
if request.method == 'GET':
......
......@@ -194,14 +194,15 @@
{% endmacro %}
{% 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">
<input type="submit" class="btn btn-primary btn-large" value="{{ _gettext('Save') }}" />
<input type="submit" class="btn btn-primary" value="{{ _gettext('Save') }}" />
{% if extra %}
{{ extra }}
{% endif %}
{% 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 %}
</div>
</div>
......
......@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% 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 %}
{% block head %}
......@@ -22,7 +23,7 @@
</ul>
{% 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 %}
{% block tail %}
......
......@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% 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 %}
{% block head %}
......@@ -26,13 +27,13 @@
</li>
{%- if admin_view.can_view_details -%}
<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>
{%- endif -%}
</ul>
{% endblock %}
{{ lib.render_form(form, return_url, extra(), form_opts) }}
{{ lib.render_form(form, cancel_url=None, extra=extra(), form_opts=form_opts) }}
{% endblock %}
{% block tail %}
......
......@@ -2,7 +2,7 @@
{% import 'admin/lib.html' as lib with context %}
{% 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,
action=url_for('.create_view', url=return_url),
is_modal=True) }}
......
......@@ -186,7 +186,7 @@
{% macro render_form_buttons(cancel_url, extra=None, is_modal=False) %}
<hr>
<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') }}" />
{% if extra %}
{{ extra }}
......
......@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% 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 %}
{% block head %}
......@@ -22,7 +23,7 @@
</ul>
{% 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 %}
{% block tail %}
......
......@@ -2,7 +2,8 @@
{% import 'admin/lib.html' as lib with context %}
{% 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 %}
{% block head %}
......@@ -26,13 +27,13 @@
</li>
{%- if admin_view.can_view_details -%}
<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>
{%- endif -%}
</ul>
{% endblock %}
{{ lib.render_form(form, return_url, extra(), form_opts) }}
{{ lib.render_form(form, cancel_url=None, extra=extra(), form_opts=form_opts) }}
{% endblock %}
{% block tail %}
......
......@@ -7,7 +7,7 @@
{% block header_text %}<h3>{{ _gettext('Create New Record') }}</h3>{% endblock %}
</div>
<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,
action=url_for('.create_view', url=return_url),
is_modal=True) }}
......
......@@ -1824,7 +1824,8 @@ def test_safe_redirect():
client = app.test_client()
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)
assert_true(rv.location.startswith('http://localhost/admin/model1/edit/'))
......@@ -1832,7 +1833,8 @@ def test_safe_redirect():
assert_true('id=1' in rv.location)
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)
assert_true(rv.location.startswith('http://localhost/admin/model1/edit/'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment