On renomme la classe ContactMessage en Message
This commit is contained in:
parent
b1e5414519
commit
c1f7bfd8c4
@ -9,7 +9,7 @@ from .models import (
|
||||
BatchImportation,
|
||||
RecurrentImport,
|
||||
Place,
|
||||
ContactMessage,
|
||||
Message,
|
||||
ReferenceLocation,
|
||||
Organisation
|
||||
)
|
||||
@ -25,7 +25,7 @@ admin.site.register(DuplicatedEvents)
|
||||
admin.site.register(BatchImportation)
|
||||
admin.site.register(RecurrentImport)
|
||||
admin.site.register(Place)
|
||||
admin.site.register(ContactMessage)
|
||||
admin.site.register(Message)
|
||||
admin.site.register(ReferenceLocation)
|
||||
admin.site.register(Organisation)
|
||||
|
||||
|
@ -44,7 +44,7 @@ from .models import (
|
||||
Tag,
|
||||
Event,
|
||||
Category,
|
||||
ContactMessage,
|
||||
Message,
|
||||
DuplicatedEvents
|
||||
)
|
||||
|
||||
@ -361,7 +361,7 @@ class EventFilterAdmin(django_filters.FilterSet):
|
||||
fields = ["status"]
|
||||
|
||||
|
||||
class ContactMessagesFilterAdmin(django_filters.FilterSet):
|
||||
class MessagesFilterAdmin(django_filters.FilterSet):
|
||||
closed = django_filters.MultipleChoiceFilter(
|
||||
label="Status",
|
||||
choices=((True, _("Closed")), (False, _("Open"))),
|
||||
@ -374,7 +374,7 @@ class ContactMessagesFilterAdmin(django_filters.FilterSet):
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = ContactMessage
|
||||
model = Message
|
||||
fields = ["closed", "spam"]
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ from .models import (
|
||||
Place,
|
||||
Category,
|
||||
Tag,
|
||||
ContactMessage
|
||||
Message
|
||||
)
|
||||
from django.conf import settings
|
||||
from django.core.files import File
|
||||
@ -783,10 +783,10 @@ class PlaceForm(GroupFormMixin, ModelForm):
|
||||
def apply(self):
|
||||
return self.cleaned_data.get("apply_to_all")
|
||||
|
||||
class ContactMessageForm(ModelForm):
|
||||
class MessageForm(ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ContactMessage
|
||||
model = Message
|
||||
fields = ["subject", "name", "email", "message", "related_event"]
|
||||
widgets = {"related_event": HiddenInput()}
|
||||
|
||||
|
@ -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'},
|
||||
),
|
||||
]
|
@ -1741,10 +1741,10 @@ class Event(models.Model):
|
||||
return [Event.get_count_modification(w) for w in when_list]
|
||||
|
||||
|
||||
class ContactMessage(models.Model):
|
||||
class Message(models.Model):
|
||||
class Meta:
|
||||
verbose_name = _("Contact message")
|
||||
verbose_name_plural = _("Contact messages")
|
||||
verbose_name = _("Message")
|
||||
verbose_name_plural = _("Messages")
|
||||
|
||||
subject = models.CharField(
|
||||
verbose_name=_("Subject"),
|
||||
@ -1800,11 +1800,11 @@ class ContactMessage(models.Model):
|
||||
null=True,
|
||||
)
|
||||
|
||||
def nb_open_contactmessages():
|
||||
return ContactMessage.objects.filter(closed=False).count()
|
||||
def nb_open_messages():
|
||||
return Message.objects.filter(closed=False).count()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("contactmessage", kwargs={"pk": self.pk})
|
||||
return reverse("message", kwargs={"pk": self.pk})
|
||||
|
||||
|
||||
class RecurrentImport(models.Model):
|
||||
|
@ -24,7 +24,7 @@
|
||||
<article>
|
||||
<header>
|
||||
<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>
|
||||
|
||||
<h1>Modération du message « {{ object.subject }} »</h1>
|
||||
@ -47,7 +47,7 @@
|
||||
</article>
|
||||
</div>
|
||||
|
||||
{% include "agenda_culturel/side-nav.html" with current="contactmessages" %}
|
||||
{% include "agenda_culturel/side-nav.html" with current="messages" %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -45,7 +45,7 @@
|
||||
{% for obj in paginator_filter %}
|
||||
<tr>
|
||||
<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>{% 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>
|
||||
@ -59,7 +59,7 @@
|
||||
</footer>
|
||||
</article>
|
||||
|
||||
{% include "agenda_culturel/side-nav.html" with current="contactmessages" %}
|
||||
{% include "agenda_culturel/side-nav.html" with current="messages" %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -2,7 +2,7 @@
|
||||
<html lang="fr">
|
||||
{% load event_extra %}
|
||||
{% load cache %}
|
||||
{% load contactmessages_extra %}
|
||||
{% load messages_extra %}
|
||||
{% load utils_extra %}
|
||||
{% load duplicated_extra %}
|
||||
{% load rimports_extra %}
|
||||
@ -77,8 +77,8 @@
|
||||
{% if perms.agenda_culturel.change_place and perms.agenda_culturel.change_event %}
|
||||
{% show_badge_unknown_places "bottom" %}
|
||||
{% endif %}
|
||||
{% if perms.agenda_culturel.view_contactmessage %}
|
||||
{% show_badge_contactmessages "bottom" %}
|
||||
{% if perms.agenda_culturel.view_message %}
|
||||
{% show_badge_messages "bottom" %}
|
||||
{% endif %}
|
||||
{% if user.is_authenticated %}
|
||||
{{ user.username }} @
|
||||
|
@ -1,5 +1,5 @@
|
||||
{% load event_extra %}
|
||||
{% load contactmessages_extra %}
|
||||
{% load messages_extra %}
|
||||
{% load duplicated_extra %}
|
||||
{% load utils_extra %}
|
||||
<aside id="sidebar">
|
||||
@ -56,11 +56,11 @@
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% if perms.agenda_culturel.view_contactmessage %}
|
||||
{% if perms.agenda_culturel.view_message %}
|
||||
<h3>Messages</h3>
|
||||
<nav>
|
||||
<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>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
@ -76,10 +76,10 @@
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if perms.agenda_culturel.change_contactmessage %}
|
||||
{% if event.contactmessage_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 %}
|
||||
{% for cm in event.contactmessage_set.all %}
|
||||
{% if perms.agenda_culturel.change_message %}
|
||||
{% if event.message_set.all.count > 0 %}
|
||||
<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.message_set.all %}
|
||||
<a href="{{ cm.get_absolute_url }}">le {{ cm.date.date }} à {{ cm.date.time }}</a>{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
</p>
|
||||
|
@ -4,7 +4,7 @@ from django.urls import reverse_lazy
|
||||
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
|
||||
|
||||
@ -12,12 +12,12 @@ register = template.Library()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def show_badge_contactmessages(placement="top"):
|
||||
nb_open = ContactMessage.nb_open_contactmessages()
|
||||
def show_badge_messages(placement="top"):
|
||||
nb_open = Message.nb_open_messages()
|
||||
if nb_open != 0:
|
||||
return mark_safe(
|
||||
'<a href="'
|
||||
+ reverse_lazy("contactmessages")
|
||||
+ reverse_lazy("messages")
|
||||
+ '?closed=False" class="badge" data-placement="'
|
||||
+ placement
|
||||
+ '" data-tooltip="'
|
@ -62,7 +62,7 @@ urlpatterns = [
|
||||
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>/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>/change-status/<status>",
|
||||
@ -97,18 +97,18 @@ urlpatterns = [
|
||||
path("mentions-legales", mentions_legales, name="mentions_legales"),
|
||||
path("a-propos", about, name="about"),
|
||||
path("merci", thank_you, name="thank_you"),
|
||||
path("contact", ContactMessageCreateView.as_view(), name="contact"),
|
||||
path("contactmessages", contactmessages, name="contactmessages"),
|
||||
path("contactmessages/spams/delete", delete_cm_spam, name="delete_cm_spam"),
|
||||
path("contact", MessageCreateView.as_view(), name="contact"),
|
||||
path("messages", messages, name="messages"),
|
||||
path("messages/spams/delete", delete_cm_spam, name="delete_cm_spam"),
|
||||
path(
|
||||
"contactmessage/<int:pk>",
|
||||
ContactMessageUpdateView.as_view(),
|
||||
name="contactmessage",
|
||||
"message/<int:pk>",
|
||||
MessageUpdateView.as_view(),
|
||||
name="message",
|
||||
),
|
||||
path(
|
||||
"contactmessage/<int:pk>/delete",
|
||||
ContactMessageDeleteView.as_view(),
|
||||
name="delete_contactmessage",
|
||||
"message/<int:pk>/delete",
|
||||
MessageDeleteView.as_view(),
|
||||
name="delete_message",
|
||||
),
|
||||
path("imports/", imports, name="imports"),
|
||||
path("imports/add", add_import, name="add_import"),
|
||||
|
@ -43,13 +43,13 @@ from .forms import (
|
||||
EventModerateForm,
|
||||
TagForm,
|
||||
TagRenameForm,
|
||||
ContactMessageForm,
|
||||
MessageForm,
|
||||
)
|
||||
|
||||
from .filters import (
|
||||
EventFilter,
|
||||
EventFilterAdmin,
|
||||
ContactMessagesFilterAdmin,
|
||||
MessagesFilterAdmin,
|
||||
SimpleSearchEventFilter,
|
||||
SearchEventFilter,
|
||||
DuplicatedEventsFilter,
|
||||
@ -61,7 +61,7 @@ from .models import (
|
||||
Category,
|
||||
Tag,
|
||||
StaticContent,
|
||||
ContactMessage,
|
||||
Message,
|
||||
BatchImportation,
|
||||
DuplicatedEvents,
|
||||
RecurrentImport,
|
||||
@ -745,10 +745,10 @@ def export_ical(request):
|
||||
|
||||
|
||||
@method_decorator(check_honeypot, name='post')
|
||||
class ContactMessageCreateView(SuccessMessageMixin, CreateView):
|
||||
model = ContactMessage
|
||||
template_name = "agenda_culturel/contactmessage_create_form.html"
|
||||
form_class = ContactMessageForm
|
||||
class MessageCreateView(SuccessMessageMixin, CreateView):
|
||||
model = Message
|
||||
template_name = "agenda_culturel/message_create_form.html"
|
||||
form_class = MessageForm
|
||||
|
||||
success_url = reverse_lazy("home")
|
||||
success_message = _("Your message has been sent successfully.")
|
||||
@ -779,27 +779,27 @@ class ContactMessageCreateView(SuccessMessageMixin, CreateView):
|
||||
|
||||
|
||||
|
||||
class ContactMessageDeleteView(SuccessMessageMixin, DeleteView):
|
||||
model = ContactMessage
|
||||
class MessageDeleteView(SuccessMessageMixin, DeleteView):
|
||||
model = Message
|
||||
success_message = _(
|
||||
"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
|
||||
):
|
||||
model = ContactMessage
|
||||
permission_required = "agenda_culturel.change_contactmessage"
|
||||
template_name = "agenda_culturel/contactmessage_moderation_form.html"
|
||||
model = Message
|
||||
permission_required = "agenda_culturel.change_message"
|
||||
template_name = "agenda_culturel/message_moderation_form.html"
|
||||
fields = ("spam", "closed", "comments")
|
||||
|
||||
success_message = _(
|
||||
"The contact message properties has been successfully modified."
|
||||
)
|
||||
|
||||
success_url = reverse_lazy("contactmessages")
|
||||
success_url = reverse_lazy("messages")
|
||||
|
||||
def get_form_kwargs(self):
|
||||
"""Return the keyword arguments for instantiating the form."""
|
||||
@ -903,15 +903,15 @@ def recent(request):
|
||||
|
||||
|
||||
@login_required(login_url="/accounts/login/")
|
||||
@permission_required("agenda_culturel.view_contactmessage")
|
||||
def contactmessages(request):
|
||||
filter = ContactMessagesFilterAdmin(
|
||||
request.GET, queryset=ContactMessage.objects.all().order_by("-date")
|
||||
@permission_required("agenda_culturel.view_message")
|
||||
def messages(request):
|
||||
filter = MessagesFilterAdmin(
|
||||
request.GET, queryset=Message.objects.all().order_by("-date")
|
||||
)
|
||||
paginator = PaginatorFilter(filter, 10, request)
|
||||
page = request.GET.get("page")
|
||||
|
||||
nb_spams = ContactMessage.objects.filter(spam=True).count()
|
||||
nb_spams = Message.objects.filter(spam=True).count()
|
||||
|
||||
try:
|
||||
response = paginator.page(page)
|
||||
@ -922,24 +922,24 @@ def contactmessages(request):
|
||||
|
||||
return render(
|
||||
request,
|
||||
"agenda_culturel/contactmessages.html",
|
||||
"agenda_culturel/messages.html",
|
||||
{"filter": filter, "nb_spams": nb_spams, "paginator_filter": response},
|
||||
)
|
||||
|
||||
@login_required(login_url="/accounts/login/")
|
||||
@permission_required("agenda_culturel.view_contactmessage")
|
||||
@permission_required("agenda_culturel.view_message")
|
||||
def delete_cm_spam(request):
|
||||
|
||||
if request.method == "POST":
|
||||
ContactMessage.objects.filter(spam=True).delete()
|
||||
Message.objects.filter(spam=True).delete()
|
||||
|
||||
messages.success(request, _("Spam has been successfully deleted."))
|
||||
return HttpResponseRedirect(reverse_lazy("contactmessages"))
|
||||
return HttpResponseRedirect(reverse_lazy("messages"))
|
||||
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_spams = sum([nb["total"] for nb in nb_msgs if nb["spam"]])
|
||||
cancel_url = reverse_lazy("contactmessages")
|
||||
cancel_url = reverse_lazy("messages")
|
||||
return render(
|
||||
request,
|
||||
"agenda_culturel/delete_spams_confirm.html",
|
||||
|
@ -1,5 +1,5 @@
|
||||
from agenda_culturel.models import ContactMessage
|
||||
from agenda_culturel.models import Message
|
||||
|
||||
|
||||
def run():
|
||||
ContactMessage.objects.all().update(spam=True)
|
||||
Message.objects.all().update(spam=True)
|
||||
|
Loading…
Reference in New Issue
Block a user