Mercurial > farol
changeset 63:b4fb652484b4
Define a split_fields function to split fields, and use it
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Wed, 08 Oct 2014 14:15:16 +0200 |
parents | ce49bd1512dd |
children | aad7db3f93b6 |
files | farol/controller.py farol/document.py |
diffstat | 2 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/farol/controller.py Wed Oct 08 12:55:40 2014 +0200 +++ b/farol/controller.py Wed Oct 08 14:15:16 2014 +0200 @@ -31,6 +31,11 @@ from farolluz.cvrf import CVRFNote, CVRFReference, CVRFAcknowledgment +def split_fields(field, separator=','): + if not field: + return [] + return [f.strip() for f in field.split(separator)] + def update_note_from_request(note): note._type = request.form['type'] note._ordinal = int(request.form['ordinal']) @@ -55,15 +60,15 @@ 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 + ack._names = split_fields(request.form['names']) + ack._organizations = split_fields(request.form['organizations']) ack._description = request.form['description'] or None ack._url = request.form['url'] or None def create_acknowledgment_from_request(): ack = CVRFAcknowledgment() - ack._name = request.form['name'] or None - ack._organization = request.form['organization'] or None + ack._names = split_fields(request.form['names']) + ack._organizations = split_fields(request.form['organizations']) ack._description = request.form['description'] or None ack._url = request.form['url'] or None return ack
--- a/farol/document.py Wed Oct 08 12:55:40 2014 +0200 +++ b/farol/document.py Wed Oct 08 14:15:16 2014 +0200 @@ -33,7 +33,8 @@ 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) + update_acknowledgment_from_request, create_acknowledgment_from_request, + split_fields) from .session import document_required, get_current @@ -83,9 +84,7 @@ return render_template('document/edit_tracking.j2', tracking=tracking, version='.'.join('%s'%v for v in tracking._version), generator=generator, now=utcnow(), statuses=tracking.STATUSES) tracking._identification._id = request.form['id'] - aliases = [] - if request.form['id_aliases']: - aliases = [a.strip() for a in request.form['id_aliases'].split(',')] + aliases = split_fields(request.form['id_aliases']) tracking._identification._aliases = aliases tracking._status = request.form['status'] tracking._version = parseVersion(request.form['version'])