Show error on page if submitting an empty comment

This commit is contained in:
Patrick Smith
2018-09-24 13:52:35 -04:00
committed by Andrew Croce
parent bed03901c2
commit fafe98756b
3 changed files with 37 additions and 17 deletions

View File

@@ -21,7 +21,7 @@ def map_ccpo_authorizing(user):
return {"fname_ccpo": user.first_name, "lname_ccpo": user.last_name}
def render_approval(request, form=None):
def render_approval(request, form=None, internal_comment_form=None):
data = request.body
if request.has_financial_data:
data["task_order"] = request.task_order.to_dictionary()
@@ -30,7 +30,8 @@ def render_approval(request, form=None):
mo_data = map_ccpo_authorizing(g.current_user)
form = CCPOReviewForm(data=mo_data)
internal_comment_form = InternalCommentForm()
if not internal_comment_form:
internal_comment_form = InternalCommentForm()
# Dummy internal comments
comments = [
@@ -52,7 +53,7 @@ def render_approval(request, form=None):
reviews=list(reversed(request.reviews)),
request=request,
current_status=request.status.value,
f=form or CCPOReviewForm(),
review_form=form or CCPOReviewForm(),
internal_comment_form=internal_comment_form,
comments=request.internal_comments,
)
@@ -102,9 +103,11 @@ def task_order_pdf_download(request_id):
@requests_bp.route("/requests/internal_comments/<string:request_id>", methods=["POST"])
def create_internal_comment(request_id):
form = InternalCommentForm(http_request.form)
request = Requests.get(g.current_user, request_id)
if form.validate():
request = Requests.get(g.current_user, request_id)
Requests.add_internal_comment(g.current_user, request, form.data.get("text"))
return redirect(
url_for("requests.approval", request_id=request_id, _anchor="ccpo-notes")
)
return redirect(
url_for("requests.approval", request_id=request_id, _anchor="ccpo-notes")
)
else:
return render_approval(request, internal_comment_form=form)