Commits

Benoît Allard committed 24682dc

Add possibility to delete empty issues

  • Participants
  • Parent commits f52681e

Comments (0)

Files changed (3)

File web/delete.py

+""" delete operations on the DB """
+
+from flask import Blueprint, request, abort, flash, url_for
+
+from utils import my_redirect
+
+import models
+
+delete = Blueprint('delete', __name__)
+
+@delete.route('/issue/', methods=['POST'])
+def issue():
+    ref = request.form['ref']
+    issue = request.dbsession.query(models.Issue) \
+                             .filter_by(ref=ref) \
+                             .one()
+    if issue is None:
+        flash ('Issue "%s" not found' % ref)
+        abort(404)
+    if issue.changesets:
+        flash('Cannot delete issue "%s", it is linked to %d changesets' %
+              (ref, len(issue.changesets)))
+        abort(412) # Precondition Failed
+    request.dbsession.delete(issue)
+    flash('Issue "%s" deleted.' % ref)
+    request.dbsession.commit()
+    return my_redirect(url_for('views.listissues'))
+

File web/templates/issues.html

 {% block items %}
 {% for issue in issues %}
   <li class="issue">
-    <p>
+    <div>
     {{ macros.render_issue(issue)|safe }}:
       
     <span class="badge {{ 'badge-info' if issue.changesets }}">{{ issue.changesets | count }}</span>
       linked changeset{% if (issue.changesets | count) > 1 %}s{% endif %}.
-    </p>
+    {% if not issue.changesets %}
+    <form class="form-inline"
+	  action="{{ url_for('delete.issue') }}"
+	  method="POST"
+	  style="display:inline">
+      <input type="hidden" name="ref" value="{{ issue.ref }}">
+      <button class="btn btn-danger btn-mini" type="submit">
+	<i class="icon-remove-circle icon-white"></i>
+	delete
+      </button>
+    </form>
+    {% endif %}
+    </div>
   </li>
 {% else %}
   <li> No issue in DB (yet)</li>
 from views import views
 from ajax import ajax
 from edit import edit
+from delete import delete
 from diff import diff
 from yamlbp import yamlbp
 from utils import *
     app.register_blueprint(views)
     app.register_blueprint(ajax)
     app.register_blueprint(edit, url_prefix='/edit')
+    app.register_blueprint(delete, url_prefix='/delete')
     app.register_blueprint(diff, url_prefix='/diff')
     app.register_blueprint(yamlbp, url_prefix='/yaml')
     app.register_blueprint(db, url_prefix='/db')