changeset 73:88adf067cae1

Fix delete urls
author Benoît Allard <benoit.allard@greenbone.net>
date Thu, 09 Oct 2014 11:14:50 +0200
parents f9aa7b1e697e
children 80cd8f65e72b
files farol/document.py farol/templates/document/view.j2 farol/templates/document/view_note.j2 farol/templates/macros.j2
diffstat 4 files changed, 11 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/farol/document.py	Thu Oct 09 10:31:06 2014 +0200
+++ b/farol/document.py	Thu Oct 09 11:14:50 2014 +0200
@@ -142,10 +142,9 @@
         tracking._currentDate = date
     return redirect(url_for('.view'))
 
-@document.route('/revision/del', methods=['POST'])
+@document.route('/revision/<int:index>/del', methods=['POST'])
 @document_required
-def del_revision():
-    index = int(request.form['index'])
+def del_revision(index):
     history = get_current()._tracking._history
     if not (0 <= index < len(history)):
         flash('Revision not found', 'danger')
@@ -213,17 +212,15 @@
     get_current().addNote(note)
     return redirect(url_for('.view'))
 
-@document.route('/note/del', methods=['POST'])
+@document.route('/note/<int:ordinal>/del', methods=['POST'])
 @document_required
-def del_note():
-    ordinal = int(request.form['ordinal'])
+def del_note(ordinal):
     cvrf = get_current()
-    notes = cvrf._notes
     note = cvrf.getNote(ordinal)
     if note is None:
         flash('Note not found', 'danger')
         abort(404)
-    notes.remove(note)
+    cvrf._notes.remove(note)
     return redirect(url_for('.view'))
 
 @document.route('/reference/<int:index>/edit', methods=['GET', 'POST'])
@@ -250,10 +247,9 @@
     get_current().addReference(ref)
     return redirect(url_for('.view'))
 
-@document.route('/reference/del', methods=['POST'])
+@document.route('/reference/<int:index>/del', methods=['POST'])
 @document_required
-def del_reference():
-    index = int(request.form['index'])
+def del_reference(index):
     refs = get_current()._references
     if not (0 <= index < len(refs)):
         flash('Reference not found', 'danger')
--- a/farol/templates/document/view.j2	Thu Oct 09 10:31:06 2014 +0200
+++ b/farol/templates/document/view.j2	Thu Oct 09 11:14:50 2014 +0200
@@ -62,7 +62,7 @@
         <div class="form-horizontal">
           <div class="pull-right">
             <a  href="{{ url_for('.edit_revision', index=loop.index0) }}"><span class="label label-default">edit</span></a>
-            {{ delete_button(url_for('.del_revision'), {'index': loop.index0}) }}
+            {{ delete_button(url_for('.del_revision', index=loop.index0)) }}
           </div>
           {{ label_value('Number', revision._number | join('.'), right=8) }}
           {{ label_value('Date', revision._date) }}
@@ -118,7 +118,7 @@
     {% call panel(type="warning", heading="References", badge=cvrf._references | length, title=3) %}
     <ul>
     {% for reference in cvrf._references %}
-      <li><a href="{{ reference._url }}" target="_blank">{{ reference._description }}{% if reference._type %} ({{ reference._type }}){% endif %}</a> (<a href="{{ url_for('.edit_reference', index=loop.index0) }}">edit</a>){{ delete_button(url_for('.del_reference'), {'index': loop.index0}) }}</li>
+      <li><a href="{{ reference._url }}" target="_blank">{{ reference._description }}{% if reference._type %} ({{ reference._type }}){% endif %}</a> (<a href="{{ url_for('.edit_reference', index=loop.index0) }}">edit</a>){{ delete_button(url_for('.del_reference', index=loop.index0)) }}</li>
     {% endfor %}
     </ul>
     <a class="pull-right" href="{{ url_for('.add_reference') }}">add</a>
--- a/farol/templates/document/view_note.j2	Thu Oct 09 10:31:06 2014 +0200
+++ b/farol/templates/document/view_note.j2	Thu Oct 09 11:14:50 2014 +0200
@@ -34,5 +34,5 @@
 </div>
 {% if note._audience %}<p>Audience: <em>{{ note._audience }}</em></p>{% endif %}
 <p>{{ note._note | replace('\n', '<br>') }}</p>
-<div class="pull-right">{{ delete_button(url_for('.del_note'), {'ordinal': note._ordinal}) }}</div>
+<div class="pull-right">{{ delete_button(url_for('.del_note', ordinal=note._ordinal)) }}</div>
 {% endblock %}
--- a/farol/templates/macros.j2	Thu Oct 09 10:31:06 2014 +0200
+++ b/farol/templates/macros.j2	Thu Oct 09 11:14:50 2014 +0200
@@ -169,7 +169,7 @@
 {% endif %}
 {% endmacro %}
 
-{% macro delete_button(url, hiddens, text="delete") %}
+{% macro delete_button(url, hiddens={}, text="delete") %}
 <form class="delete" action="{{ url }}" method="POST">
   {% for elem in hiddens %}
   <input type=hidden name="{{ elem }}", value="{{ hiddens[elem] }}">

http://farol.wald.intevation.org