add error handling for webhook and custom links. fix initializer comments

This commit is contained in:
Schylar Utleye 2021-01-15 23:12:03 -06:00 committed by Christian Mäder
parent a3cf645dc5
commit 618feff63a
3 changed files with 30 additions and 23 deletions

View file

@ -10,20 +10,22 @@ if webhooks is None:
sys.exit()
def get_content_type_id(content_type_str):
return ContentType.objects.get(model=content_type_str).id
try:
id = ContentType.objects.get(model=content_type_str).id
return id
except ContentType.DoesNotExist:
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
for hook in webhooks:
obj_types = hook.pop('object_types')
obj_type_ids = []
for obj in obj_types:
obj_type_ids.append(get_content_type_id(obj))
if obj_type_ids is None:
print("⚠️ Error determining content type id for user declared var: {0}".format(obj_type))
else:
if obj_type_ids is not None:
webhook = Webhook(**hook)
if not Webhook.objects.filter(name=webhook.name):
webhook.save()
webhook.content_types.set(obj_type_ids)
print(" Created Webhook {0}".format(webhook.name))
print("🖥️ Created Webhook {0}".format(webhook.name))
else:
print(" Skipping Webhook {0}, already exists".format(webhook.name))
print("⚠️ Skipping Webhook {0}, already exists".format(webhook.name))