Skip to content

Commit

Permalink
add generic form-view.html and grid-view.html templates
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofgentoo committed Dec 6, 2022
1 parent 57fc4ab commit 1eb8db2
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 31 deletions.
28 changes: 28 additions & 0 deletions docs/source/getting-started.rst
Expand Up @@ -110,3 +110,31 @@ The desired workflow here is to run tox, update strings in the PO files as neces
.. code::
tox -e i18n
Upgrade Notes
=============

While we attempt to preserve backward compatibility, some KegElements versions do introduce
breaking changes. This list should provide information on needed app changes.

- 0.8.0
- ``pytest`` removed support for nose-style methods, so base test classes (e.g. ``EntityBase``)
now use ``setup_method`` instead of ``setup``
- Bootstrap 4 "horizontal" form templates had been broken and were displaying forms in the
vertical style instead. This has been resolved, which means forms will change to showing with
horizontal layout. If this is not desired, you will need to override the form templates/macros.
- Template files now follow keg's more recent naming scheme to use dashes instead of underscores.
E.g. ``keg_elements/forms/horizontal_b4.html`` became ``keg-elements/forms/horizontal-b4.html``
- The older Bootstrap 3 macro template (``horizontal.html``) has been renamed for
namespacing to ``horizontal-b3.html``.
- ``keg-elements/form-view.html`` and ``keg-elements/grid-view.html`` are now available, but
need a config value (either ``BASE_TEMPLATE`` or ``KEG_BASE_TEMPLATE``) set to represent the
parent to extend.
- forms now have an ident field built-in to assist in identifying the form from POSTed data.
If a form's render is customized in the template layer, the ident field may be missing. A few
options for moving forward:

- add the field in render (identified by the result of the form's ``_form_ident_key`` method)
- turn off ident validation by setting ``_form_ident_strict`` to ``False`` on the form class
- turn off the field by setting ``_form_ident_enabled`` to ``False`` on the form class
37 changes: 37 additions & 0 deletions keg_elements/templates/keg-elements/form-view.html
@@ -0,0 +1,37 @@
{% if is_read_only %}
{% import 'keg-elements/forms/horizontal-static.html' as horizontal %}
{% else %}
{% import 'keg-elements/forms/horizontal-b4.html' as horizontal %}
{% endif %}

{% set base_template = config.get('BASE_TEMPLATE') or config.get('KEG_BASE_TEMPLATE') %}
{% if base_template %}
{% extends base_template %}
{% endif %}

{% if use_select2 is not defined %}
{% set use_select2 = config.get('KEG_USE_SELECT2', True) %}
{% endif %}

{% block scripts %}
{{ super() }}
{% if use_select2 %}
{% include 'keg-elements/forms/select2-scripts.html' %}
{% endif %}
{{ horizontal.custom_js() }}
{% endblock %}

{% block styles %}
{{ super() }}
{% if use_select2 %}
{% include 'keg-elements/forms/select2-styles.html' %}
{% endif %}
{{ horizontal.custom_css() }}
{% endblock %}

{% block page_content %}
{% block page_content_title %}
<h1>{{ title }}</h1>
{% endblock %}
{% block form %}{% endblock %}
{% endblock %}
Expand Up @@ -336,6 +336,6 @@ <h2>{{heading}}</h2>

{% macro datetime_helper() -%}
<script type="text/javascript">
{% include "keg_elements/forms/datetime_helper.js" %}
{% include "keg-elements/forms/datetime-helper.js" %}
</script>
{%- endmacro %}
Expand Up @@ -21,6 +21,11 @@
</div>
{%- endmacro %}

{% macro custom_css() %}
{% endmacro %}

{% macro custom_js() %}
{% endmacro %}

{% macro identity(value) %}{{ value }}{% endmacro %}

Expand Down
@@ -0,0 +1,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.min.js"></script>
<script>
$(document).ready(function() {
$('form select').select2();
});
</script>
@@ -0,0 +1 @@
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" rel="stylesheet" />
38 changes: 38 additions & 0 deletions keg_elements/templates/keg-elements/grid-view.html
@@ -0,0 +1,38 @@
{% set base_template = config.get('BASE_TEMPLATE') or config.get('KEG_BASE_TEMPLATE') %}
{% if base_template %}
{% extends base_template %}
{% endif %}

{% macro grid_scripts() %}
<script src="{{ url_for('webgrid.static', filename='webgrid.js') }}"></script>
<script src="{{ url_for('webgrid.static', filename='jquery.multiple.select.js') }}"></script>
{% endmacro %}

{% block page_content %}
{% block page_content_title %}
<h1>{{ title }}</h1>
{% endblock %}

{% block pre_grid %}{% endblock %}

<section id="grid-body">
<div class="preamble">
{% block preamble %}
{% endblock %}
</div>
{{ grid.html() | safe}}
</section>

{% block post_grid %}{% endblock %}

{% if not base_template %}
{{ grid_scripts() }}
{% endif %}
{% endblock %}

{% block scripts %}
{% if base_template %}
{{ super() }}
{{ grid_scripts() }}
{% endif %}
{% endblock %}
4 changes: 2 additions & 2 deletions keg_elements/views.py
Expand Up @@ -72,8 +72,8 @@ class GridMixin:
"""Mixin supporting simple grid view setup"""
grid_cls = None
"""Grid class to construct, or callable returning a grid instance."""
template = 'grid-view.html'
"""Template to render. Defaults to grid-view.html, but this is not provided by keg_elements."""
template = 'keg-elements/grid-view.html'
"""Template to render. Defaults to keg-elements/grid-view.html"""
title = None
"""Page title, will be assigned as title for the template."""

Expand Down
6 changes: 3 additions & 3 deletions kegel_app/templates/field-macros.html
@@ -1,6 +1,6 @@
{% import 'keg_elements/forms/horizontal.html' as dynamic_render %}
{% import 'keg_elements/forms/horizontal_b4.html' as b4_render %}
{% import 'keg_elements/forms/horizontal_static.html' as static_render %}
{% import 'keg-elements/forms/horizontal-b3.html' as dynamic_render %}
{% import 'keg-elements/forms/horizontal-b4.html' as b4_render %}
{% import 'keg-elements/forms/horizontal-static.html' as static_render %}

{%- if _ is not defined -%}
{% macro _(message) -%}
Expand Down
6 changes: 3 additions & 3 deletions kegel_app/templates/form-field-value-macro.html
@@ -1,6 +1,6 @@
{% import 'keg_elements/forms/horizontal.html' as dynamic_render %}
{% import 'keg_elements/forms/horizontal_b4.html' as b4_render %}
{% import 'keg_elements/forms/horizontal_static.html' as static_render %}
{% import 'keg-elements/forms/horizontal-b3.html' as dynamic_render %}
{% import 'keg-elements/forms/horizontal-b4.html' as b4_render %}
{% import 'keg-elements/forms/horizontal-static.html' as static_render %}

{%- macro doubled(value) -%}
{{ value }}{{ value }}
Expand Down
6 changes: 3 additions & 3 deletions kegel_app/templates/generic-form.html
@@ -1,6 +1,6 @@
{% import 'keg_elements/forms/horizontal.html' as dynamic_render %}
{% import 'keg_elements/forms/horizontal_b4.html' as b4_render %}
{% import 'keg_elements/forms/horizontal_static.html' as static_render %}
{% import 'keg-elements/forms/horizontal-b3.html' as dynamic_render %}
{% import 'keg-elements/forms/horizontal-b4.html' as b4_render %}
{% import 'keg-elements/forms/horizontal-static.html' as static_render %}

<div id="dynamic">
{{ dynamic_render.form(form) }}
Expand Down
4 changes: 2 additions & 2 deletions kegel_app/templates/generic-input-field.html
@@ -1,5 +1,5 @@
{% import 'keg_elements/forms/horizontal.html' as dynamic_render %}
{% import 'keg_elements/forms/horizontal_static.html' as static_render %}
{% import 'keg-elements/forms/horizontal-b3.html' as dynamic_render %}
{% import 'keg-elements/forms/horizontal-static.html' as static_render %}

<div id="dynamic">
{{ dynamic_render.field(form[field_name]) }}
Expand Down
4 changes: 2 additions & 2 deletions kegel_app/templates/generic-radio-field.html
@@ -1,5 +1,5 @@
{% import 'keg_elements/forms/horizontal.html' as dynamic_render %}
{% import 'keg_elements/forms/horizontal_static.html' as static_render %}
{% import 'keg-elements/forms/horizontal-b3.html' as dynamic_render %}
{% import 'keg-elements/forms/horizontal-static.html' as static_render %}

<div id="dynamic">
{{ dynamic_render.radio_field(form[field_name]) }}
Expand Down
11 changes: 0 additions & 11 deletions kegel_app/templates/grid-view.html

This file was deleted.

2 changes: 1 addition & 1 deletion kegel_app/templates/keg_element/demo-form.html
@@ -1,4 +1,4 @@
{% import 'keg_elements/forms/horizontal_b4.html' as horizontal %}
{% import 'keg-elements/forms/horizontal-b4.html' as horizontal %}

{% block main %}
<h1>{{ title }}</h1>
Expand Down
6 changes: 3 additions & 3 deletions kegel_app/templates/section-macro.html
@@ -1,6 +1,6 @@
{% import 'keg_elements/forms/horizontal.html' as dynamic_render %}
{% import 'keg_elements/forms/horizontal_b4.html' as b4_render %}
{% import 'keg_elements/forms/horizontal_static.html' as static_render %}
{% import 'keg-elements/forms/horizontal-b3.html' as dynamic_render %}
{% import 'keg-elements/forms/horizontal-b4.html' as b4_render %}
{% import 'keg-elements/forms/horizontal-static.html' as static_render %}

{%- if _ is not defined -%}
{% macro _(message) -%}
Expand Down

0 comments on commit 1eb8db2

Please sign in to comment.