changeset 61:55b72057b066

Unify reference update/creation from forms
author Benoît Allard <benoit.allard@greenbone.net>
date Wed, 08 Oct 2014 12:06:50 +0200
parents c6e7175ff28c
children ce49bd1512dd
files farol/controller.py farol/document.py farol/vulnerability.py
diffstat 3 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/farol/controller.py	Wed Oct 08 11:58:33 2014 +0200
+++ b/farol/controller.py	Wed Oct 08 12:06:50 2014 +0200
@@ -45,6 +45,15 @@
     return CVRFNote(request.form['type'], int(request.form['ordinal']),
                     request.form['note'], title, audience)
 
+def update_reference_from_request(ref):
+    ref._type = request.form['type'] or None
+    ref._url = request.form['url']
+    ref._description = request.form['description']
+
+def create_reference_from_request():
+    return CVRFReference(request.form['url'], request.form['description'],
+                         request.form['type'] or None)
+
 def update_acknowledgment_from_request(ack):
     ack._name = request.form['name'] or None
     ack._organization = request.form['organization'] or None
--- a/farol/document.py	Wed Oct 08 11:58:33 2014 +0200
+++ b/farol/document.py	Wed Oct 08 12:06:50 2014 +0200
@@ -32,6 +32,7 @@
 from farolluz.renderer import utcnow
 
 from .controller import (update_note_from_request, create_note_from_request,
+    update_reference_from_request, create_reference_from_request,
     update_acknowledgment_from_request, create_acknowledgment_from_request)
 from .session import document_required, get_current
 
@@ -209,9 +210,7 @@
     if request.method != 'POST':
         return render_template('document/edit_reference.j2', _type=ref._type, url=ref._url, description=ref._description, types=('',) + ref.TYPES)
 
-    ref._type = request.form['type'] or None
-    ref._url = request.form['url']
-    ref._description = request.form['description']
+    update_reference_from_request(ref)
     return redirect(url_for('.view'))
 
 
@@ -221,7 +220,7 @@
     if request.method != 'POST':
         return render_template('document/edit_reference.j2', action='Add', types=('',) + CVRFReference.TYPES)
 
-    ref = CVRFReference(request.form['url'], request.form['description'], request.form['type'] or None)
+    ref = create_reference_from_request()
     get_current().addReference(ref)
     return redirect(url_for('.view'))
 
--- a/farol/vulnerability.py	Wed Oct 08 11:58:33 2014 +0200
+++ b/farol/vulnerability.py	Wed Oct 08 12:06:50 2014 +0200
@@ -32,6 +32,7 @@
 from farolluz.renderer import utcnow
 
 from .controller import (update_note_from_request, create_note_from_request,
+    update_reference_from_request, create_reference_from_request,
     update_acknowledgment_from_request, create_acknowledgment_from_request)
 from .session import document_required, get_current
 
@@ -426,9 +427,7 @@
     if request.method != 'POST':
         return render_template('vulnerability/edit_reference.j2', ordinal=ordinal, _type=reference._type, url=reference._url, description=reference._description, types=('',) + reference.TYPES)
 
-    reference._type = request.form['type'] or None
-    reference._url = request.form['url']
-    reference._description = request.form['description']
+    update_reference_from_request(reference)
     return redirect(url_for('.view', ordinal=ordinal))
 
 @vulnerability.route('/<int:ordinal>/reference/add', methods=['GET', 'POST'])
@@ -437,7 +436,7 @@
     if request.method != 'POST':
         return render_template('vulnerability/edit_reference.j2', action='Add', ordinal=ordinal, types=('',) + CVRFReference.TYPES)
 
-    ref = CVRFReference(request.form['url'], request.form['description'], request.form['type'] or None)
+    ref = create_reference_from_request()
     get_vuln(ordinal).addReference(ref)
     return redirect(url_for('.view', ordinal=ordinal))
 

http://farol.wald.intevation.org