diff --git a/models/database.py b/models/database.py index 6a9cf5d3d7ff63241e3f099d04cf4a5d9d2d3c81..adafb0156d02ec34d186a0c68a03ed658fbd5c21 100644 --- a/models/database.py +++ b/models/database.py @@ -148,3 +148,8 @@ class Statement(db.Model): self.execution_time = datetime.now() return True + def undo(self): + if not self.executed: + return False + self.executed = False + self.execution_time = datetime(1970, 1, 1) diff --git a/modules/admin.py b/modules/admin.py index b590b237f0735c8811ba933b666f01303d847a24..3c2c79dddad154efb4a5c86b065886625bf01293 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -189,7 +189,7 @@ def topic_edit(): if form.validate_on_submit(): form.populate_obj(topic) db.session.commit() - return redirect(url_for(".index")) + return redirect(url_for(".topic_show", id=topic.id)) else: return render_layout("admin_topic_edit.html", form=form, id=topic_id) else: @@ -256,3 +256,11 @@ def statement_delete(): return redirect(url_for(".topic_show", id=topic_id)) return redirect(url_for(".index")) +@admin.route("/statement/undo") +@login_required +@admin_permission.require() +def statement_undo(): + statement = Statement.query.filter_by(executed=True).order_by(db.desc(Statement.execution_time)).first() + statement.undo() + db.session.commit() + return redirect(url_for(".topic_show", id=statement.topic.id)) diff --git a/templates/admin_topic_show.html b/templates/admin_topic_show.html index f0d2990806a80747fb8417a22dda15da15c024e7..f030874070754703bb1f84502d95b2b55bfa3e28 100644 --- a/templates/admin_topic_show.html +++ b/templates/admin_topic_show.html @@ -35,5 +35,12 @@ </tbody> </table> </div> - {{ render_form(form, action_url=url_for(".statement_new"), action_text="Add", title="Add Statement", class_="mdl-card mdl-shadow--2dp mdl-cell mdl-cell--3-col mdl-cell-3-col-tablet mdl-cell--4-col-phone") }} + <div class="mdl-cell mdl-cell--3-col mdl-cell--3-col-tablet mdl-cell--4-col-phone mdl-grid mdl-grid--no-spacing"> + {{ render_form(form, action_url=url_for(".statement_new"), action_text="Add", title="Add Statement", class_="mdl-card mdl-shadow--2dp mdl-cell mdl-cell--12-col mdl-cell--8-col-tablet mdl-cell--4-col-phone") }} + <div class="mdl-cell mdl-card mdl-shadow--2dp mdl-cell--12-col mdl-cell--8-col-tablet mdl-cell--4-col-phone"> + <ul class="mdl-menu"> + <li class="mdl-menu__item"><a class="mdl-navigation__link" href="{{ url_for(".statement_undo") }}"><i class="material-icons" role="presentation">undo</i>Undo</a></li> + </ul> + </div> + </div> {% endblock %}