Mercurial > farol > farol
annotate farol/document.py @ 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 | d49c1ee6bc07 |
children | 812e613cbbb4 |
rev | line source |
---|---|
0 | 1 # -*- encoding: utf-8 -*- |
2 # Description: | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
3 # The Document Blueprint |
0 | 4 # |
5 # Authors: | |
6 # BenoƮt Allard <benoit.allard@greenbone.net> | |
7 # | |
8 # Copyright: | |
9 # Copyright (C) 2014 Greenbone Networks GmbH | |
10 # | |
11 # This program is free software; you can redistribute it and/or | |
12 # modify it under the terms of the GNU General Public License | |
13 # as published by the Free Software Foundation; either version 2 | |
14 # of the License, or (at your option) any later version. | |
15 # | |
16 # This program is distributed in the hope that it will be useful, | |
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 # GNU General Public License for more details. | |
20 # | |
21 # You should have received a copy of the GNU General Public License | |
22 # along with this program; if not, write to the Free Software | |
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
24 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
25 from flask import (Blueprint, render_template, abort, redirect, request, |
66
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
26 url_for, flash) |
0 | 27 |
62
ce49bd1512dd
Make pyflafes a happier
Benoît Allard <benoit.allard@greenbone.net>
parents:
61
diff
changeset
|
28 from farolluz.cvrf import (CVRFNote, CVRFReference, CVRFPublisher, |
ce49bd1512dd
Make pyflafes a happier
Benoît Allard <benoit.allard@greenbone.net>
parents:
61
diff
changeset
|
29 CVRFTracking, CVRFTrackingID, CVRFGenerator, CVRFRevision, |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
30 CVRFAggregateSeverity) |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
31 from farolluz.renderer import utcnow |
0 | 32 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
33 from .controller import (update_note_from_request, create_note_from_request, |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
34 update_reference_from_request, create_reference_from_request, |
63
b4fb652484b4
Define a split_fields function to split fields, and use it
Benoît Allard <benoit.allard@greenbone.net>
parents:
62
diff
changeset
|
35 update_acknowledgment_from_request, create_acknowledgment_from_request, |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
36 split_fields, parseDate, parseVersion) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
37 from .session import document_required, get_current |
0 | 38 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
39 |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
40 document = Blueprint('document', __name__) |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
41 |
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
42 @document.route('/') |
0 | 43 @document_required |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
44 def view(): |
0 | 45 cvrf = get_current() |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
46 return render_template('document/view.j2', cvrf=cvrf) |
0 | 47 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
48 @document.route('/title/edit', methods=['GET', 'POST']) |
0 | 49 @document_required |
50 def edit_title(): | |
51 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
52 return render_template('document/edit_title.j2', title = get_current()._title, _type = get_current()._type) |
0 | 53 |
54 | |
55 get_current()._title = request.form['title'] | |
56 get_current()._type = request.form['type'] | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
57 return redirect(url_for('.view')) |
0 | 58 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
59 @document.route('/publisher/edit', methods=['GET', 'POST']) |
0 | 60 @document_required |
61 def edit_publisher(): | |
62 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
63 return render_template('document/edit_publisher.j2', publisher = get_current()._publisher or CVRFPublisher(''), types=CVRFPublisher.TYPES) |
0 | 64 |
65 publisher = CVRFPublisher(request.form['type'], request.form['vendorid'] or None) | |
66 publisher.setContact(request.form['contact'] or None) | |
67 publisher.setAuthority(request.form['authority'] or None) | |
68 get_current().setPublisher(publisher) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
69 return redirect(url_for('.view')) |
0 | 70 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
71 @document.route('/tracking/edit', methods=['GET', 'POST']) |
0 | 72 @document_required |
73 def edit_tracking(): | |
74 wasNone = False | |
75 tracking = get_current()._tracking | |
76 if tracking is None: | |
77 wasNone = True | |
66
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
78 tracking = CVRFTracking(CVRFTrackingID(''), 'Draft', (0,0), utcnow(), utcnow()) |
0 | 79 generator = tracking._generator |
80 if not tracking._generator: | |
81 generator = CVRFGenerator() | |
82 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
83 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) |
0 | 84 |
85 tracking._identification._id = request.form['id'] | |
63
b4fb652484b4
Define a split_fields function to split fields, and use it
Benoît Allard <benoit.allard@greenbone.net>
parents:
62
diff
changeset
|
86 aliases = split_fields(request.form['id_aliases']) |
0 | 87 tracking._identification._aliases = aliases |
88 tracking._status = request.form['status'] | |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
89 version = parseVersion(request.form['version']) |
129
d2588d88d47a
Move parseVersion flashing one level higher
Benoît Allard <benoit.allard@greenbone.net>
parents:
127
diff
changeset
|
90 if version is not None: |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
91 tracking._version = version |
0 | 92 tracking._initialDate = parseDate(request.form['initial']) |
93 tracking._currentDate = parseDate(request.form['current']) | |
94 if wasNone: | |
95 get_current().setTracking(tracking) | |
96 if (not request.form['gen_engine']) and (not request.form['gen_date']): | |
97 generator = None | |
98 else: | |
99 generator._engine = request.form['gen_engine'] or None | |
100 if request.form['gen_date']: | |
101 generator._date = parseDate(request.form['gen_date']) | |
102 else: | |
103 generator._date = None | |
104 tracking.setGenerator(generator) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
105 return redirect(url_for('.view')) |
0 | 106 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
107 @document.route('/revision/<int:index>/edit', methods=['GET', 'POST']) |
0 | 108 @document_required |
109 def edit_revision(index): | |
110 cvrf = get_current() | |
111 if cvrf._tracking is None: | |
112 abort(404) | |
113 try: | |
114 revision = cvrf._tracking._history[index] | |
115 except IndexError: | |
116 abort(404) | |
117 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
118 return render_template('document/edit_revision.j2', number='.'.join('%s'%v for v in revision._number), date=revision._date, description=revision._description, action='Update') |
0 | 119 |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
120 version = parseVersion(request.form['number']) |
129
d2588d88d47a
Move parseVersion flashing one level higher
Benoît Allard <benoit.allard@greenbone.net>
parents:
127
diff
changeset
|
121 if version is not None: |
127
d49c1ee6bc07
Harden server-side version parsing
Benoît Allard <benoit.allard@greenbone.net>
parents:
100
diff
changeset
|
122 revision._number = version |
0 | 123 revision._date = parseDate(request.form['date']) |
124 revision._description = request.form['description'] | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
125 return redirect(url_for('.view')) |
0 | 126 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
127 @document.route('/revision/add', methods=['GET', 'POST']) |
0 | 128 @document_required |
129 def add_revision(): | |
130 tracking = get_current()._tracking | |
131 if request.method != 'POST': | |
66
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
132 if tracking is None: |
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
133 flash('The tracking information should be set first to be able to add a revision.', 'danger') |
f1705e90695b
Don't allow to add a revision without tracking information
Benoît Allard <benoit.allard@greenbone.net>
parents:
64
diff
changeset
|
134 return redirect(url_for('.edit_tracking')) |
0 | 135 version = tracking._version |
136 version = version[:-1] + (version[-1] + 1,) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
137 return render_template('document/edit_revision.j2', number='.'.join("%d"%v for v in version), date=utcnow(), action='Add') |
0 | 138 |
129
d2588d88d47a
Move parseVersion flashing one level higher
Benoît Allard <benoit.allard@greenbone.net>
parents:
127
diff
changeset
|
139 version = parseVersion(request.form['number']) or (0,0) |
0 | 140 date = parseDate(request.form['date']) |
141 revision = CVRFRevision(version, date, request.form['description']) | |
142 tracking.addRevision(revision) | |
143 if 'update_tracking' in request.form: | |
144 tracking._version = version | |
145 tracking._currentDate = date | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
146 return redirect(url_for('.view')) |
0 | 147 |
73 | 148 @document.route('/revision/<int:index>/del', methods=['POST']) |
67
023080ffd995
Allow deletion of revisions
Benoît Allard <benoit.allard@greenbone.net>
parents:
66
diff
changeset
|
149 @document_required |
73 | 150 def del_revision(index): |
68
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
151 history = get_current()._tracking._history |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
152 if not (0 <= index < len(history)): |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
153 flash('Revision not found', 'danger') |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
154 abort(404) |
33cdb9faed64
Improve deletion of revisions (input validation)
Benoît Allard <benoit.allard@greenbone.net>
parents:
67
diff
changeset
|
155 del history[index] |
67
023080ffd995
Allow deletion of revisions
Benoît Allard <benoit.allard@greenbone.net>
parents:
66
diff
changeset
|
156 return redirect(url_for('.view')) |
023080ffd995
Allow deletion of revisions
Benoît Allard <benoit.allard@greenbone.net>
parents:
66
diff
changeset
|
157 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
158 @document.route('/distribution/edit', methods=['GET', 'POST']) |
0 | 159 @document_required |
160 def edit_distribution(): | |
161 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
162 return render_template('document/edit_distribution.j2', distribution=get_current()._distribution) |
0 | 163 |
164 get_current().setDistribution(request.form['distribution']) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
165 return redirect(url_for('.view')) |
0 | 166 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
167 @document.route('/severity/edit', methods=['GET', 'POST']) |
0 | 168 @document_required |
169 def edit_severity(): | |
170 severity = get_current()._aggregateseverity | |
171 if severity is None: | |
172 severity = CVRFAggregateSeverity('') | |
173 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
174 return render_template('document/edit_severity.j2', severity=severity) |
0 | 175 if not request.form['severity']: |
176 severity = None | |
177 else: | |
178 severity._severity = request.form['severity'] | |
179 severity.setNamespace(request.form['namespace'] or None) | |
180 get_current().setAggregateSeverity(severity) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
181 return redirect(url_for('.view')) |
0 | 182 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
183 @document.route('/note/<int:ordinal>') |
0 | 184 @document_required |
185 def view_note(ordinal): | |
186 note = get_current().getNote(ordinal) | |
187 if note is None: | |
188 abort(404) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
189 return render_template('document/view_note.j2', note=note) |
0 | 190 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
191 @document.route('/note/<int:ordinal>/edit', methods=['GET', 'POST']) |
0 | 192 @document_required |
193 def edit_note(ordinal): | |
194 note = get_current().getNote(ordinal) | |
195 if note is None: | |
196 abort(404) | |
197 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
198 return render_template('document/edit_note.j2', note=note, types = note.TYPES) |
0 | 199 |
58
fbc413b8a46e
Unify note update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
7
diff
changeset
|
200 update_note_from_request(note) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
201 return redirect(url_for('.view_note', ordinal=note._ordinal )) |
0 | 202 |
203 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
204 @document.route('/note/add', methods=['GET', 'POST']) |
0 | 205 @document_required |
206 def add_note(): | |
207 if request.method != 'POST': | |
208 next_ordinal = 1 | |
209 notes = get_current()._notes | |
210 if notes: | |
211 next_ordinal = notes[-1]._ordinal + 1 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
212 return render_template('document/edit_note.j2', ordinal=next_ordinal, types=CVRFNote.TYPES, action='Add') |
0 | 213 |
58
fbc413b8a46e
Unify note update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
7
diff
changeset
|
214 note = create_note_from_request() |
0 | 215 get_current().addNote(note) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
216 return redirect(url_for('.view')) |
0 | 217 |
73 | 218 @document.route('/note/<int:ordinal>/del', methods=['POST']) |
70
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
219 @document_required |
73 | 220 def del_note(ordinal): |
70
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
221 cvrf = get_current() |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
222 note = cvrf.getNote(ordinal) |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
223 if note is None: |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
224 flash('Note not found', 'danger') |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
225 abort(404) |
73 | 226 cvrf._notes.remove(note) |
70
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
227 return redirect(url_for('.view')) |
727c01e8e3e9
Allow deletion of Notes
Benoît Allard <benoit.allard@greenbone.net>
parents:
68
diff
changeset
|
228 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
229 @document.route('/reference/<int:index>/edit', methods=['GET', 'POST']) |
0 | 230 @document_required |
231 def edit_reference(index): | |
232 try: | |
233 ref = get_current()._references[index] | |
234 except IndexError: | |
235 abort(404) | |
236 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
237 return render_template('document/edit_reference.j2', _type=ref._type, url=ref._url, description=ref._description, types=('',) + ref.TYPES) |
0 | 238 |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
239 update_reference_from_request(ref) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
240 return redirect(url_for('.view')) |
0 | 241 |
242 | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
243 @document.route('/reference/add', methods=['GET', 'POST']) |
0 | 244 @document_required |
245 def add_reference(): | |
246 if request.method != 'POST': | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
247 return render_template('document/edit_reference.j2', action='Add', types=('',) + CVRFReference.TYPES) |
0 | 248 |
61
55b72057b066
Unify reference update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
60
diff
changeset
|
249 ref = create_reference_from_request() |
0 | 250 get_current().addReference(ref) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
251 return redirect(url_for('.view')) |
0 | 252 |
73 | 253 @document.route('/reference/<int:index>/del', methods=['POST']) |
72
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
254 @document_required |
73 | 255 def del_reference(index): |
72
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
256 refs = get_current()._references |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
257 if not (0 <= index < len(refs)): |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
258 flash('Reference not found', 'danger') |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
259 abort(404) |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
260 del refs[index] |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
261 return redirect(url_for('.view')) |
f9aa7b1e697e
Add possibility to delete References
Benoît Allard <benoit.allard@greenbone.net>
parents:
70
diff
changeset
|
262 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
263 @document.route('/acknowledgment/<int:index>') |
0 | 264 @document_required |
265 def view_acknowledgment(index): | |
266 try: | |
267 ack = get_current()._acknowledgments[index] | |
268 except IndexError: | |
269 abort(404) | |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
270 return render_template('document/view_acknowledgment.j2', acknowledgment=ack, index=index, action='Update') |
0 | 271 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
272 @document.route('/acknowledgment/<int:index>/edit', methods=['GET', 'POST']) |
0 | 273 @document_required |
274 def edit_acknowledgment(index): | |
275 try: | |
276 ack = get_current()._acknowledgments[index] | |
277 except IndexError: | |
278 abort(404) | |
279 if request.method != 'POST': | |
64
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
280 return render_template('document/edit_acknowledgment.j2', |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
281 names=ack._names, organizations=ack._organizations, |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
282 description=ack._description, url=ack._url, |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
283 action='Update') |
0 | 284 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
285 update_acknowledgment_from_request(ack) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
286 return redirect(url_for('.view')) |
0 | 287 |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
288 @document.route('/acknowledgment/add', methods=['GET', 'POST']) |
0 | 289 @document_required |
290 def add_acknowledgment(): | |
291 if request.method != 'POST': | |
64
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
292 return render_template('document/edit_acknowledgment.j2', |
aad7db3f93b6
Add support for Acknowledgments with multiple names and organizations
Benoît Allard <benoit.allard@greenbone.net>
parents:
63
diff
changeset
|
293 action='Add') |
0 | 294 |
60
c6e7175ff28c
Unify acknowledgments update/creation from forms
Benoît Allard <benoit.allard@greenbone.net>
parents:
58
diff
changeset
|
295 ack = create_acknowledgment_from_request() |
0 | 296 get_current().addAcknowledgment(ack) |
7
8f41bb7f4681
Move the Document management routines to a document Blueprint
Benoît Allard <benoit.allard@greenbone.net>
parents:
3
diff
changeset
|
297 return redirect(url_for('.view')) |
74
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
298 |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
299 @document.route('/acknowledgment/<int:index>/del', methods=['POST']) |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
300 @document_required |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
301 def del_acknowledgment(index): |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
302 acks = get_current()._acknowledgments |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
303 if not( 0 <= index < len(acks)): |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
304 flash('Acknowledgment not found', 'danger') |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
305 abort(404) |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
306 del acks[index] |
80cd8f65e72b
Add deletion of Acknowledgments
Benoît Allard <benoit.allard@greenbone.net>
parents:
73
diff
changeset
|
307 return redirect(url_for('.view')) |