This repository was archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathutils.py
68 lines (58 loc) · 1.77 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
from django.conf.urls import url
from django.core.exceptions import ValidationError
from django.dispatch import Signal
from django.http import Http404
from django.shortcuts import get_object_or_404 as get_obj_or_404
link_status_changed = Signal(providing_args=["link"])
def print_info(message): # pragma no cover
"""
print info message if calling from management command ``update_all``
"""
if 'update_topology' in sys.argv:
print('{0}\n'.format(message))
def get_object_or_404(model, pk, **kwargs):
"""
retrieves topology with specified arguments or raises 404
"""
kwargs.update({'pk': pk, 'published': True})
try:
return get_obj_or_404(model, **kwargs)
except ValidationError:
raise Http404()
def get_api_urls(views_module):
"""
used by third party apps to reduce boilerplate
"""
urls = [
url(r'^topology/$', views_module.network_collection, name='network_collection'),
url(
r'^topology/(?P<pk>[^/]+)/$',
views_module.network_graph,
name='network_graph',
),
url(
r'^topology/(?P<pk>[^/]+)/history/$',
views_module.network_graph_history,
name='network_graph_history',
),
url(
r'^receive/(?P<pk>[^/\?]+)/$',
views_module.receive_topology,
name='receive_topology',
),
]
return urls
def get_visualizer_urls(views_module):
"""
used by third party apps to reduce boilerplate
"""
urls = [
url(r'^$', views_module.topology_list, name='topology_list'),
url(
r'^topology/(?P<pk>[^/]+)/$',
views_module.topology_detail,
name='topology_detail',
),
]
return urls