# HG changeset patch # User Benoît Allard # Date 1412760851 -7200 # Node ID fbc413b8a46e0ec0b3c935f90b44bbb2227efa87 # Parent 4ac1dd522998e6da8b89ad373812d63ba863619a Unify note update/creation from forms diff -r 4ac1dd522998 -r fbc413b8a46e farol/controller.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/farol/controller.py Wed Oct 08 11:34:11 2014 +0200 @@ -0,0 +1,46 @@ +# -*- encoding: utf-8 -*- +# Description: +# Common controller Web stuffs +# +# Authors: +# Benoît Allard +# +# Copyright: +# Copyright (C) 2014 Greenbone Networks GmbH +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + +"""\ +Some common routines for handling of Notes, Acknowledgments and Reference that +is shared for the Document and the Vulnerabilities. +""" + +from flask import request + +from farolluz.cvrf import CVRFNote + +def update_note_from_request(note): + note._type = request.form['type'] + note._ordinal = int(request.form['ordinal']) + note._note = request.form['note'] + note._title = request.form['title'] or None + note._audience = request.form['audience'] or None + +def create_note_from_request(): + title = request.form['title'] or None + audience = request.form['audience'] or None + + return CVRFNote(request.form['type'], int(request.form['ordinal']), + request.form['note'], title, audience) diff -r 4ac1dd522998 -r fbc413b8a46e farol/document.py --- a/farol/document.py Wed Oct 08 10:22:14 2014 +0200 +++ b/farol/document.py Wed Oct 08 11:34:11 2014 +0200 @@ -31,6 +31,7 @@ CVRFAggregateSeverity) from farolluz.renderer import utcnow +from .controller import update_note_from_request, create_note_from_request from .session import document_required, get_current @@ -179,11 +180,7 @@ if request.method != 'POST': return render_template('document/edit_note.j2', note=note, types = note.TYPES) - note._type = request.form['type'] - note._ordinal = int(request.form['ordinal']) - note._note = request.form['note'] - note._title = request.form['title'] or None - note._audience = request.form['audience'] or None + update_note_from_request(note) return redirect(url_for('.view_note', ordinal=note._ordinal )) @@ -197,12 +194,7 @@ next_ordinal = notes[-1]._ordinal + 1 return render_template('document/edit_note.j2', ordinal=next_ordinal, types=CVRFNote.TYPES, action='Add') - title = None - audience = None - title = request.form['title'] or None - audience = request.form['audience'] or None - - note = CVRFNote(request.form['type'], int(request.form['ordinal']), request.form['note'], title, audience) + note = create_note_from_request() get_current().addNote(note) return redirect(url_for('.view')) diff -r 4ac1dd522998 -r fbc413b8a46e farol/vulnerability.py --- a/farol/vulnerability.py Wed Oct 08 10:22:14 2014 +0200 +++ b/farol/vulnerability.py Wed Oct 08 11:34:11 2014 +0200 @@ -31,6 +31,7 @@ CVRFProductStatus, CVRFCVSSSet, CVRFRemediation) from farolluz.renderer import utcnow +from .controller import update_note_from_request, create_note_from_request from .session import document_required, get_current @@ -124,11 +125,7 @@ if request.method != 'POST': return render_template('vulnerability/edit_note.j2', note=note, ordinal=ordinal, types=note.TYPES) - note._type = request.form['type'] - note._ordinal = int(request.form['ordinal']) - note._note = request.form['note'] - note._title = request.form['title'] or None - note._audience = request.form['audience'] or None + update_note_from_request(note) return redirect(url_for('.view_note', ordinal=ordinal, note_ordinal=note._ordinal)) @vulnerability.route('//note/add', methods=['GET', 'POST']) @@ -141,10 +138,7 @@ next_ordinal = notes[-1]._ordinal + 1 return render_template('vulnerability/edit_note.j2', ordinal=ordinal, note_ordinal=next_ordinal, types=CVRFNote.TYPES, action='Add') - title = request.form['title'] or None - audience = request.form['audience'] or None - - note = CVRFNote(request.form['type'], int(request.form['ordinal']), request.form['note'], title, audience) + note = create_note_from_request() get_vuln(ordinal).addNote(note) return redirect(url_for('.view', ordinal=ordinal))