On renomme la classe ContactMessage en Message

This commit is contained in:
Jean-Marie Favreau 2024-12-11 11:36:40 +01:00
parent b1e5414519
commit c1f7bfd8c4
16 changed files with 91 additions and 70 deletions

View File

@ -9,7 +9,7 @@ from .models import (
BatchImportation, BatchImportation,
RecurrentImport, RecurrentImport,
Place, Place,
ContactMessage, Message,
ReferenceLocation, ReferenceLocation,
Organisation Organisation
) )
@ -25,7 +25,7 @@ admin.site.register(DuplicatedEvents)
admin.site.register(BatchImportation) admin.site.register(BatchImportation)
admin.site.register(RecurrentImport) admin.site.register(RecurrentImport)
admin.site.register(Place) admin.site.register(Place)
admin.site.register(ContactMessage) admin.site.register(Message)
admin.site.register(ReferenceLocation) admin.site.register(ReferenceLocation)
admin.site.register(Organisation) admin.site.register(Organisation)

View File

@ -44,7 +44,7 @@ from .models import (
Tag, Tag,
Event, Event,
Category, Category,
ContactMessage, Message,
DuplicatedEvents DuplicatedEvents
) )
@ -361,7 +361,7 @@ class EventFilterAdmin(django_filters.FilterSet):
fields = ["status"] fields = ["status"]
class ContactMessagesFilterAdmin(django_filters.FilterSet): class MessagesFilterAdmin(django_filters.FilterSet):
closed = django_filters.MultipleChoiceFilter( closed = django_filters.MultipleChoiceFilter(
label="Status", label="Status",
choices=((True, _("Closed")), (False, _("Open"))), choices=((True, _("Closed")), (False, _("Open"))),
@ -374,7 +374,7 @@ class ContactMessagesFilterAdmin(django_filters.FilterSet):
) )
class Meta: class Meta:
model = ContactMessage model = Message
fields = ["closed", "spam"] fields = ["closed", "spam"]

View File

@ -24,7 +24,7 @@ from .models import (
Place, Place,
Category, Category,
Tag, Tag,
ContactMessage Message
) )
from django.conf import settings from django.conf import settings
from django.core.files import File from django.core.files import File
@ -783,10 +783,10 @@ class PlaceForm(GroupFormMixin, ModelForm):
def apply(self): def apply(self):
return self.cleaned_data.get("apply_to_all") return self.cleaned_data.get("apply_to_all")
class ContactMessageForm(ModelForm): class MessageForm(ModelForm):
class Meta: class Meta:
model = ContactMessage model = Message
fields = ["subject", "name", "email", "message", "related_event"] fields = ["subject", "name", "email", "message", "related_event"]
widgets = {"related_event": HiddenInput()} widgets = {"related_event": HiddenInput()}

View File

@ -0,0 +1,21 @@
# Generated by Django 4.2.9 on 2024-12-11 11:33
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0124_place_postcode'),
]
operations = [
migrations.RenameModel(
old_name='ContactMessage',
new_name='Message',
),
migrations.AlterModelOptions(
name='message',
options={'verbose_name': 'Message', 'verbose_name_plural': 'Messages'},
),
]

View File

@ -1741,10 +1741,10 @@ class Event(models.Model):
return [Event.get_count_modification(w) for w in when_list] return [Event.get_count_modification(w) for w in when_list]
class ContactMessage(models.Model): class Message(models.Model):
class Meta: class Meta:
verbose_name = _("Contact message") verbose_name = _("Message")
verbose_name_plural = _("Contact messages") verbose_name_plural = _("Messages")
subject = models.CharField( subject = models.CharField(
verbose_name=_("Subject"), verbose_name=_("Subject"),
@ -1800,11 +1800,11 @@ class ContactMessage(models.Model):
null=True, null=True,
) )
def nb_open_contactmessages(): def nb_open_messages():
return ContactMessage.objects.filter(closed=False).count() return Message.objects.filter(closed=False).count()
def get_absolute_url(self): def get_absolute_url(self):
return reverse("contactmessage", kwargs={"pk": self.pk}) return reverse("message", kwargs={"pk": self.pk})
class RecurrentImport(models.Model): class RecurrentImport(models.Model):

View File

@ -24,7 +24,7 @@
<article> <article>
<header> <header>
<div class="slide-buttons"> <div class="slide-buttons">
<a href="{% url 'delete_contactmessage' object.id %}" role="button" data-tooltip="Supprimer le message">Supprimer {% picto_from_name "trash-2" %}</a> <a href="{% url 'delete_message' object.id %}" role="button" data-tooltip="Supprimer le message">Supprimer {% picto_from_name "trash-2" %}</a>
</div> </div>
<h1>Modération du message «&nbsp;{{ object.subject }}&nbsp;»</h1> <h1>Modération du message «&nbsp;{{ object.subject }}&nbsp;»</h1>
@ -47,7 +47,7 @@
</article> </article>
</div> </div>
{% include "agenda_culturel/side-nav.html" with current="contactmessages" %} {% include "agenda_culturel/side-nav.html" with current="messages" %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -45,7 +45,7 @@
{% for obj in paginator_filter %} {% for obj in paginator_filter %}
<tr> <tr>
<td>{{ obj.date }}</td> <td>{{ obj.date }}</td>
<td><a href="{% url 'contactmessage' obj.pk %}">{{ obj.subject }}</a></td> <td><a href="{% url 'message' obj.pk %}">{{ obj.subject }}</a></td>
<td>{{ obj.name }}</td> <td>{{ obj.name }}</td>
<td>{% if obj.related_event %}<a href="{{ obj.related_event.get_absolute_url }}">{{ obj.related_event.pk }}</a>{% else %}/{% endif %}</td> <td>{% if obj.related_event %}<a href="{{ obj.related_event.get_absolute_url }}">{{ obj.related_event.pk }}</a>{% else %}/{% endif %}</td>
<td>{% if obj.closed %}{% picto_from_name "check-square" "fermé" %}{% else %}{% picto_from_name "square" "ouvert" %}{% endif %}</td> <td>{% if obj.closed %}{% picto_from_name "check-square" "fermé" %}{% else %}{% picto_from_name "square" "ouvert" %}{% endif %}</td>
@ -59,7 +59,7 @@
</footer> </footer>
</article> </article>
{% include "agenda_culturel/side-nav.html" with current="contactmessages" %} {% include "agenda_culturel/side-nav.html" with current="messages" %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -2,7 +2,7 @@
<html lang="fr"> <html lang="fr">
{% load event_extra %} {% load event_extra %}
{% load cache %} {% load cache %}
{% load contactmessages_extra %} {% load messages_extra %}
{% load utils_extra %} {% load utils_extra %}
{% load duplicated_extra %} {% load duplicated_extra %}
{% load rimports_extra %} {% load rimports_extra %}
@ -77,8 +77,8 @@
{% if perms.agenda_culturel.change_place and perms.agenda_culturel.change_event %} {% if perms.agenda_culturel.change_place and perms.agenda_culturel.change_event %}
{% show_badge_unknown_places "bottom" %} {% show_badge_unknown_places "bottom" %}
{% endif %} {% endif %}
{% if perms.agenda_culturel.view_contactmessage %} {% if perms.agenda_culturel.view_message %}
{% show_badge_contactmessages "bottom" %} {% show_badge_messages "bottom" %}
{% endif %} {% endif %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
{{ user.username }} @ {{ user.username }} @

View File

@ -1,5 +1,5 @@
{% load event_extra %} {% load event_extra %}
{% load contactmessages_extra %} {% load messages_extra %}
{% load duplicated_extra %} {% load duplicated_extra %}
{% load utils_extra %} {% load utils_extra %}
<aside id="sidebar"> <aside id="sidebar">
@ -56,11 +56,11 @@
</ul> </ul>
</nav> </nav>
{% endif %} {% endif %}
{% if perms.agenda_culturel.view_contactmessage %} {% if perms.agenda_culturel.view_message %}
<h3>Messages</h3> <h3>Messages</h3>
<nav> <nav>
<ul> <ul>
<li><a {% if current == "contactmessages" %}class="selected" {% endif %}href="{% url 'contactmessages' %}">Messages de contact</a>{% show_badge_contactmessages "left" %}</li> <li><a {% if current == "messages" %}class="selected" {% endif %}href="{% url 'messages' %}">Messages de contact</a>{% show_badge_messages "left" %}</li>
</ul> </ul>
</nav> </nav>
{% endif %} {% endif %}

View File

@ -76,10 +76,10 @@
</p> </p>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if perms.agenda_culturel.change_contactmessage %} {% if perms.agenda_culturel.change_message %}
{% if event.contactmessage_set.all.count > 0 %} {% if event.message_set.all.count > 0 %}
<p class="remarque">Cet événement a fait l'objet {% if event.contactmessage_set.all.count == 1 %}d'un signalement{% else %}de signalements{% endif %} <p class="remarque">Cet événement a fait l'objet {% if event.message_set.all.count == 1 %}d'un signalement{% else %}de signalements{% endif %}
{% for cm in event.contactmessage_set.all %} {% for cm in event.message_set.all %}
<a href="{{ cm.get_absolute_url }}">le {{ cm.date.date }} à {{ cm.date.time }}</a>{% if not forloop.last %}, {% endif %} <a href="{{ cm.get_absolute_url }}">le {{ cm.date.date }} à {{ cm.date.time }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %} {% endfor %}
</p> </p>

View File

@ -4,7 +4,7 @@ from django.urls import reverse_lazy
from django.template.defaultfilters import pluralize from django.template.defaultfilters import pluralize
from agenda_culturel.models import ContactMessage from agenda_culturel.models import Message
from .utils_extra import picto_from_name from .utils_extra import picto_from_name
@ -12,12 +12,12 @@ register = template.Library()
@register.simple_tag @register.simple_tag
def show_badge_contactmessages(placement="top"): def show_badge_messages(placement="top"):
nb_open = ContactMessage.nb_open_contactmessages() nb_open = Message.nb_open_messages()
if nb_open != 0: if nb_open != 0:
return mark_safe( return mark_safe(
'<a href="' '<a href="'
+ reverse_lazy("contactmessages") + reverse_lazy("messages")
+ '?closed=False" class="badge" data-placement="' + '?closed=False" class="badge" data-placement="'
+ placement + placement
+ '" data-tooltip="' + '" data-tooltip="'

View File

@ -62,7 +62,7 @@ urlpatterns = [
path("moderate", EventModerateView.as_view(), name="moderate"), path("moderate", EventModerateView.as_view(), name="moderate"),
path("event/<int:pk>/simple-clone/edit", EventUpdateView.as_view(), name="simple_clone_edit"), path("event/<int:pk>/simple-clone/edit", EventUpdateView.as_view(), name="simple_clone_edit"),
path("event/<int:pk>/clone/edit", EventUpdateView.as_view(), name="clone_edit"), path("event/<int:pk>/clone/edit", EventUpdateView.as_view(), name="clone_edit"),
path("event/<int:pk>/message", ContactMessageCreateView.as_view(), name="message_for_event"), path("event/<int:pk>/message", MessageCreateView.as_view(), name="message_for_event"),
path("event/<int:pk>/update-from-source", update_from_source, name="update_from_source"), path("event/<int:pk>/update-from-source", update_from_source, name="update_from_source"),
path( path(
"event/<int:pk>/change-status/<status>", "event/<int:pk>/change-status/<status>",
@ -97,18 +97,18 @@ urlpatterns = [
path("mentions-legales", mentions_legales, name="mentions_legales"), path("mentions-legales", mentions_legales, name="mentions_legales"),
path("a-propos", about, name="about"), path("a-propos", about, name="about"),
path("merci", thank_you, name="thank_you"), path("merci", thank_you, name="thank_you"),
path("contact", ContactMessageCreateView.as_view(), name="contact"), path("contact", MessageCreateView.as_view(), name="contact"),
path("contactmessages", contactmessages, name="contactmessages"), path("messages", messages, name="messages"),
path("contactmessages/spams/delete", delete_cm_spam, name="delete_cm_spam"), path("messages/spams/delete", delete_cm_spam, name="delete_cm_spam"),
path( path(
"contactmessage/<int:pk>", "message/<int:pk>",
ContactMessageUpdateView.as_view(), MessageUpdateView.as_view(),
name="contactmessage", name="message",
), ),
path( path(
"contactmessage/<int:pk>/delete", "message/<int:pk>/delete",
ContactMessageDeleteView.as_view(), MessageDeleteView.as_view(),
name="delete_contactmessage", name="delete_message",
), ),
path("imports/", imports, name="imports"), path("imports/", imports, name="imports"),
path("imports/add", add_import, name="add_import"), path("imports/add", add_import, name="add_import"),

View File

@ -43,13 +43,13 @@ from .forms import (
EventModerateForm, EventModerateForm,
TagForm, TagForm,
TagRenameForm, TagRenameForm,
ContactMessageForm, MessageForm,
) )
from .filters import ( from .filters import (
EventFilter, EventFilter,
EventFilterAdmin, EventFilterAdmin,
ContactMessagesFilterAdmin, MessagesFilterAdmin,
SimpleSearchEventFilter, SimpleSearchEventFilter,
SearchEventFilter, SearchEventFilter,
DuplicatedEventsFilter, DuplicatedEventsFilter,
@ -61,7 +61,7 @@ from .models import (
Category, Category,
Tag, Tag,
StaticContent, StaticContent,
ContactMessage, Message,
BatchImportation, BatchImportation,
DuplicatedEvents, DuplicatedEvents,
RecurrentImport, RecurrentImport,
@ -745,10 +745,10 @@ def export_ical(request):
@method_decorator(check_honeypot, name='post') @method_decorator(check_honeypot, name='post')
class ContactMessageCreateView(SuccessMessageMixin, CreateView): class MessageCreateView(SuccessMessageMixin, CreateView):
model = ContactMessage model = Message
template_name = "agenda_culturel/contactmessage_create_form.html" template_name = "agenda_culturel/message_create_form.html"
form_class = ContactMessageForm form_class = MessageForm
success_url = reverse_lazy("home") success_url = reverse_lazy("home")
success_message = _("Your message has been sent successfully.") success_message = _("Your message has been sent successfully.")
@ -779,27 +779,27 @@ class ContactMessageCreateView(SuccessMessageMixin, CreateView):
class ContactMessageDeleteView(SuccessMessageMixin, DeleteView): class MessageDeleteView(SuccessMessageMixin, DeleteView):
model = ContactMessage model = Message
success_message = _( success_message = _(
"The contact message has been successfully deleted." "The contact message has been successfully deleted."
) )
success_url = reverse_lazy("contactmessages") success_url = reverse_lazy("messages")
class ContactMessageUpdateView( class MessageUpdateView(
SuccessMessageMixin, PermissionRequiredMixin, LoginRequiredMixin, UpdateView SuccessMessageMixin, PermissionRequiredMixin, LoginRequiredMixin, UpdateView
): ):
model = ContactMessage model = Message
permission_required = "agenda_culturel.change_contactmessage" permission_required = "agenda_culturel.change_message"
template_name = "agenda_culturel/contactmessage_moderation_form.html" template_name = "agenda_culturel/message_moderation_form.html"
fields = ("spam", "closed", "comments") fields = ("spam", "closed", "comments")
success_message = _( success_message = _(
"The contact message properties has been successfully modified." "The contact message properties has been successfully modified."
) )
success_url = reverse_lazy("contactmessages") success_url = reverse_lazy("messages")
def get_form_kwargs(self): def get_form_kwargs(self):
"""Return the keyword arguments for instantiating the form.""" """Return the keyword arguments for instantiating the form."""
@ -903,15 +903,15 @@ def recent(request):
@login_required(login_url="/accounts/login/") @login_required(login_url="/accounts/login/")
@permission_required("agenda_culturel.view_contactmessage") @permission_required("agenda_culturel.view_message")
def contactmessages(request): def messages(request):
filter = ContactMessagesFilterAdmin( filter = MessagesFilterAdmin(
request.GET, queryset=ContactMessage.objects.all().order_by("-date") request.GET, queryset=Message.objects.all().order_by("-date")
) )
paginator = PaginatorFilter(filter, 10, request) paginator = PaginatorFilter(filter, 10, request)
page = request.GET.get("page") page = request.GET.get("page")
nb_spams = ContactMessage.objects.filter(spam=True).count() nb_spams = Message.objects.filter(spam=True).count()
try: try:
response = paginator.page(page) response = paginator.page(page)
@ -922,24 +922,24 @@ def contactmessages(request):
return render( return render(
request, request,
"agenda_culturel/contactmessages.html", "agenda_culturel/messages.html",
{"filter": filter, "nb_spams": nb_spams, "paginator_filter": response}, {"filter": filter, "nb_spams": nb_spams, "paginator_filter": response},
) )
@login_required(login_url="/accounts/login/") @login_required(login_url="/accounts/login/")
@permission_required("agenda_culturel.view_contactmessage") @permission_required("agenda_culturel.view_message")
def delete_cm_spam(request): def delete_cm_spam(request):
if request.method == "POST": if request.method == "POST":
ContactMessage.objects.filter(spam=True).delete() Message.objects.filter(spam=True).delete()
messages.success(request, _("Spam has been successfully deleted.")) messages.success(request, _("Spam has been successfully deleted."))
return HttpResponseRedirect(reverse_lazy("contactmessages")) return HttpResponseRedirect(reverse_lazy("messages"))
else: else:
nb_msgs = ContactMessage.objects.values('spam').annotate(total=Count('spam')) nb_msgs = Message.objects.values('spam').annotate(total=Count('spam'))
nb_total = sum([nb["total"] for nb in nb_msgs]) nb_total = sum([nb["total"] for nb in nb_msgs])
nb_spams = sum([nb["total"] for nb in nb_msgs if nb["spam"]]) nb_spams = sum([nb["total"] for nb in nb_msgs if nb["spam"]])
cancel_url = reverse_lazy("contactmessages") cancel_url = reverse_lazy("messages")
return render( return render(
request, request,
"agenda_culturel/delete_spams_confirm.html", "agenda_culturel/delete_spams_confirm.html",

View File

@ -1,5 +1,5 @@
from agenda_culturel.models import ContactMessage from agenda_culturel.models import Message
def run(): def run():
ContactMessage.objects.all().update(spam=True) Message.objects.all().update(spam=True)