diff options
author | 2024-01-15 13:10:25 -0800 | |
---|---|---|
committer | 2024-01-15 13:10:25 -0800 | |
commit | 6e44b64a1d16b48ced27144d666aeb1bd6f52dbb (patch) | |
tree | 97ede466b31cb7d700efee03c3eee5f538ec6029 | |
parent | glsamaker/templates: add some bootstrap/tyrian niceness (diff) | |
download | glsamaker-6e44b64a1d16b48ced27144d666aeb1bd6f52dbb.tar.gz glsamaker-6e44b64a1d16b48ced27144d666aeb1bd6f52dbb.tar.bz2 glsamaker-6e44b64a1d16b48ced27144d666aeb1bd6f52dbb.zip |
templates/edit_glsa: add user-visible error for invalid references
Signed-off-by: John Helmert III <ajak@gentoo.org>
-rw-r--r-- | glsamaker/templates/edit_glsa.html | 3 | ||||
-rw-r--r-- | glsamaker/views.py | 20 |
2 files changed, 21 insertions, 2 deletions
diff --git a/glsamaker/templates/edit_glsa.html b/glsamaker/templates/edit_glsa.html index 915d4d1..165cef8 100644 --- a/glsamaker/templates/edit_glsa.html +++ b/glsamaker/templates/edit_glsa.html @@ -136,6 +136,9 @@ <tr> <td>References</td> <td>{{ form.references(size=50) }}</td> + {% for error in form.references.errors %} + <p style="color: red;">{{ error }}</span> + {% endfor %} </tr> <tr> <td>Requester</td> diff --git a/glsamaker/views.py b/glsamaker/views.py index b8a1a65..f1f63d9 100644 --- a/glsamaker/views.py +++ b/glsamaker/views.py @@ -1,3 +1,7 @@ +from __future__ import ( # needed to reference class types from within the class + annotations, +) + import uuid from datetime import date, datetime from logging.config import dictConfig @@ -18,10 +22,10 @@ from wtforms import ( SubmitField, TextAreaField, ) -from wtforms.validators import DataRequired +from wtforms.validators import DataRequired, ValidationError from glsamaker.app import bgo -from glsamaker.autoglsa import NoAtomInSummary, autogenerate_glsa, bugs_aliases +from glsamaker.autoglsa import autogenerate_glsa, bugs_aliases from glsamaker.extensions import db, login_manager from glsamaker.models.bug import Bug from glsamaker.models.glsa import GLSA @@ -77,6 +81,18 @@ class GLSAForm(FlaskForm): ack = BooleanField("Ack") submit = SubmitField("Submit") + @classmethod + def validate_references(cls, form: GLSAForm, field: StringField): + message = "Invalid references: {}" + references = [ref.strip() for ref in field.data.split(",")] + invalid_references = list( + filter(lambda x: not Reference.valid_reference(x), references) + ) + if invalid_references: + message = message.format(", ".join(invalid_references)) + app.logger.info(message) + raise ValidationError(message) + class BugForm(FlaskForm): bugs = StringField("Bugs") |