Skip to content

Commit

Permalink
Add Postmortem update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasha Radchenko committed Mar 25, 2021
1 parent e522832 commit 6741f2b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 8 deletions.
8 changes: 4 additions & 4 deletions autopsy_app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class ProfileForm(FlaskForm):
class PostmortemForm(FlaskForm):
title = StringField('Title', validators=[DataRequired(), Length(max=100)])
mortem = TextAreaField('Mortem details', validators=[DataRequired()])
submit = SubmitField('Add Postmortem')
submit = SubmitField('Postmortem!')


class SupportForm(FlaskForm):
subject = StringField('Subject', validators=[DataRequired(),
Length(max=100)])
content = TextAreaField('Case details',
validators=[DataRequired()])
validators=[DataRequired()])
attach = FileField('Attach a screenshot',
validators=[FileAllowed(['jpg','png'],
'Images only!')])
validators=[FileAllowed(['jpg', 'png'],
'Images only!')])
submit = SubmitField('Request for help')
23 changes: 22 additions & 1 deletion autopsy_app/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from flask import render_template, request, flash, redirect, url_for
from flask import render_template, request, flash, redirect, url_for, abort
from flask_login import login_user, logout_user, current_user, login_required
from autopsy_app import app, flask_bcrypt
from autopsy_app.model import db, User, Mortem, Support
Expand Down Expand Up @@ -120,6 +120,27 @@ def get_postmortem(url):
return render_template('get_postmortem.html', mortem=mortem)


@app.route('/postmortems/<url>/update', methods=['GET', 'POST'])
@login_required
def update_postmortem(url):
mortem = Mortem.query.filter_by(mortem_url=url).first()
if mortem.author != current_user:
abort(403)
form = PostmortemForm()
# passing value of Mortem content to the textarea
if form.validate_on_submit():
mortem.mortem_name = form.title.data
mortem.mortem_content = form.mortem.data
mortem.mortem_updated = datetime.datetime.utcnow()
db.session.commit()
flash('The mortem has been updated', 'success')
return redirect(url_for('get_postmortem', url=url))
elif request.method == "GET":
form.title.data = mortem.mortem_name
form.mortem.data = mortem.mortem_content
return render_template('update_postmortem.html', mortem=mortem, form=form)


@app.route('/notifications')
@login_required
def notify():
Expand Down
9 changes: 6 additions & 3 deletions autopsy_app/templates/get_postmortem.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
<title>Autopsy: Add Postmortem</title>
{% endblock title %}



{% block content_top %}
<div class="flex-row d-flex">
<div class="mortem-tab">
<a href="{{ url_for('postmortems') }}">Postmortems</a>
</div>
<div class="mortem-tab-focus">
<a href="{{ mortem.mortem_url }}"> View
<span data-feather="trending-down"></span>
<span data-feather="corner-right-down"></span>
</a>
</div>
<div class="mortem-tab">
<a href="{{ mortem.mortem_url }}/update">Update
<span data-feather="refresh-cw"></span>
</a>
</div>
<div class="mortem-tab">
Expand Down
84 changes: 84 additions & 0 deletions autopsy_app/templates/update_postmortem.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{% extends "base/middle_layer.html" %}

{% block title %}
<title>Autopsy: Update Postmortem</title>
{% endblock title %}


{% block content_top %}
<div class="flex-row d-flex">
<div class="mortem-tab">
<a href="{{ url_for('postmortems') }}">Postmortems</a>
</div>
<div class="mortem-tab-focus">
<a href="{{ mortem.mortem_url }}"> Update
<span data-feather="refresh-cw"></span>
</a>
</div>
<div class="mortem-tab">
<a href="{{ url_for('add_postmortem') }}">New
<span data-feather="plus-square"></span>
</a>
</div>
</div>
{% endblock content_top %}

{% block content_body %}
<div class="flex-row">
{% if mortem %}
<div class="my-3">
<div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }}">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
</div>
<form class="col-lg-8" action="" method="POST">
{{ form.hidden_tag() }}
<div class="form-group py-2 my-2">
{{ form.title.label(class="form-control-label") }}
{% if form.title.errors %}
{{ form.title(class="form-control form-control-md is-invalid") }}
<div class="invalid-feedback">
{% for err in form.title.errors %}
<span>
{{ err }}
</span>
{% endfor%}
</div>
{% else %}
{{ form.title(class="form-control form-control-md",
value=mortem.mortem_name) }}
{% endif %}
</div>

<div class="form-group py-2 my-2">
{{ form.mortem.label(class="form-control-label") }}
{% if form.mortem.errors %}
{{ form.mortem(class="form-control form-control-md add-mortem-content is-invalid") }}
<div class="invalid-feedback">
{% for err in form.mortem.errors %}
<span>
{{ err }}
</span>
{% endfor%}
</div>
{% else %}
{{ form.mortem(class="form-control form-control-md add-mortem-content") }}
{% endif %}
</div>

<div class="form-group py-2 my-2">
{{ form.submit(class="btn btn-lg btn-outline-dark btn-block") }}
</div>
</form>
</div>
{% endif %}
</div>
{% endblock content_body %}

0 comments on commit 6741f2b

Please sign in to comment.