Browse Source

send notifications to webhooks

Guilhem Saurel 6 years ago
parent
commit
3d3b0cf5f3

+ 1 - 0
requirements/base.txt

@@ -3,3 +3,4 @@ PyYAML>=3.11,<4.0
 django-request-token>=0.6,<0.7
 pytz
 sqlparse
+requests

+ 3 - 0
wifiwithme/apps/contribmap/views.py

@@ -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(

+ 17 - 0
wifiwithme/apps/contribmap/webhooks.py

@@ -0,0 +1,17 @@
+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
+        requests.post(
+            settings.WEBHOOK_URL,
+            data=json.dumps({
+                'name': contrib.name,
+                'permalink': contrib.get_absolute_url(request) if request else None,
+                'key': settings.WEBHOOK_KEY,
+            }))

+ 2 - 0
wifiwithme/settings/base.py

@@ -147,3 +147,5 @@ DATA_EXPIRATION_REMINDERS = [
 ]
 
 SITE_URL = 'http://localhost:8000'
+
+WEBHOOK = False