From b208a9cb537fb047f55c7187003d268b7e880001 Mon Sep 17 00:00:00 2001 From: Sean McCarthy Date: Wed, 15 Jun 2022 16:26:55 -0600 Subject: [PATCH] Revert "Merge branch 'Details-View-Like-Edit-and-Create-Views'" This reverts commit a6c4cea8b5fd60e800308d0a50ff3c84fdf5a267, reversing changes made to 829fa65c6ab8c577cd79d3389a25b6fffbdb70ef. --- examples/forms-files-images/app.py | 3 -- .../templates/details_user.html | 2 -- flask_admin/model/base.py | 21 +------------ .../templates/bootstrap4/admin/lib.html | 7 ++--- .../bootstrap4/admin/model/details.html | 30 +++++++++++++------ 5 files changed, 24 insertions(+), 39 deletions(-) delete mode 100644 examples/forms-files-images/templates/details_user.html diff --git a/examples/forms-files-images/app.py b/examples/forms-files-images/app.py index f762f6c001..e771cadd94 100644 --- a/examples/forms-files-images/app.py +++ b/examples/forms-files-images/app.py @@ -171,8 +171,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'), 'Personal'), @@ -207,7 +205,6 @@ class UserView(sqla.ModelView): create_template = 'create_user.html' edit_template = 'edit_user.html' - details_template = 'details_user.html' # Flask views diff --git a/examples/forms-files-images/templates/details_user.html b/examples/forms-files-images/templates/details_user.html deleted file mode 100644 index 9290ef777c..0000000000 --- a/examples/forms-files-images/templates/details_user.html +++ /dev/null @@ -1,2 +0,0 @@ -{% extends 'admin/model/details.html' %} -{% import 'macros.html' as rule_demo %} diff --git a/flask_admin/model/base.py b/flask_admin/model/base.py index 14475eeea0..665e646808 100755 --- a/flask_admin/model/base.py +++ b/flask_admin/model/base.py @@ -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') @@ -2187,22 +2186,6 @@ 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: @@ -2210,8 +2193,6 @@ def details_view(self): 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) diff --git a/flask_admin/templates/bootstrap4/admin/lib.html b/flask_admin/templates/bootstrap4/admin/lib.html index 5b04ebf63c..d0c4605cf6 100644 --- a/flask_admin/templates/bootstrap4/admin/lib.html +++ b/flask_admin/templates/bootstrap4/admin/lib.html @@ -234,13 +234,10 @@

{{ text }}

{% 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 %} diff --git a/flask_admin/templates/bootstrap4/admin/model/details.html b/flask_admin/templates/bootstrap4/admin/model/details.html index 2c1f625880..f4017e3df0 100644 --- a/flask_admin/templates/bootstrap4/admin/model/details.html +++ b/flask_admin/templates/bootstrap4/admin/model/details.html @@ -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 %} @@ -29,12 +23,30 @@ {% 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 %} +
+ + +
+ {% endblock %} + + {% block details_table %} + + {% for c, name in details_columns %} + + + + + {% endfor %} +
+ {{ name }} + + {{ get_value(model, c) }} +
{% endblock %} {% endblock %} {% block tail %} {{ super() }} - {{ lib.form_js() }} + {% endblock %}