Adjust to repository standards
This commit is contained in:
parent
e4e2c788a9
commit
16ae063321
4 changed files with 83 additions and 71 deletions
|
@ -9,17 +9,21 @@ custom_links = load_yaml('/opt/netbox/initializers/custom_links.yml')
|
|||
if custom_links is None:
|
||||
sys.exit()
|
||||
|
||||
def get_content_type_id(content_type_str):
|
||||
|
||||
def get_content_type_id(content_type):
|
||||
try:
|
||||
return ContentType.objects.get(model=content_type_str).id
|
||||
return ContentType.objects.get(model=content_type).id
|
||||
except ContentType.DoesNotExist:
|
||||
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
|
||||
pass
|
||||
|
||||
|
||||
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 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))
|
||||
if link['content_type_id'] is None:
|
||||
print("⚠️ Unable to create Custom Link '{0}': The content_type '{1}' is unknown".format(link.name, content_type))
|
||||
continue
|
||||
|
||||
custom_link, created = CustomLink.objects.get_or_create(**link)
|
||||
if created:
|
||||
print("🔗 Created Custom Link '{0}'".format(custom_link.name))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue