feat: Add basic comment form
This commit is contained in:
parent
7bcab5bb59
commit
aebbe0f6c6
@ -2,7 +2,7 @@ import datetime
|
||||
|
||||
from django import forms
|
||||
|
||||
from .models import AdoptionNotice, Animal, Image, Report, ModerationAction, User, Species
|
||||
from .models import AdoptionNotice, Animal, Image, Report, ModerationAction, User, Species, Comment
|
||||
from django_registration.forms import RegistrationForm
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field
|
||||
@ -59,6 +59,10 @@ class ReportForm(forms.ModelForm):
|
||||
model = Report
|
||||
fields = ('reported_broken_rules', 'comment')
|
||||
|
||||
class CommentForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Comment
|
||||
fields = ('text',)
|
||||
|
||||
class ModerationActionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
@ -0,0 +1,7 @@
|
||||
{% load i18n %}
|
||||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{{ comment_form.as_p }}
|
||||
<button class="button-report" type="submit">{% translate "Kommentieren" %}</button>
|
||||
</form>
|
@ -12,4 +12,10 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
{% include "fellchensammlung/forms/form-comment.html" %}
|
||||
{% else %}
|
||||
{% translate 'Du musst dich einloggen um Kommentare zu hinterlassen' %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
@ -4,15 +4,16 @@ from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render, redirect
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from django.utils import translation
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from .mail import mail_admins_new_report
|
||||
from notfellchen import settings
|
||||
|
||||
from fellchensammlung import logger
|
||||
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
||||
Member
|
||||
from .forms import AdoptionNoticeForm, ImageForm, ReportForm
|
||||
from .forms import AdoptionNoticeForm, ImageForm, ReportForm, CommentForm
|
||||
from .models import Language
|
||||
|
||||
|
||||
@ -43,7 +44,20 @@ def change_language(request):
|
||||
|
||||
def adoption_notice_detail(request, adoption_notice_id):
|
||||
adoption_notice = AdoptionNotice.objects.get(id=adoption_notice_id)
|
||||
context = {"adoption_notice": adoption_notice}
|
||||
if request.method == 'POST':
|
||||
if request.user.is_authenticated:
|
||||
comment_form = CommentForm(request.POST)
|
||||
|
||||
if comment_form.is_valid():
|
||||
comment_instance = comment_form.save(commit=False)
|
||||
comment_instance.adoption_notice_id = adoption_notice_id
|
||||
comment_instance.user = request.user.member
|
||||
comment_instance.save()
|
||||
else:
|
||||
raise PermissionDenied
|
||||
else:
|
||||
comment_form = CommentForm(instance=adoption_notice)
|
||||
context = {"adoption_notice": adoption_notice, "comment_form": comment_form}
|
||||
return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user