Mercurial > farol
changeset 126:e0830bcab004
Add (optional) regex matching to our input fields
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Thu, 23 Oct 2014 16:32:33 +0200 |
parents | 67c4b299736e |
children | d49c1ee6bc07 |
files | farol/templates/document/edit_revision.j2 farol/templates/document/edit_tracking.j2 farol/templates/macros.j2 |
diffstat | 3 files changed, 4 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/farol/templates/document/edit_revision.j2 Thu Oct 23 16:18:30 2014 +0200 +++ b/farol/templates/document/edit_revision.j2 Thu Oct 23 16:32:33 2014 +0200 @@ -30,7 +30,7 @@ {% block content %} <p><strong>Revision</strong> contains all the elements required to track the evolution of a CVRF document. Each change to a CVRF document should be accompanied by <strong>Number</strong>, <strong>Date</strong>, and <strong>Description</strong> elements.</p> <form role="form" method="POST"> - {% call textinput("number", "Number", "a.b.c.d", number, required=True) %} + {% call textinput("number", "Number", "a.b.c.d", number, required=True, regex='(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*)){0,3}') %} <p><strong>Number</strong> should contain the numeric version of the document. Like the <strong>Version</strong> element above, it is a numeric tokenized field of the format “nn” with up to four fields “nn.nn.nn.nn”. It is recommended that this be a monotonically increasing value. Minor revisions should be used for less-significant changes (for example, <samp>1.0.0.0</samp> to <samp>1.0.0.1</samp>). Major, actionable changes should lead to a major increase of the version number (for example, <samp>1.0</samp> to <samp>2.0</samp>).</p> <p>Examples of such changes include:</p> <ul>
--- a/farol/templates/document/edit_tracking.j2 Thu Oct 23 16:18:30 2014 +0200 +++ b/farol/templates/document/edit_tracking.j2 Thu Oct 23 16:32:33 2014 +0200 @@ -52,7 +52,7 @@ </dl> <p>Issuing parties are strongly recommended to set <strong>Status</strong> to <samp>Draft</samp> when initiating a new document and to implement procedures to ensure that the status is changed to the appropriate value before the document is released.</p> {% endcall %} -{% call textinput("version", "Version", value=version, required=True) %} +{% call textinput("version", "Version", value=version, required=True, regex='(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*)){0,3}') %} <p>Version is a simple counter to track the version of the document. This is a numeric tokenized field of the format “nn” – “nn.nn.nn.nn”. It may be incremented in either major or minor notation to denote clearly the evolution of the content of the document. Issuing parties must ensure that this field is incremented appropriately, even for the least editorial or grammatical changes, when the field is used. It is validated using the following regular expression: <code>(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*)){0,3}</code>.</p> {{ examples(['1.0', '1.0.1', '1.0.0.1']) }} {% endcall %}
--- a/farol/templates/macros.j2 Thu Oct 23 16:18:30 2014 +0200 +++ b/farol/templates/macros.j2 Thu Oct 23 16:32:33 2014 +0200 @@ -23,7 +23,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -#} -{% macro textinput(name, label, placeholder="", value=None, required=False, type="text", extras={}, help='') %} +{% macro textinput(name, label, placeholder="", value=None, required=False, type="text", extras={}, help='', regex=None) %} <div class="form-group"> {% if caller %} {% set content=caller () %} @@ -42,6 +42,7 @@ id="{{ name }}" name="{{ name }}" {%- if placeholder %} placeholder="{{ placeholder }}"{% endif %} {%- if value %} value="{{ value }}"{% endif %} + {%- if regex %} pattern="{{ regex }}"{% endif %} {%- if required %} required{% endif %} {{- extras | xmlattr }}> {% if type == "datetime" %}