Changeset - 421171af6c75
[Not reviewed]
default
0 11 0
Branko Majic (branko) - 6 years ago 2017-12-22 10:33:56
branko@majic.rs
CONNT-25: Updating application and project to use Django 1.11.x:

- Bumped Django version in both the development requirements and setup
script to 1.11.x.
- Bumped Django Crispy Forms to version 1.7.0 in both development
requirements and setup script.
- Updated import of URL-related modules to use the new path (previous
one is deprecated).
- Added explicit on_delete = models.CASCADE option to all foreign key
fields (old implicit behaviour will be deprecated in Django 2.0).
- Fixed the custom change_list.html template used in Django Admin to
render without errors.
11 files changed with 22 insertions and 23 deletions:
0 comments (0 inline, 0 general)
conntrackt/admin.py
Show inline comments
 
@@ -39,13 +39,13 @@
 
# Django Conntrackt.  If not, see <http://www.gnu.org/licenses/>.
 
#
 

	
 

	
 
# Django imports.
 
from django.contrib import admin
 
from django.core.urlresolvers import resolve
 
from django.urls import resolve
 

	
 
# Application imports.
 
from .models import Project, Location, Entity, Interface, Communication
 

	
 

	
 
class InterfaceInline(admin.StackedInline):
conntrackt/models.py
Show inline comments
 
@@ -19,13 +19,13 @@
 
#
 

	
 

	
 
# Django imports.
 
from django.contrib.admin.utils import NestedObjects
 
from django.core.exceptions import ValidationError
 
from django.core.urlresolvers import reverse
 
from django.urls import reverse
 
from django.db import models
 
from django.db.models.query_utils import Q
 

	
 
# Application imports.
 
from .utils import list_formatter_callback, get_distinct_colors
 

	
 
@@ -245,14 +245,14 @@ class Entity(RelatedCollectorMixin, mode
 
      location - Foreign key pointing to the location at which the entity is
 
      located.
 
    """
 

	
 
    name = models.CharField(max_length=100)
 
    description = models.TextField(blank=True)
 
    project = models.ForeignKey(Project)
 
    location = models.ForeignKey(Location)
 
    project = models.ForeignKey(Project, on_delete = models.CASCADE)
 
    location = models.ForeignKey(Location, on_delete = models.CASCADE)
 
    objects = SearchManager()
 

	
 
    class Meta:
 
        # Fix the plural form used by Django.
 
        verbose_name_plural = 'entities'
 
        # Enforce uniqueness of entity name in a project.
 
@@ -342,13 +342,13 @@ class Interface(RelatedCollectorMixin, m
 
      (255.255.255.255), but in case of subnet entities this can be used for
 
      denoting the network netmask.
 
    """
 

	
 
    name = models.CharField(max_length=100, default='eth0')
 
    description = models.TextField(blank=True, default='Main network interface.')
 
    entity = models.ForeignKey(Entity)
 
    entity = models.ForeignKey(Entity, on_delete = models.CASCADE)
 
    address = models.GenericIPAddressField()
 
    netmask = models.GenericIPAddressField(default='255.255.255.255')
 

	
 
    class Meta:
 
        # Enforce uniqueness of interface name in an entity. Enforce uniqueness
 
        # of IP address in a subnet for an entity.
 
@@ -404,14 +404,14 @@ class Communication(RelatedCollectorMixi
 
    PROTOCOL_CHOICES = (
 
        ('TCP', 'TCP'),
 
        ('UDP', 'UDP'),
 
        ('ICMP', 'ICMP'),
 
        )
 

	
 
    source = models.ForeignKey(Interface, related_name='source_set')
 
    destination = models.ForeignKey(Interface, related_name='destination_set')
 
    source = models.ForeignKey(Interface, related_name='source_set', on_delete = models.CASCADE)
 
    destination = models.ForeignKey(Interface, related_name='destination_set', on_delete = models.CASCADE)
 
    protocol = models.CharField(max_length=10, choices=PROTOCOL_CHOICES)
 
    port = models.IntegerField(default=0)
 
    description = models.TextField(blank=True)
 

	
 
    class Meta:
 
        # Enforce uniqueness of communication.
conntrackt/templates/admin/conntrackt/communication/change_list.html
Show inline comments
 
{% extends "admin/change_list.html" %}
 
{% load i18n admin_static admin_list %}
 
{% load url from future %}
 
{% load admin_urls %}
 

	
 
{% block object-tools-items %}
 
            <li>
 
              {# Add the GET parameters from the admin's filter to 'Add entity' button #}
 
              {# so we can perform some filtering on source/destination interfaces. #}
conntrackt/templatetags/conntrackt_tags.py
Show inline comments
 
@@ -18,13 +18,13 @@
 
# Django Conntrackt.  If not, see <http://www.gnu.org/licenses/>.
 
#
 

	
 

	
 
# Django imports.
 
from django import template
 
from django.core import urlresolvers
 
from django import urls
 
from django.utils.html import format_html
 

	
 

	
 
# Get an instance of Django's template library.
 
register = template.Library()
 

	
 
@@ -59,13 +59,13 @@ def html_link(text, view, *args, **kwarg
 
    for key in kwargs.keys():
 
        if key not in ("get", "class", "title", "id"):
 
            raise template.TemplateSyntaxError("Unknown argument for 'html_link' tag: %r" % key)
 

	
 
    # Generate the URL by using the supplied view name and arguments that should
 
    # be passed to the view.
 
    url = urlresolvers.reverse(view, args=args)
 
    url = urls.reverse(view, args=args)
 

	
 
    # Set-up the base pattern (url, parameters, text).
 
    if 'get' in kwargs:
 
        pattern = '<a href="{url}?{get}"'
 
    else:
 
        pattern = '<a href="{url}"'
 
@@ -118,14 +118,14 @@ def current_url_equals(context, url_name
 
    """
 

	
 
    # Assume that we have not been able to resolve the request path to an URL.
 
    resolved = False
 
    try:
 
        # Use the request path, and resolve it to a URL name.
 
        resolved = urlresolvers.resolve(context.get('request').path)
 
    except urlresolvers.Resolver404:
 
        resolved = urls.resolve(context.get('request').path)
 
    except urls.Resolver404:
 
        # This means we haven't been able to resolve the path from request.
 
        pass
 

	
 
    # If the request was resolved and URL names match, verify that the kwargs
 
    # match as well.
 
    matches = resolved and resolved.url_name == url_name
conntrackt/tests/test_tags.py
Show inline comments
 
@@ -32,13 +32,13 @@ from django.template import Context, Tem
 
from django.test import TestCase
 

	
 
# Application imports
 
from conntrackt.templatetags.conntrackt_tags import html_link, active_link, current_url_equals
 

	
 

	
 
@mock.patch('conntrackt.templatetags.conntrackt_tags.urlresolvers.reverse')
 
@mock.patch('conntrackt.templatetags.conntrackt_tags.urls.reverse')
 
class HtmlLinkTest(TestCase):
 

	
 
    def test_url_reverse_called_with_passed_in_args(self, mock_reverse):
 
        """
 
        Tests if URL reversing is performed using the correct set of
 
        passed-in arguments.
conntrackt/tests/test_views.py
Show inline comments
 
@@ -26,13 +26,13 @@ from zipfile import ZipFile, ZIP_DEFLATE
 

	
 
# Python third-party library imports.
 
import mock
 

	
 
# Django imports.
 
from django.core.exceptions import ValidationError
 
from django.core.urlresolvers import reverse
 
from django.urls import reverse
 
from django.http import Http404
 
from django.test import RequestFactory
 
from django.test import TestCase
 
from django.utils.http import urlquote
 

	
 
# Application imports
conntrackt/views.py
Show inline comments
 
@@ -25,17 +25,17 @@ from zipfile import ZipFile, ZIP_DEFLATE
 
import json
 

	
 
# Django imports.
 
from django.contrib.auth.decorators import permission_required
 
from django.contrib import messages
 
from django.core.exceptions import ValidationError
 
from django.core.urlresolvers import reverse, reverse_lazy
 
from django.db.models import Q
 
from django.db.models.deletion import Collector
 
from django.http import HttpResponse
 
from django.shortcuts import render_to_response, get_object_or_404
 
from django.urls import reverse, reverse_lazy
 
from django.views.generic import TemplateView, DetailView, CreateView, UpdateView, DeleteView, View
 

	
 
# Third-party application imports.
 
from braces.views import MultiplePermissionsRequiredMixin, SetHeadlineMixin
 

	
 
# Application imports.
requirements/base.in
Show inline comments
 
@@ -18,16 +18,16 @@
 
#
 

	
 
# Convenience mixins for Django (for authentication etc).
 
django-braces~=1.12.0
 

	
 
# Convenience tools for controlling rendering of forms while embracing DRY.
 
django-crispy-forms~=1.6.0
 
django-crispy-forms~=1.7.0
 

	
 
# Web framework used by application.
 
django~=1.10.0
 
django~=1.11.0
 

	
 
# Library for programatic calculation of colours (contrasts,
 
# inversions etc).
 
palette~=0.2.0
 

	
 
# Interaface towards Graphviz for chart generation.
requirements/development.txt
Show inline comments
 
@@ -7,14 +7,14 @@
 
alabaster==0.7.10         # via sphinx
 
babel==2.5.1              # via sphinx
 
certifi==2017.11.5        # via requests
 
chardet==3.0.4            # via requests
 
coverage==4.4.2
 
django-braces==1.12.0
 
django-crispy-forms==1.6.1
 
django==1.10.8
 
django-crispy-forms==1.7.0
 
django==1.11.8
 
docutils==0.14            # via sphinx
 
factory-boy==2.1.2
 
funcsigs==1.0.2           # via mock
 
idna==2.6                 # via requests
 
imagesize==0.7.1          # via sphinx
 
jinja2==2.10              # via sphinx
requirements/test.txt
Show inline comments
 
@@ -7,14 +7,14 @@
 
alabaster==0.7.10         # via sphinx
 
babel==2.5.1              # via sphinx
 
certifi==2017.11.5        # via requests
 
chardet==3.0.4            # via requests
 
coverage==4.4.2
 
django-braces==1.12.0
 
django-crispy-forms==1.6.1
 
django==1.10.8
 
django-crispy-forms==1.7.0
 
django==1.11.8
 
docutils==0.14            # via sphinx
 
factory-boy==2.1.2
 
funcsigs==1.0.2           # via mock
 
idna==2.6                 # via requests
 
imagesize==0.7.1          # via sphinx
 
jinja2==2.10              # via sphinx
setup.py
Show inline comments
 
@@ -22,14 +22,14 @@
 
import os
 
from setuptools import setup, find_packages
 

	
 
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
INSTALL_REQUIREMENTS = [
 
    "django-braces~=1.12.0",
 
    "django-crispy-forms~=1.6.0",
 
    "django~=1.10.0",
 
    "django-crispy-forms~=1.7.0",
 
    "django~=1.11.0",
 
    "palette~=0.2.0",
 
    "pydot~=1.2.0",
 
]
 

	
 
# allow setup.py to be run from any path
 
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
0 comments (0 inline, 0 general)