diff --git a/webapp/forms.py b/webapp/forms.py index 7c29bf2..35757f1 100644 --- a/webapp/forms.py +++ b/webapp/forms.py @@ -4,7 +4,8 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from django.core.exceptions import ValidationError -from webapp.models import OhlhafvChallenge, KaehmyForm +from webapp.models import OhlhafvChallenge, KaehmyForm, KaehmyMessage + class KaehmyForm_Form(forms.ModelForm): @@ -27,6 +28,13 @@ class KaehmyForm_Form(forms.ModelForm): raise ValidationError(_('Invalid value')) +class KaehmyCommentForm(forms.ModelForm): + + class Meta: + model = KaehmyMessage + fields = ['name', 'email', 'message', 'parent'] + + class OhlhafvForm(forms.ModelForm): """Class representing Ohlhafv form.""" diff --git a/webapp/templates/error.html b/webapp/templates/error.html new file mode 100644 index 0000000..ccb932f --- /dev/null +++ b/webapp/templates/error.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block navigation %} +{% endblock navigation %} + +{% block content %} + +{% endblock content %} \ No newline at end of file diff --git a/webapp/templates/kaehmy_list.html b/webapp/templates/kaehmy_list.html index 18a948e..2bcd48e 100644 --- a/webapp/templates/kaehmy_list.html +++ b/webapp/templates/kaehmy_list.html @@ -8,6 +8,17 @@ {% endblock %} {% block content %} +

{% trans "All kaehmys" %}

@@ -17,6 +28,34 @@
{% trans "Total kaehmys:" %} {{ application_count }}
+
+
+
+
{% csrf_token %} +
+ {% trans "Commenting on post by " %} + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+ {% for application in applications %}
@@ -31,16 +70,26 @@

{{ application.text }}

- -
- {% for message in application.messages.all %} - {% include "kaehmy_message.html" with messages=message.messages.all %} - {% endfor %} + {% if application.comment_count > 0 %} + + {% endif %} + +
+ +
+ +
+ {% for message in application.messages.all %} + {% include "kaehmy_message.html" with messages=message.messages.all %} + {% endfor %}
{% endfor %} +
{% endblock content %} diff --git a/webapp/templates/kaehmy_message.html b/webapp/templates/kaehmy_message.html index 410492b..44230e4 100644 --- a/webapp/templates/kaehmy_message.html +++ b/webapp/templates/kaehmy_message.html @@ -1,10 +1,16 @@ -
+{% load i18n %} + +

{{ message.name }}

{{ message.message }}

{{ message.timestamp }}
- +
+ +
{% for message in messages %} {% include "kaehmy_message.html" with messages=message.messages.all %} diff --git a/webapp/templates/sik_header.html b/webapp/templates/sik_header.html index 17ef251..b447b3b 100644 --- a/webapp/templates/sik_header.html +++ b/webapp/templates/sik_header.html @@ -3,6 +3,6 @@
diff --git a/webapp/urls.py b/webapp/urls.py index fd9b5a6..f93c35c 100644 --- a/webapp/urls.py +++ b/webapp/urls.py @@ -21,6 +21,7 @@ from webapp.views import contact_view from webapp.views import kaehmy_view from webapp.views import kaehmy_list_view from webapp.views import kaehmy_submit +from webapp.views import kaehmy_comment urlpatterns = [ # main @@ -49,6 +50,7 @@ urlpatterns = [ url(r'^kaehmy$', kaehmy_list_view), url(r'^kaehmy/new', kaehmy_view), url(r'^kaehmy/submit', kaehmy_submit), + url(r'^kaehmy/add_comment', kaehmy_comment), # ohlhafv url(r'^ohlhafv$', ohlhafv_view), diff --git a/webapp/views.py b/webapp/views.py index 806088d..db1eeeb 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -10,7 +10,7 @@ from django.conf import settings import logging from webapp.models import CustomKaehmyRole from webapp.models import OhlhafvChallenge, KaehmyForm -from webapp.forms import OhlhafvForm, KaehmyForm_Form +from webapp.forms import OhlhafvForm, KaehmyForm_Form, KaehmyCommentForm from webapp.tables import OhlhafvTable @@ -187,3 +187,20 @@ def kaehmy_list_view(request, *args, **kwargs): 'application_count': len(applications) } return render(request, 'kaehmy_list.html', context) + + +@ensure_csrf_cookie +@require_http_methods(["POST"]) +def kaehmy_comment(request, *args, **kwargs): + """POST endpoint for commenting""" + + form = KaehmyCommentForm(request.POST) + if form.is_valid(): + form.save() + return redirect('/kaehmy') + else: + print(form) + context = { + 'errors': form.errors + } + return render(request, 'error.html', context)