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 Schylar Utley
parent 717575f253
commit 32500016ae
3 changed files with 30 additions and 23 deletions

View file

@ -10,15 +10,20 @@ if custom_links is None:
sys.exit()
def get_content_type_id(content_type_str):
for type in ContentType.objects.all():
if type.name == content_type_str:
return type.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 link in custom_links:
content_type = link.pop('content_type')
link['content_type_id'] = get_content_type_id(content_type)
if link['content_type_id'] is None:
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type))
else:
CustomLink(**link).save()
if link['content_type_id'] is not None:
custom_link = CustomLink(**link)
if not CustomLink.objects.filter(name=custom_link.name):
custom_link.save()
print(" Created Custom Link {0}".format(custom_link.name))
else:
print("⚠️ Skipping Custom Link {0}, already exists".format(custom_link.name))