Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alerts manager when a path has draft True #3195

Merged
merged 6 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHANGELOG

- Add sync_rando / sync_mobile option `empty_tmp_folder` which will force deletion of all directories / files in tmp directory
- Add information desk uuid (#3189)
- Add setting ``ALERT_DRAFT`` which send mail whenever a path has been changed to draft (#2904)

**Minor improvements**

Expand Down
10 changes: 10 additions & 0 deletions docs/install/advanced-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2795,6 +2795,16 @@ It is possible to customize the pdf, with trek_public_booklet_pdf.html.
If false, it forbid to delete a path when at least one topology is linked to this path.


::

ALERT_DRAFT = False

If True, it sends a message to managers (MAIL_MANAGERS) whenever a path has been changed to draft.

Email configuration takes place in ``/opt/geotrek-admin/var/conf/custom.py``, where you control
recipients emails (``ADMINS``, ``MAIL_MANAGERS``) and email server configuration.


::

ALERT_REVIEW = False
Expand Down
2 changes: 1 addition & 1 deletion geotrek/common/templates/common/review_email_message.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n l10n %}
{% autoescape off %}

{% blocktrans %}{{obj}} has changed state, it needs a review to be published. {% endblocktrans %}
{% blocktrans %}{{obj}} has changed state, it needs a review to be published. {% endblocktrans %}

{% endautoescape %}
16 changes: 12 additions & 4 deletions geotrek/core/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-26 09:00+0000\n"
"POT-Creation-Date: 2022-08-02 07:32+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -52,6 +52,9 @@ msgstr ""
msgid "Arrival"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Trail"
msgstr ""

Expand Down Expand Up @@ -131,6 +134,10 @@ msgstr ""
msgid "Paths"
msgstr ""

#, python-brace-format
msgid "{obj} has been set to draft"
msgstr ""

msgid "You can't delete this path, some topologies are linked with this path"
msgstr ""

Expand Down Expand Up @@ -224,9 +231,6 @@ msgstr ""
msgid "Certification label"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Certification status"
msgstr ""

Expand All @@ -245,6 +249,10 @@ msgstr ""
msgid "Add a new trail"
msgstr ""

#, python-format
msgid "%(obj)s has changed state to draft. "
msgstr ""

#, python-format
msgid "Do you really wish to delete <strong>%(object)s</strong> ?"
msgstr ""
Expand Down
16 changes: 12 additions & 4 deletions geotrek/core/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-26 09:00+0000\n"
"POT-Creation-Date: 2022-08-02 07:32+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -52,6 +52,9 @@ msgstr ""
msgid "Arrival"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Trail"
msgstr ""

Expand Down Expand Up @@ -131,6 +134,10 @@ msgstr ""
msgid "Paths"
msgstr ""

#, python-brace-format
msgid "{obj} has been set to draft"
msgstr ""

msgid "You can't delete this path, some topologies are linked with this path"
msgstr ""

Expand Down Expand Up @@ -224,9 +231,6 @@ msgstr ""
msgid "Certification label"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Certification status"
msgstr ""

Expand All @@ -245,6 +249,10 @@ msgstr ""
msgid "Add a new trail"
msgstr ""

#, python-format
msgid "%(obj)s has changed state to draft. "
msgstr ""

#, python-format
msgid "Do you really wish to delete <strong>%(object)s</strong> ?"
msgstr ""
Expand Down
16 changes: 12 additions & 4 deletions geotrek/core/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-26 09:00+0000\n"
"POT-Creation-Date: 2022-08-02 07:32+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -52,6 +52,9 @@ msgstr ""
msgid "Arrival"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Trail"
msgstr ""

Expand Down Expand Up @@ -131,6 +134,10 @@ msgstr ""
msgid "Paths"
msgstr ""

#, python-brace-format
msgid "{obj} has been set to draft"
msgstr ""

msgid "You can't delete this path, some topologies are linked with this path"
msgstr ""

Expand Down Expand Up @@ -224,9 +231,6 @@ msgstr ""
msgid "Certification label"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Certification status"
msgstr ""

Expand All @@ -245,6 +249,10 @@ msgstr ""
msgid "Add a new trail"
msgstr ""

#, python-format
msgid "%(obj)s has changed state to draft. "
msgstr ""

#, python-format
msgid "Do you really wish to delete <strong>%(object)s</strong> ?"
msgstr ""
Expand Down
19 changes: 15 additions & 4 deletions geotrek/core/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-26 08:47+0000\n"
"POT-Creation-Date: 2022-08-02 07:32+0000\n"
"PO-Revision-Date: 2020-09-23 07:10+0000\n"
"Last-Translator: Emmanuelle Helly <[email protected]>\n"
"Language-Team: French <https://weblate.makina-corpus.net/projects/geotrek-"
Expand Down Expand Up @@ -53,6 +53,9 @@ msgstr "Départ"
msgid "Arrival"
msgstr "Arrivée"

msgid "Certification labels"
msgstr "Labellisations"

msgid "Trail"
msgstr "Sentier"

Expand Down Expand Up @@ -132,6 +135,10 @@ msgstr "Tronçon"
msgid "Paths"
msgstr "Tronçons"

#, python-brace-format
msgid "{obj} has been set to draft"
msgstr "{obj} a été mis en brouillon"

msgid "You can't delete this path, some topologies are linked with this path"
msgstr ""
"Vous ne pouvez pas supprimer ce tronçon, des topologies sont liés à ce "
Expand Down Expand Up @@ -227,9 +234,6 @@ msgstr "Categories de sentier"
msgid "Certification label"
msgstr "Labellisation"

msgid "Certification labels"
msgstr "Labellisations"

msgid "Certification status"
msgstr "Statut de labellisation"

Expand All @@ -248,6 +252,10 @@ msgstr "Pas d'information"
msgid "Add a new trail"
msgstr "Ajouter un sentier"

#, python-format
msgid "%(obj)s has changed state to draft. "
msgstr "%(obj)s a été mis en brouillon."

#, python-format
msgid "Do you really wish to delete <strong>%(object)s</strong> ?"
msgstr "Voulez-vous réellement supprimer <strong>%(object)s</strong> ?"
Expand Down Expand Up @@ -351,3 +359,6 @@ msgstr "Aucun point de correspondance trouvé pour fusionner les tronçons"

msgid "Paths merged successfully"
msgstr "Les tronçons ont été fusionnés."

#~ msgid "length"
#~ msgstr "Longueur"
16 changes: 12 additions & 4 deletions geotrek/core/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-26 09:00+0000\n"
"POT-Creation-Date: 2022-08-02 07:32+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -52,6 +52,9 @@ msgstr ""
msgid "Arrival"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Trail"
msgstr ""

Expand Down Expand Up @@ -131,6 +134,10 @@ msgstr ""
msgid "Paths"
msgstr ""

#, python-brace-format
msgid "{obj} has been set to draft"
msgstr ""

msgid "You can't delete this path, some topologies are linked with this path"
msgstr ""

Expand Down Expand Up @@ -224,9 +231,6 @@ msgstr ""
msgid "Certification label"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Certification status"
msgstr ""

Expand All @@ -245,6 +249,10 @@ msgstr ""
msgid "Add a new trail"
msgstr ""

#, python-format
msgid "%(obj)s has changed state to draft. "
msgstr ""

#, python-format
msgid "Do you really wish to delete <strong>%(object)s</strong> ?"
msgstr ""
Expand Down
16 changes: 12 additions & 4 deletions geotrek/core/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-26 09:00+0000\n"
"POT-Creation-Date: 2022-08-02 07:32+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -52,6 +52,9 @@ msgstr ""
msgid "Arrival"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Trail"
msgstr ""

Expand Down Expand Up @@ -131,6 +134,10 @@ msgstr ""
msgid "Paths"
msgstr ""

#, python-brace-format
msgid "{obj} has been set to draft"
msgstr ""

msgid "You can't delete this path, some topologies are linked with this path"
msgstr ""

Expand Down Expand Up @@ -224,9 +231,6 @@ msgstr ""
msgid "Certification label"
msgstr ""

msgid "Certification labels"
msgstr ""

msgid "Certification status"
msgstr ""

Expand All @@ -245,6 +249,10 @@ msgstr ""
msgid "Add a new trail"
msgstr ""

#, python-format
msgid "%(obj)s has changed state to draft. "
msgstr ""

#, python-format
msgid "Do you really wish to delete <strong>%(object)s</strong> ?"
msgstr ""
Expand Down
13 changes: 13 additions & 0 deletions geotrek/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.geos import Point, fromstr, LineString, GEOSGeometry
from django.contrib.postgres.indexes import GistIndex
from django.core.mail import mail_managers
from django.db import connection, connections, DEFAULT_DB_ALIAS
from django.db.models import ProtectedError
from django.db.models.query import QuerySet
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
Expand Down Expand Up @@ -241,6 +243,17 @@ def save(self, *args, **kwargs):
aggr.end_position = 1 - aggr.end_position
aggr.save()
self._is_reversed = False

# If draft is set from False to True, and setting ALERT_DRAFT is True, send email to managers
if (self.pk and self.draft and self.__class__.objects.get(pk=self.pk).draft != self.draft) \
and settings.ALERT_DRAFT:
subject = _("{obj} has been set to draft").format(obj=self)
message = render_to_string('core/draft_email_message.txt', {"obj": self})
try:
mail_managers(subject, message, fail_silently=False)
except Exception as exc:
msg = f'Caught {exc.__class__.__name__}: {exc}'
logger.warning(f"Error mail managers didn't work ({msg})")
super().save(*args, **kwargs)
self.reload()

Expand Down
6 changes: 6 additions & 0 deletions geotrek/core/templates/core/draft_email_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% load i18n l10n %}
{% autoescape off %}

{% blocktrans %}{{obj}} has changed state to draft. {% endblocktrans %}

{% endautoescape %}
Loading