Skip to content
Snippets Groups Projects
Commit e1a49634 authored by Tim G's avatar Tim G
Browse files

Merge branch 'frontend-add-comment-view' into 'apdev'

Display a form with errors for passage comment

See merge request anthologie-palatine/anthologyontology!25
parents 10329095 6768a736
No related branches found
No related tags found
1 merge request!25Display a form with errors for passage comment
......@@ -4,4 +4,4 @@ from django import forms
class CommentDescriptionForm(forms.Form):
comment_title = forms.CharField()
description = forms.CharField(widget=forms.Textarea(attrs={"rows": 2, "cols": 40}))
language = forms.CharField(max_length=3)
language = forms.CharField(min_length=3, max_length=3)
{% extends "web/base.html" %}
{% load static i18n %}
{% block content %}
<h1 class="mt-6 u-center headline-4 font-alt">
{{ passage }}
</h1>
<div class="content">
<form
action="."
data-controller="textareas"
data-action="input->textareas#expand"
method="post">
{% csrf_token %}
{{ comment_description_form.as_p }}
<div class="form-section u-flex u-justify-space-between">
<a href="{{ passage.get_absolute_url }}" class="btn u-inline-block">
{% translate "Cancel" %}
</a>
<button class="btn-info u-inline-block" type="submit">
{% translate "Submit & save" %}
</button>
</div>
</form>
</div>
{% endblock %}
{% block extra_body %}
<script src="{% static 'web/js/textareas_controller.js' %}"></script>
<script type="text/javascript">
;(() => {
application.register('textareas', Textareas)
})()
</script>
{% endblock %}
from django.shortcuts import redirect
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from web.models import APPassage
from web.forms.comment import CommentForm
from web.forms.description import DescriptionForm
......@@ -7,8 +7,10 @@ from web.forms.comment_description import CommentDescriptionForm
def add_comment_from_passage(request, passage_pk):
passage = get_object_or_404(APPassage, pk=passage_pk)
description_form = DescriptionForm(request.POST)
comment_form = CommentForm(request.POST)
comment_description_form = CommentDescriptionForm(request.POST)
if description_form.is_valid() and comment_form.is_valid():
description = description_form.save()
......@@ -18,4 +20,8 @@ def add_comment_from_passage(request, passage_pk):
passage.comments.add(comment)
return redirect(f"{passage.get_absolute_url()}#comment-{comment.pk}")
else:
return HttpResponse("Invalid form")
return render(
request,
"web/add_comment_from_passage.html",
{"passage": passage, "comment_description_form": comment_description_form},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment