Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Merge 54d4d5e into a554148
Browse files Browse the repository at this point in the history
  • Loading branch information
atb00ker committed Feb 29, 2020
2 parents a554148 + 54d4d5e commit c4db635
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

Version 0.6.2 [Unreleased]
--------------------------

- Renamed api setting TOPOLOGY_RECEIVE_URLCONF -> TOPOLOGY_API_URLCONF
- Renamed api setting TOPOLOGY_RECEIVE_BASEURL -> TOPOLOGY_API_BASEURL

Version 0.6.1 [2020-02-26]
--------------------------

Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ it will be deleted by the ``update_topology`` management command. This depends o
``NETJSONGRAPH_LINK_EXPIRATION`` being enabled.
Replace ``False`` with an integer to enable the feature.

``TOPOLOGY_RECEIVE_URLCONF``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``TOPOLOGY_API_URLCONF``
^^^^^^^^^^^^^^^^^^^^^^^^

+--------------+---------------+
| **type**: | ``string`` |
Expand All @@ -304,8 +304,8 @@ Replace ``False`` with an integer to enable the feature.
Use the ``urlconf`` option to change receive api url to point to
another module, example, ``myapp.urls``.

``TOPOLOGY_RECEIVE_BASEURL``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``TOPOLOGY_API_BASEURL``
^^^^^^^^^^^^^^^^^^^^^^^^

+--------------+---------------+
| **type**: | ``string`` |
Expand Down
10 changes: 5 additions & 5 deletions django_netjsongraph/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .. import settings as app_settings
from ..contextmanagers import log_failure
from ..visualizer import GraphVisualizerUrls


class TimeStampedEditableAdmin(ModelAdmin):
Expand Down Expand Up @@ -37,7 +38,7 @@ class Media:
static('netjsongraph/js/visualize.js')]


class AbstractTopologyAdmin(BaseAdmin, ReceiveUrlAdmin):
class AbstractTopologyAdmin(BaseAdmin, ReceiveUrlAdmin, GraphVisualizerUrls):
list_display = ['label', 'parser', 'strategy', 'published', 'created', 'modified']
readonly_fields = ['protocol', 'version', 'revision', 'metric', 'receive_url']
list_filter = ['parser', 'strategy']
Expand All @@ -47,8 +48,8 @@ class AbstractTopologyAdmin(BaseAdmin, ReceiveUrlAdmin):
'expiration_time', 'receive_url', 'published', 'protocol',
'version', 'revision', 'metric', 'created']
receive_url_name = 'receive_topology'
receive_url_urlconf = app_settings.TOPOLOGY_RECEIVE_URLCONF
receive_url_baseurl = app_settings.TOPOLOGY_RECEIVE_BASEURL
receive_url_urlconf = app_settings.TOPOLOGY_API_URLCONF
receive_url_baseurl = app_settings.TOPOLOGY_API_BASEURL

def get_actions(self, request):
"""
Expand Down Expand Up @@ -135,8 +136,7 @@ def unpublish_selected(self, request, queryset):
unpublish_selected.short_description = _('Unpublish selected items')

def visualize_view(self, request, pk):
graph_url = reverse('network_graph', args=[pk])
history_url = reverse('network_graph_history', args=[pk])
graph_url, history_url = self.get_graph_urls(request, pk)
context = self.admin_site.each_context(request)
opts = self.model._meta
context.update({
Expand Down
4 changes: 2 additions & 2 deletions django_netjsongraph/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
LINK_EXPIRATION = getattr(settings, 'NETJSONGRAPH_LINK_EXPIRATION', 60)
NODE_EXPIRATION = getattr(settings, 'NETJSONGRAPH_NODE_EXPIRATION', False)
VISUALIZER_CSS = getattr(settings, 'NETJSONGRAPH_VISUALIZER_CSS', 'netjsongraph/css/style.css')
TOPOLOGY_RECEIVE_URLCONF = getattr(settings, 'TOPOLOGY_RECEIVE_URLCONF', None)
TOPOLOGY_RECEIVE_BASEURL = getattr(settings, 'TOPOLOGY_RECEIVE_BASEURL', None)
TOPOLOGY_API_URLCONF = getattr(settings, 'TOPOLOGY_API_URLCONF', None)
TOPOLOGY_API_BASEURL = getattr(settings, 'TOPOLOGY_API_BASEURL', None)
15 changes: 10 additions & 5 deletions django_netjsongraph/static/netjsongraph/js/topology-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ window.initTopologyHistory = function ($) {
today = new Date(),
apiUrl = datepicker.attr('data-history-api');
today.setHours(0, 0, 0, 0);
datepicker.datepicker({dateFormat: 'dd/mm/yy'});
datepicker.datepicker({ dateFormat: 'dd/mm/yy' });
datepicker.datepicker('setDate', today);
datepicker.change(function () {
var date = datepicker.val().split('/').reverse().join('-'),
Expand All @@ -13,10 +13,15 @@ window.initTopologyHistory = function ($) {
if (datepicker.datepicker('getDate').getTime() === today.getTime()) {
url = window.__njg_default_url__;
}
$.getJSON(url).done(function (data) {
window.graph = window.loadNetJsonGraph(data);
}).error(function (xhr) {
alert(xhr.responseJSON.detail);
$.ajax({
url: url,
dataType: 'json',
success: function (data) {
window.graph = window.loadNetJsonGraph(data);
},
error: function (xhr) {
alert(xhr.responseJSON.detail);
}
});
});
};
25 changes: 25 additions & 0 deletions django_netjsongraph/visualizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.urls import reverse

from ..settings import TOPOLOGY_API_BASEURL, TOPOLOGY_API_URLCONF


class GraphVisualizerUrls:

def get_graph_urls(self, request, pk):
graph_path = reverse('network_graph',
urlconf=TOPOLOGY_API_URLCONF,
args=[pk])
history_path = reverse('network_graph_history',
urlconf=TOPOLOGY_API_URLCONF,
args=[pk])
if TOPOLOGY_API_BASEURL:
graph_url = '{}{}'.format(TOPOLOGY_API_BASEURL, graph_path)
history_url = '{}{}'.format(TOPOLOGY_API_BASEURL, history_path)
else:
graph_url = '{0}://{1}{2}'.format(request.scheme,
request.get_host(),
graph_path)
history_url = '{0}://{1}{2}'.format(request.scheme,
request.get_host(),
history_path)
return graph_url, history_url
10 changes: 6 additions & 4 deletions django_netjsongraph/visualizer/generics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.shortcuts import render
from django.urls import reverse
from django.views import View

from ..settings import VISUALIZER_CSS
from ..utils import get_object_or_404
from . import GraphVisualizerUrls


class BaseTopologyListView(View):
Expand All @@ -14,12 +14,14 @@ def get(self, request):
'VISUALIZER_CSS': VISUALIZER_CSS})


class BaseTopologyDetailView(View):
class BaseTopologyDetailView(View, GraphVisualizerUrls):

def get(self, request, pk):
topology = get_object_or_404(self.topology_model, pk)
graph_url, history_url = self.get_graph_urls(request, pk)
return render(request, 'netjsongraph/detail.html', {
'topology': topology,
'graph_url': reverse('network_graph', args=[topology.pk]),
'history_url': reverse('network_graph_history', args=[topology.pk]),
'graph_url': graph_url,
'history_url': history_url,
'VISUALIZER_CSS': VISUALIZER_CSS
})

0 comments on commit c4db635

Please sign in to comment.