Ajout de la possibilité de commenter les événements
This commit is contained in:
parent
bc06b6205d
commit
0526854d6b
@ -798,3 +798,13 @@ class MessageForm(ModelForm):
|
||||
if self.internal:
|
||||
self.fields.pop("name")
|
||||
self.fields.pop("email")
|
||||
|
||||
class MessageEventForm(ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Message
|
||||
fields = ["message"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["message"].label = _("Add a comment")
|
File diff suppressed because it is too large
Load Diff
@ -1574,7 +1574,7 @@ label.required::after {
|
||||
|
||||
}
|
||||
|
||||
.chronology {
|
||||
#chronology {
|
||||
.entree {
|
||||
display: grid;
|
||||
grid-template-columns: fit-content(2em) auto;
|
||||
|
@ -28,7 +28,7 @@
|
||||
{% endwith %}
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<article class="chronology">
|
||||
<article id="chronology">
|
||||
<header>
|
||||
<h2>Chronologie</h2>
|
||||
</header>
|
||||
@ -37,10 +37,10 @@
|
||||
<div class="entree dateline">
|
||||
<div><span class="ts">{{ step.timestamp }}</span></div>
|
||||
<div>
|
||||
{% if step.data == "created_date" %}<em>création</em>{% endif %}
|
||||
{% if step.data == "modified_date" %}<em>dernière modification</em>{% endif %}
|
||||
{% if step.data == "moderated_date" %}<em>dernière modération</em>{% endif %}
|
||||
{% if step.data == "imported_date" %}<em>dernière importation</em>{% endif %}
|
||||
{% if step.data == "created_date" %}<em>création</em>{% if event.created_by_user %} par {{ event.created_by_user.username }}{% endif %}{% endif %}
|
||||
{% if step.data == "modified_date" %}<em>dernière modification</em>{% if event.modified_by_user %} par {{ event.modified_by_user.username }}{% endif %}{% endif %}
|
||||
{% if step.data == "moderated_date" %}<em>dernière modération</em>{% if event.moderated_by_user %} par {{ event.moderated_by_user.username }}{% endif %}{% endif %}
|
||||
{% if step.data == "imported_date" %}<em>dernière importation</em>{% if event.imported_by_user %} par {{ event.imported_by_user.username }}{% endif %}{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
@ -56,6 +56,11 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<form method="post">{% csrf_token %}
|
||||
{{ form.media }}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Commenter">
|
||||
</form>
|
||||
|
||||
{% include "agenda_culturel/event-info-inc.html" with allbutdates=1 %}
|
||||
</article>
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView, ModelFormMixin
|
||||
from django.contrib.auth.mixins import (
|
||||
LoginRequiredMixin,
|
||||
UserPassesTestMixin,
|
||||
@ -44,6 +44,7 @@ from .forms import (
|
||||
TagForm,
|
||||
TagRenameForm,
|
||||
MessageForm,
|
||||
MessageEventForm,
|
||||
)
|
||||
|
||||
from .filters import (
|
||||
@ -469,8 +470,9 @@ class EventDeleteView(
|
||||
success_message = _("The event has been successfully deleted.")
|
||||
|
||||
|
||||
class EventDetailView(UserPassesTestMixin, DetailView):
|
||||
class EventDetailView(UserPassesTestMixin, DetailView, ModelFormMixin):
|
||||
model = Event
|
||||
form_class = MessageEventForm
|
||||
template_name = "agenda_culturel/page-event.html"
|
||||
queryset = Event.objects.select_related("exact_location").select_related("category").select_related("other_versions").select_related("other_versions__representative").prefetch_related("message_set")
|
||||
|
||||
@ -490,6 +492,32 @@ class EventDetailView(UserPassesTestMixin, DetailView):
|
||||
obj.set_current_date(date(y, m, d))
|
||||
return obj
|
||||
|
||||
def get_success_url(self):
|
||||
return self.get_object().get_absolute_url() + "#chronology"
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated:
|
||||
return HttpResponseForbidden()
|
||||
form = self.get_form()
|
||||
if form.is_valid():
|
||||
return self.form_valid(form)
|
||||
else:
|
||||
return self.form_invalid(form)
|
||||
|
||||
def form_valid(self, form):
|
||||
logger.warning("on form valide")
|
||||
message = form.save(commit=False)
|
||||
message.user = self.request.user
|
||||
message.related_event = self.get_object()
|
||||
message.subject = _("Comment")
|
||||
message.spam = False
|
||||
message.closed = True
|
||||
message.save()
|
||||
logger.warning("on save " + str(message))
|
||||
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
||||
@login_required(login_url="/accounts/login/")
|
||||
|
Loading…
Reference in New Issue
Block a user