Skip to content

Commit

Permalink
schedule changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wslyvh committed Aug 21, 2024
1 parent 6a59f5d commit e5b688e
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions pretalx_webhook/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@
import requests
import logging
from django.dispatch import receiver
from django.urls import reverse
from django.conf import settings
from pretalx.orga.signals import nav_event_settings
from pretalx.schedule.signals import schedule_release
from pretalx.api.serializers.submission import ScheduleSerializer

logger = logging.getLogger(__name__)

def log_object_keys(obj):
if isinstance(obj, dict):
keys = obj.keys()
else:
keys = vars(obj).keys()

logger.error(f"Keys of {type(obj).__name__}: {list(keys)}")

@receiver(schedule_release, dispatch_uid="pretalx_webhook_schedule_release")
def on_schedule_release(sender, schedule, user, **kwargs):
try:
Expand All @@ -34,32 +23,21 @@ def on_schedule_release(sender, schedule, user, **kwargs):
logger.info(f"Webhook endpoint is empty for event {sender.slug}")
return

# log the arguments
logger.error("Logging keys of all arguments:")
log_object_keys(sender)
log_object_keys(schedule)
log_object_keys(schedule.changes)
logger.error(f"Schedule changes: {schedule.changes}")
log_object_keys(user)
logger.error(ScheduleSerializer(schedule).data)

payload = {
'event': sender.slug,
'schedule': str(schedule),
'user': str(user)
'user': str(user),
'schedule': schedule.version,
'changes': str(schedule.changes),
}

logger.error(f"Prepare payload..")
logger.error(payload)

headers = {'Content-Type': 'application/json'}
if webhook_secret:
headers['X-Webhook-Secret'] = webhook_secret
else:
logger.warning(f"Webhook secret is empty for event {sender.slug}")


logger.error(f"Send JSON request to {webhook_endpoint}")
logger.error(f"Send JSON request to {webhook_endpoint} with payload: {payload}")
response = requests.post(webhook_endpoint,
json=json.dumps(payload),
headers=headers,
Expand Down

0 comments on commit e5b688e

Please sign in to comment.