Просмотр исходного кода

Fixes #3951: Fix exception in webhook worker due to missing constant

Jeremy Stretch 6 лет назад
Родитель
Сommit
f15cde0275
2 измененных файлов с 14 добавлено и 5 удалено
  1. 8 0
      docs/release-notes/version-2.7.md
  2. 6 5
      netbox/extras/webhooks_worker.py

+ 8 - 0
docs/release-notes/version-2.7.md

@@ -1,3 +1,11 @@
+# v2.7.2 (FUTURE)
+
+## Bug Fixes
+
+* [#3951](https://github.com/netbox-community/netbox/issues/3951) - Fix exception in webhook worker due to missing constant
+
+---
+
 # v2.7.1 (2020-01-16)
 
 ## Bug Fixes

+ 6 - 5
netbox/extras/webhooks_worker.py

@@ -6,8 +6,7 @@ import requests
 from django_rq import job
 from rest_framework.utils.encoders import JSONEncoder
 
-from .choices import ObjectChangeActionChoices
-from .constants import *
+from .choices import ObjectChangeActionChoices, WebhookContentTypeChoices
 
 
 @job('default')
@@ -35,9 +34,9 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque
         'headers': headers
     }
 
-    if webhook.http_content_type == WEBHOOK_CT_JSON:
+    if webhook.http_content_type == WebhookContentTypeChoices.CONTENTTYPE_JSON:
         params.update({'data': json.dumps(payload, cls=JSONEncoder)})
-    elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:
+    elif webhook.http_content_type == WebhookContentTypeChoices.CONTENTTYPE_FORMDATA:
         params.update({'data': payload})
 
     prepared_request = requests.Request(**params).prepare()
@@ -61,5 +60,7 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque
         return 'Status {} returned, webhook successfully processed.'.format(response.status_code)
     else:
         raise requests.exceptions.RequestException(
-            "Status {} returned with content '{}', webhook FAILED to process.".format(response.status_code, response.content)
+            "Status {} returned with content '{}', webhook FAILED to process.".format(
+                response.status_code, response.content
+            )
         )