On envoie une notification à la personne qui a proposé l'événement en cas de modération
Fix #209
This commit is contained in:
parent
4b55830419
commit
eef4f5639c
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,11 @@ from django.core.cache.utils import make_template_fragment_key
|
||||
from django.contrib.auth.models import User, AnonymousUser
|
||||
import emoji
|
||||
from django.core.files.storage import default_storage
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.mail import send_mail
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
||||
import uuid
|
||||
|
||||
import hashlib
|
||||
@ -939,7 +944,6 @@ class Event(models.Model):
|
||||
|
||||
def download_missing_image(self):
|
||||
if self.local_image and not default_storage.exists(self.local_image.name):
|
||||
logger.warning("on dl")
|
||||
self.download_image()
|
||||
self.save(update_fields=["local_image"])
|
||||
|
||||
@ -1144,6 +1148,36 @@ class Event(models.Model):
|
||||
if not self.category or self.category.name == Category.default_name:
|
||||
CategorisationRule.apply_rules(self)
|
||||
|
||||
|
||||
def get_contributor_message(self):
|
||||
msg = Message.objects.filter(related_event=self.pk, email__isnull=False, closed=False).first()
|
||||
if msg is None:
|
||||
msg = Message.objects.filter(related_event__in=self.other_versions.get_duplicated(), email__isnull=False, closed=False).first()
|
||||
return msg
|
||||
|
||||
|
||||
def notify_if_required(self, request):
|
||||
if self.status != Event.STATUS.DRAFT:
|
||||
message = self.get_contributor_message()
|
||||
if message and not message.closed and message.email:
|
||||
# send email
|
||||
context = {"sitename": Site.objects.get_current(request).name, 'event_title': self.title }
|
||||
if self.status == Event.STATUS.PUBLISHED:
|
||||
context["url"] = request.build_absolute_uri(self.get_absolute_url())
|
||||
subject = _('Your event has been published')
|
||||
body = render_to_string("agenda_culturel/emails/published.txt", context)
|
||||
else:
|
||||
subject = _('Your message has not been retained')
|
||||
body = render_to_string("agenda_culturel/emails/retained.txt", context)
|
||||
|
||||
send_mail(subject, body, None, [message.email])
|
||||
message.closed = True
|
||||
message.save()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.prepare_save()
|
||||
|
||||
@ -1177,6 +1211,10 @@ class Event(models.Model):
|
||||
# first save the current object
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# notify only if required (and request is known)
|
||||
if "request" in kwargs:
|
||||
self.notify_if_required(kwargs.get("request"))
|
||||
|
||||
# clear cache
|
||||
for is_auth in [False, True]:
|
||||
key = make_template_fragment_key("event_body", [is_auth, self])
|
||||
@ -1285,7 +1323,7 @@ class Event(models.Model):
|
||||
result = Event(**event_structure)
|
||||
result.add_pending_organisers(organisers)
|
||||
if email or comments:
|
||||
result.set_message(Message(subject=_('during import process'), email=email, message=comments))
|
||||
result.set_message(Message(subject=_('during import process'), email=email, message=comments, closed=False))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
Bonjour,
|
||||
|
||||
Nous avons le plaisir de t'informer que l'événement « {{ event_title }} » que tu as proposé sur {{ sitename }} a été validé et publié par l'équipe de modération.
|
||||
Tu peux dès maintenant le retrouver à l'adresse suivante :
|
||||
- {{ url }}
|
||||
|
||||
Merci de participer à l'amélioration de {{ sitename }}. N'hésites pas à continuer à contribuer en ajoutant de nouveaux événements, ça nous fait bien plaisir.
|
||||
|
||||
L'équipe de modération.
|
@ -0,0 +1,8 @@
|
||||
Bonjour,
|
||||
|
||||
Nous avons la dure tâche de t'informer que l'événement « {{ event_title }} » que tu avais proposé sur {{ sitename }} n'a pas été retenu par l'équipe de modération.
|
||||
|
||||
Nous te remercions pour cette proposition, et espérons qu'une prochaine fois, ta proposition correspondra à la ligne portée par {{ sitename }}.
|
||||
|
||||
L'équipe de modération.
|
||||
|
@ -46,8 +46,8 @@
|
||||
<tr>
|
||||
<td>{{ obj.date }}</td>
|
||||
<td><a href="{% url 'message' obj.pk %}">{{ obj.subject }}</a></td>
|
||||
<td>{% if obj.user %}<em>{{ obj.user }}</em>{% else %}{{ obj.name }}{% 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.user %}<em>{{ obj.user }}</em>{% else %}{% if obj.name %}{{ obj.name }}{% else %}-{% endif %}{% 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.spam %}{% picto_from_name "check-square" "spam" %}{% else %}{% picto_from_name "square" "non spam" %}{% endif %}</td>
|
||||
</tr>
|
||||
|
@ -78,7 +78,7 @@
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
<p class="remarque">Cet événement a été l'objet {% if event.message_set.all.count == 1 %}d'un message{% else %}de messages{% 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 %}
|
||||
|
@ -312,7 +312,6 @@ class EventUpdateView(
|
||||
model = Event
|
||||
permission_required = "agenda_culturel.change_event"
|
||||
form_class = EventForm
|
||||
success_message = _("The event has been successfully modified.")
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
@ -321,8 +320,14 @@ class EventUpdateView(
|
||||
kwargs["is_simple_cloning"] = self.is_simple_cloning
|
||||
return kwargs
|
||||
|
||||
def get_success_message(self, cleaned_data):
|
||||
txt = _(" A message has been sent to the person who proposed the event.") if hasattr(self, "with_msg") else ""
|
||||
return mark_safe(_('The event has been successfully modified.') + txt)
|
||||
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.set_processing_user(self.request.user)
|
||||
self.with_message = form.instance.notify_if_required(self.request)
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_initial(self):
|
||||
@ -364,7 +369,8 @@ class EventModerateView(
|
||||
form_class = EventModerateForm
|
||||
|
||||
def get_success_message(self, cleaned_data):
|
||||
return mark_safe(_('The event <a href="{}">{}</a> has been moderated with success.').format(self.object.get_absolute_url(), self.object.title))
|
||||
txt = _(" A message has been sent to the person who proposed the event.") if hasattr(self, "with_msg") else ""
|
||||
return mark_safe(_('The event <a href="{}">{}</a> has been moderated with success.').format(self.object.get_absolute_url(), self.object.title) + txt)
|
||||
|
||||
|
||||
def is_moderate_next(self):
|
||||
@ -424,6 +430,7 @@ class EventModerateView(
|
||||
form.instance.set_no_modification_date_changed()
|
||||
form.instance.set_in_moderation_process()
|
||||
form.instance.set_processing_user(self.request.user)
|
||||
self.with_msg = form.instance.notify_if_required(self.request)
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
@ -539,7 +546,11 @@ def change_status_event(request, pk, status):
|
||||
if request.method == "POST":
|
||||
event.status = Event.STATUS(status)
|
||||
event.save(update_fields=["status"])
|
||||
messages.success(request, _("The status has been successfully modified."))
|
||||
with_msg = event.notify_if_required(request)
|
||||
if with_msg:
|
||||
messages.success(request, _("The status has been successfully modified and a message has been sent to the person who proposed the event."))
|
||||
else:
|
||||
messages.success(request, _("The status has been successfully modified."))
|
||||
|
||||
return HttpResponseRedirect(event.get_absolute_url())
|
||||
|
||||
@ -586,14 +597,21 @@ class EventCreateView(SuccessMessageMixin, CreateView):
|
||||
if form.cleaned_data['cloning']:
|
||||
form.instance.set_in_moderation_process()
|
||||
|
||||
if form.cleaned_data["email"] or form.cleaned_data["comments"]:
|
||||
if form.cleaned_data.get("email") or form.cleaned_data.get("comments"):
|
||||
form.instance.set_message(
|
||||
Message(subject=_('during the creation process'), message=form.cleaned_data["comments"], email=form.cleaned_data["email"]))
|
||||
Message(subject=_('during the creation process'), message=form.cleaned_data["comments"], email=form.cleaned_data["email"]), closed=False)
|
||||
|
||||
form.instance.import_sources = None
|
||||
form.instance.set_processing_user(self.request.user)
|
||||
|
||||
return super().form_valid(form)
|
||||
result = super().form_valid(form)
|
||||
|
||||
if form.cleaned_data['cloning']:
|
||||
with_msg = form.instance.notify_if_required(self.request)
|
||||
if with_msg:
|
||||
messages.success(self.request, _("A message has been sent to the person who proposed the initial event."))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user