changeset 129:d2588d88d47a

Move parseVersion flashing one level higher
author Benoît Allard <benoit.allard@greenbone.net>
date Fri, 24 Oct 2014 10:52:04 +0200
parents 79abdecb2d0b
children 5b47af23547f
files farol/controller.py farol/document.py
diffstat 2 files changed, 7 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/farol/controller.py	Thu Oct 23 16:57:36 2014 +0200
+++ b/farol/controller.py	Fri Oct 24 10:52:04 2014 +0200
@@ -35,7 +35,7 @@
 except ImportError:
     from farolluz.py2 import FixedTimeZone as timezone
 
-from flask import request
+from flask import request, flash
 
 from farolluz.cvrf import CVRFNote, CVRFReference, CVRFAcknowledgment
 from farolluz.parsers.cvrf import parseDate as parseXMLDate, parseVersion as parseXMLVersion
@@ -95,4 +95,6 @@
 def parseVersion(string):
     """ An extended version, one that doesn't throw exceptions """
     try: return parseXMLVersion(string)
-    except ValueError: return None
+    except ValueError:
+        flash('Cannot parse Version string: "%s"' % string)
+        return None
--- a/farol/document.py	Thu Oct 23 16:57:36 2014 +0200
+++ b/farol/document.py	Fri Oct 24 10:52:04 2014 +0200
@@ -87,9 +87,7 @@
     tracking._identification._aliases = aliases
     tracking._status = request.form['status']
     version = parseVersion(request.form['version'])
-    if version is None:
-        flash('Cannot parse Version field: "%s"' % request.form['version'], 'warning')
-    else:
+    if version is not None:
         tracking._version = version
     tracking._initialDate = parseDate(request.form['initial'])
     tracking._currentDate = parseDate(request.form['current'])
@@ -120,9 +118,7 @@
         return render_template('document/edit_revision.j2', number='.'.join('%s'%v for v in revision._number), date=revision._date, description=revision._description, action='Update')
 
     version = parseVersion(request.form['number'])
-    if version is None:
-        flash('Cannot parse Revision Number: %s' % request.form['number'])
-    else:
+    if version is not None:
         revision._number = version
     revision._date = parseDate(request.form['date'])
     revision._description = request.form['description']
@@ -140,10 +136,7 @@
         version = version[:-1] + (version[-1] + 1,)
         return render_template('document/edit_revision.j2', number='.'.join("%d"%v for v in version), date=utcnow(), action='Add')
 
-    version = parseVersion(request.form['number'])
-    if version is None:
-        flash('Cannot parse Revision Number: "%s", assuming "0.0"' % request.form['number'])
-        version = (0,0)
+    version = parseVersion(request.form['number']) or (0,0)
     date = parseDate(request.form['date'])
     revision = CVRFRevision(version, date, request.form['description'])
     tracking.addRevision(revision)

http://farol.wald.intevation.org