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 64
[feature] Topology history #49
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| from django.utils.translation import ugettext_lazy as _ | ||
|
|
||
| from ..contextmanagers import log_failure | ||
| from ..utils import get_object_or_404 | ||
|
|
||
|
|
||
| class TimeStampedEditableAdmin(ModelAdmin): | ||
|
|
@@ -25,9 +24,12 @@ class BaseAdmin(TimeStampedEditableAdmin): | |
|
|
||
| class Media: | ||
| css = {'all': [static('netjsongraph/css/src/netjsongraph.css'), | ||
| static('netjsongraph/css/lib/jquery-ui.min.css'), | ||
| static('netjsongraph/css/style.css'), | ||
| static('netjsongraph/css/admin.css')]} | ||
| js = [static('netjsongraph/js/lib/d3.min.js'), | ||
| static('netjsongraph/js/lib/jquery.min.js'), | ||
| static('netjsongraph/js/lib/jquery-ui.min.js'), | ||
| static('netjsongraph/js/src/netjsongraph.js'), | ||
| static('netjsongraph/js/receive-url.js'), | ||
| static('netjsongraph/js/strategy-switcher.js'), | ||
|
|
@@ -83,7 +85,10 @@ def get_urls(self): | |
| return [ | ||
| url(r'^visualize/(?P<pk>[^/]+)/$', | ||
| self.admin_site.admin_view(self.visualize_view), | ||
| name='{0}_visualize'.format(url_prefix)) | ||
| name='{0}_visualize'.format(url_prefix)), | ||
| url(r'^visualize/history/(?P<pk>[^/]+)/$', | ||
| self.admin_site.admin_view(self.visualize_history_view), | ||
| name='{0}_visualize_history'.format(url_prefix)) | ||
| ] + super(AbstractTopologyAdmin, self).get_urls() | ||
|
|
||
| def _message(self, request, rows, suffix, level=messages.SUCCESS): | ||
|
|
@@ -123,15 +128,35 @@ def unpublish_selected(self, request, queryset): | |
| unpublish_selected.short_description = _('Unpublish selected items') | ||
|
|
||
| def visualize_view(self, request, pk): | ||
| topology = get_object_or_404(self.model, pk) | ||
| api_url = reverse('network_graph', args=[pk]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this change 👍 |
||
| context = self.admin_site.each_context(request) | ||
| opts = self.model._meta | ||
| prefix = 'admin:{0}_{1}'.format(self.opts.app_label, self.model.__name__.lower()) | ||
| graph_url = reverse('{0}_visualize_history'.format(prefix), args=[pk]) | ||
| context.update({ | ||
| 'is_popup': True, | ||
| 'opts': opts, | ||
| 'change': False, | ||
| 'media': self.media, | ||
| 'api_url': api_url, | ||
| 'graph_url': graph_url | ||
| }) | ||
| return TemplateResponse(request, 'admin/%s/visualize.html' % opts.app_label, context) | ||
|
|
||
| def visualize_history_view(self, request, pk): | ||
| date = request.GET.get('date', '') | ||
| api_url = '{0}?date={1}'.format(reverse('network_graph_history', args=[pk]), date) | ||
| context = self.admin_site.each_context(request) | ||
| opts = self.model._meta | ||
| prefix = 'admin:{0}_{1}'.format(self.opts.app_label, self.model.__name__.lower()) | ||
| graph_url = reverse('{0}_visualize_history'.format(prefix), args=[pk]) | ||
| context.update({ | ||
| 'is_popup': True, | ||
| 'opts': opts, | ||
| 'change': False, | ||
| 'media': self.media, | ||
| 'topology': topology | ||
| 'api_url': api_url, | ||
| 'graph_url': graph_url | ||
| }) | ||
| return TemplateResponse(request, 'admin/%s/visualize.html' % opts.app_label, context) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from django.db import models | ||
| from django.utils.translation import ugettext_lazy as _ | ||
|
|
||
| from .base import TimeStampedEditableModel | ||
|
|
||
|
|
||
| class AbstractSnapshot(TimeStampedEditableModel): | ||
| """ | ||
| NetJSON NetworkGraph Snapshot implementation | ||
| """ | ||
| topology = models.ForeignKey('django_netjsongraph.topology') | ||
| data = models.TextField(blank=False) | ||
| date = models.DateField(auto_now=True) | ||
|
|
||
| class Meta: | ||
| verbose_name_plural = _('snapshots') | ||
| abstract = True | ||
|
|
||
| def __str__(self): | ||
| return "{0}: {1}".format(self.topology.label, self.date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from . import BaseSaveSnapshotCommand | ||
| from ...models import Topology | ||
|
|
||
|
|
||
| class Command(BaseSaveSnapshotCommand): | ||
| topology_model = Topology |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Generated by Django 1.11.3 on 2017-07-24 20:26 | ||
| from __future__ import unicode_literals | ||
|
|
||
| import uuid | ||
|
|
||
| import django.db.models.deletion | ||
| import django.utils.timezone | ||
| import model_utils.fields | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('django_netjsongraph', '0004_increased_addresses_maxlength'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='Snapshot', | ||
| fields=[ | ||
| ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
| ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), | ||
| ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), | ||
| ('data', models.TextField()), | ||
| ('date', models.DateField(auto_now=True)), | ||
| ('topology', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_netjsongraph.Topology')), | ||
| ], | ||
| options={ | ||
| 'abstract': False, | ||
| }, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,5 +46,5 @@ input[type=text].readonly{ | |
|
|
||
| .njg-overlay{ | ||
| top: auto; | ||
| bottom: 10px; | ||
| bottom: 50px; | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
django_netjsongraph/static/netjsongraph/css/lib/jquery-ui.min.css
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
django_netjsongraph/static/netjsongraph/js/lib/jquery-ui.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
django_netjsongraph/static/netjsongraph/js/topology-switcher.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| $(function() { | ||
| $('#dp').datepicker(); | ||
| d = new Date(); | ||
| month = d.getMonth() + 1; | ||
| day = d.getDate(); | ||
| default_date = (month<10? '0':'') + month + '/' + | ||
| (day<10? '0':'') + day + '/' + | ||
| d.getFullYear(); | ||
| $('#dp').val(default_date); | ||
| current_date = d.getFullYear() + '-' + | ||
| (month<10? '0':'') + month + '-' + | ||
| (day<10? '0':'') + day; | ||
| $('#submit').click(function() { | ||
| query_date = $('#dp').val(); | ||
| date = query_date.split('/').reverse(); | ||
| if(date != []){ | ||
| var x = date[1]; | ||
| date[1] = date[2]; | ||
| date[2] = x; | ||
| } | ||
| date = date.join('-'); | ||
| graph_url = $('.switcher').attr('graph-url') + '?date=' + date; | ||
| if(current_date == date){ | ||
| graph_url = window.location.href; | ||
| } | ||
| body = $('body'); | ||
| $.get(graph_url, function(html) { | ||
| body.html(html); | ||
| $('#dp').val(query_date); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write a test in which you supply a rubbish date here, make it fail and then find a fix (great occasion to learn TDD)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I get it 😄