Commit 93049e5d authored by jocelyn's avatar jocelyn Committed by Team adminsys FFDN
Browse files

Merge branch 'master' of Nim/wifi-with-me into master

parents c49b2907 1b7690b7
......@@ -68,9 +68,9 @@ accessible under *http://example.com/foo/* :
URL_PREFIX='foo/'
### Notifications
### Email Notifications
If you to receive notifications on each new contrib, customize those :
If you want to receive email notifications on each new contrib, customize those :
List of notification recipients:
......@@ -80,6 +80,17 @@ Notification sender address:
DEFAULT_FROM_EMAIL='notifier@example.tld'
### Webhook Notifications
If you want to send web notifications on each new contrib, install
[requests](http://docs.python-requests.org/en/master/) and customize those :
WEBHOOK = True
WEBHOOK_URL = 'https://<domain>/<path>'
WEBHOOK_KEY = '<secret>'
Then, on each contrib, an HTTP POST request wil be made to `WEBHOOK_URL` with a json dict containing `'key': WEBHOOK_KEY`
and the notification as `'text'`.
### Data expiration
......
......@@ -3,3 +3,4 @@ PyYAML>=3.11,<4.0
django-request-token>=0.6,<0.7
pytz
sqlparse
requests
......@@ -19,6 +19,7 @@ from .models import Contrib
from .decorators import prevent_robots
from .tokens import ContribTokenManager, URLTokenManager, TokenError
from .emails import send_contributor_email, send_moderator_emails
from .webhooks import send_moderator_webhook
@prevent_robots()
......@@ -40,6 +41,8 @@ def add_contrib(request):
send_moderator_emails(
contrib, admin_subject, admin_body, mgmt_token, request)
send_moderator_webhook(contrib, request)
# Notification email to the author
if contrib.email:
author_subject = get_template(
......
import json
from django.conf import settings
def send_moderator_webhook(contrib, request=None):
""" Sends a notification to a webhook
"""
if settings.WEBHOOK:
import requests
text = "Nouvelle demande de %s" % contrib.name
if request is not None:
text += ": %s" % contrib.get_absolute_url(request)
requests.post(
settings.WEBHOOK_URL, data=json.dumps({
'text': text,
'key': settings.WEBHOOK_KEY,
}))
......@@ -147,3 +147,5 @@ DATA_EXPIRATION_REMINDERS = [
]
SITE_URL = 'http://localhost:8000'
WEBHOOK = False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment