File tree Expand file tree Collapse file tree 3 files changed +30
-23
lines changed Expand file tree Collapse file tree 3 files changed +30
-23
lines changed Original file line number Diff line number Diff line change 9
9
# #
10
10
# # Examples:
11
11
12
- # - name: link_to_repo
13
- # text: 'Link to docker repository'
14
- # url: 'https://github.com/netbox-community/netbox-docker'
15
- # new_window: False
16
- # content_type: device
17
- # - name: link_to_localhost
18
- # text: 'Link to the users localhost'
19
- # url: 'http://localhost'
20
- # new_window: True
21
- # content_type: device
12
+ # - name: link_to_repo
13
+ # text: 'Link to docker repository'
14
+ # url: 'https://github.com/netbox-community/netbox-docker'
15
+ # new_window: False
16
+ # content_type: device
17
+ # - name: link_to_localhost
18
+ # text: 'Link to the users localhost'
19
+ # url: 'http://localhost'
20
+ # new_window: True
21
+ # content_type: device
Original file line number Diff line number Diff line change 10
10
sys .exit ()
11
11
12
12
def get_content_type_id (content_type_str ):
13
- for type in ContentType .objects .all ():
14
- if type .name == content_type_str :
15
- return type .id
13
+ try :
14
+ id = ContentType .objects .get (model = content_type_str ).id
15
+ return id
16
+ except ContentType .DoesNotExist :
17
+ print (" Error determining content type id for user declared var: {0}" .format (content_type_str ))
16
18
17
19
for link in custom_links :
18
20
content_type = link .pop ('content_type' )
19
21
link ['content_type_id' ] = get_content_type_id (content_type )
20
- if link ['content_type_id' ] is None :
21
- print ("⚠️ Error determining content type id for user declared var: {0}" .format (content_type ))
22
- else :
23
- CustomLink (** link ).save ()
22
+ if link ['content_type_id' ] is not None :
23
+ custom_link = CustomLink (** link )
24
+ if not CustomLink .objects .filter (name = custom_link .name ):
25
+ custom_link .save ()
26
+ print (" Created Custom Link {0}" .format (custom_link .name ))
27
+ else :
28
+ print ("⚠️ Skipping Custom Link {0}, already exists" .format (custom_link .name ))
24
29
Original file line number Diff line number Diff line change 10
10
sys .exit ()
11
11
12
12
def get_content_type_id (content_type_str ):
13
- return ContentType .objects .get (model = content_type_str ).id
13
+ try :
14
+ id = ContentType .objects .get (model = content_type_str ).id
15
+ return id
16
+ except ContentType .DoesNotExist :
17
+ print ("⚠️ Error determining content type id for user declared var: {0}" .format (content_type_str ))
14
18
15
19
for hook in webhooks :
16
20
obj_types = hook .pop ('object_types' )
17
21
obj_type_ids = []
18
22
for obj in obj_types :
19
23
obj_type_ids .append (get_content_type_id (obj ))
20
- if obj_type_ids is None :
21
- print ("⚠️ Error determining content type id for user declared var: {0}" .format (obj_type ))
22
- else :
24
+ if obj_type_ids is not None :
23
25
webhook = Webhook (** hook )
24
26
if not Webhook .objects .filter (name = webhook .name ):
25
27
webhook .save ()
26
28
webhook .content_types .set (obj_type_ids )
27
- print (" Created Webhook {0}" .format (webhook .name ))
29
+ print ("🖥️ Created Webhook {0}" .format (webhook .name ))
28
30
else :
29
- print (" Skipping Webhook {0}, already exists" .format (webhook .name ))
31
+ print ("⚠️ Skipping Webhook {0}, already exists" .format (webhook .name ))
You can’t perform that action at this time.
0 commit comments