Skip to content

Commit

Permalink
Revert "Merge branch 'Details-View-Like-Edit-and-Create-Views'"
Browse files Browse the repository at this point in the history
This reverts commit a6c4cea, reversing
changes made to 829fa65.
  • Loading branch information
mccarthysean committed Jul 11, 2022
1 parent 1fe9e04 commit 669c926
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 39 deletions.
3 changes: 0 additions & 3 deletions examples/forms-files-images/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ class UserView(sqla.ModelView):
"""
This class demonstrates the use of 'rules' for controlling the rendering of forms.
"""
can_view_details = True

form_create_rules = [
# Header and four fields. Email field will go above phone field.
rules.FieldSet(('first_name', 'last_name', 'email', 'phone', 'is_admin'), 'Personal'),
Expand Down Expand Up @@ -208,7 +206,6 @@ class UserView(sqla.ModelView):

create_template = 'create_user.html'
edit_template = 'edit_user.html'
details_template = 'details_user.html'

column_descriptions = {
"is_admin": "Is this an admin user?",
Expand Down
2 changes: 0 additions & 2 deletions examples/forms-files-images/templates/details_user.html

This file was deleted.

21 changes: 1 addition & 20 deletions flask_admin/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2169,8 +2169,7 @@ def edit_view(self):
@expose('/details/')
def details_view(self):
"""
Details model view, which looks like the "create" and "edit" views,
but with read-only fields.
Details model view
"""
return_url = get_redirect_target() or self.get_url('.index_view')

Expand All @@ -2187,31 +2186,13 @@ def details_view(self):
flash(gettext('Record does not exist.'), 'error')
return redirect(return_url)

# Send the form to the template, same as the "edit" view
form = self.edit_form(obj=model)
if not hasattr(form, '_validated_ruleset') or not form._validated_ruleset:
self._validate_form_instance(ruleset=self._form_edit_rules, form=form)

self.on_form_prefill(form, id)

# Make the input fields "read-only" since this isn't the "edit" view
widget_args = {}
for field in self._form_edit_rules.visible_fields:
widget_args[field] = self.form_widget_args.get(field, {})
widget_args[field]['readonly'] = True

form_opts = FormOpts(widget_args=widget_args,
form_rules=self._form_edit_rules)

if self.details_modal and request.args.get('modal'):
template = self.details_modal_template
else:
template = self.details_template

return self.render(template,
model=model,
form=form,
form_opts=form_opts,
details_columns=self._details_columns,
get_value=self.get_detail_value,
return_url=return_url)
Expand Down
7 changes: 2 additions & 5 deletions flask_admin/templates/bootstrap4/admin/lib.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,10 @@ <h3>{{ text }}</h3>
{% endif %}
{% endmacro %}

{% macro render_form(form, cancel_url, extra=None, form_opts=None, action=None, is_modal=False, render_buttons=True) -%}
{% macro render_form(form, cancel_url, extra=None, form_opts=None, action=None, is_modal=False) -%}
{% call form_tag(action=action) %}
{{ render_form_fields(form, form_opts=form_opts) }}
{# The "details" view doesn't need or want "Save" and "Cancel" buttons #}
{% if render_buttons %}
{{ render_form_buttons(cancel_url, extra, is_modal) }}
{% endif %}
{{ render_form_buttons(cancel_url, extra, is_modal) }}
{% endcall %}
{% endmacro %}

Expand Down
30 changes: 21 additions & 9 deletions flask_admin/templates/bootstrap4/admin/model/details.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib with context %}
{% from 'admin/lib.html' import extra with context %} {# backward compatible #}

{% block head %}
{{ super() }}
{{ lib.form_css() }}
{% endblock %}

{% block body %}
{% block navlinks %}
Expand All @@ -29,12 +23,30 @@
</ul>
{% endblock %}

{% block edit_form %}
{{ lib.render_form(form, return_url, extra=None, form_opts=form_opts, render_buttons=False, input_disable=True) }}
{% block details_search %}
<div class="form-inline fa_filter_container col-lg-6">
<label for="fa_filter">{{ _gettext('Filter') }}</label>
<input id="fa_filter" type="text" class="ml-3 form-control">
</div>
{% endblock %}

{% block details_table %}
<table class="table table-hover table-bordered searchable">
{% for c, name in details_columns %}
<tr>
<td>
<b>{{ name }}</b>
</td>
<td>
{{ get_value(model, c) }}
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
{% endblock %}

{% block tail %}
{{ super() }}
{{ lib.form_js() }}
<script src="{{ admin_static.url(filename='admin/js/details_filter.js', v='1.0.0') }}"></script>
{% endblock %}

0 comments on commit 669c926

Please sign in to comment.