|
@@ -26,16 +26,18 @@ import itertools
|
|
|
# Third-party Python library imports.
|
|
|
import palette
|
|
|
import pydot
|
|
|
|
|
|
# Django imports.
|
|
|
from django.template import Context, loader
|
|
|
from django.utils.html import format_html
|
|
|
from django.utils.text import capfirst
|
|
|
|
|
|
# Application imports.
|
|
|
import iptables
|
|
|
from .models import Communication
|
|
|
import models
|
|
|
|
|
|
|
|
|
def generate_entity_iptables(entity):
|
|
|
"""
|
|
|
Generates full iptables rules for the supplied entity. The generated rules
|
|
|
can be fed directly to the iptables-restore utility.
|
|
@@ -184,13 +186,13 @@ def generate_project_diagram(project):
|
|
|
|
|
|
# Add clusters to the graph.
|
|
|
for cluster in clusters.values():
|
|
|
graph.add_subgraph(cluster)
|
|
|
|
|
|
# Get all project communications.
|
|
|
communications = Communication.objects.filter(source__entity__project=project)
|
|
|
communications = models.Communication.objects.filter(source__entity__project=project)
|
|
|
|
|
|
# Add the edges (lines) representing communications, drawing them with same
|
|
|
# colour as the source node/entity.
|
|
|
for comm in communications:
|
|
|
edge_color = node_colors[comm.source.entity.id]
|
|
|
|
|
@@ -198,6 +200,30 @@ def generate_project_diagram(project):
|
|
|
|
|
|
edge = pydot.Edge(comm.source.entity.name, comm.destination.entity.name, label=label, color=edge_color)
|
|
|
|
|
|
graph.add_edge(edge)
|
|
|
|
|
|
return graph
|
|
|
|
|
|
|
|
|
def list_formatter_callback(obj):
|
|
|
"""
|
|
|
Creates model object representation in format:
|
|
|
|
|
|
MODEL_NAME: OBJECT_REPRESENTATION
|
|
|
|
|
|
If passed object has a callable get_absolute_url method, the
|
|
|
instance representation will be surrouned by an HTML anchor
|
|
|
(<a></a>) where target is set to value of the get_absolute_url()
|
|
|
method call.
|
|
|
|
|
|
Arguments:
|
|
|
obj - Model object whose representation should be returned.
|
|
|
|
|
|
Returns:
|
|
|
String represenation of passed model object.
|
|
|
"""
|
|
|
|
|
|
try:
|
|
|
return format_html('<strong>{0}</strong>: <a href="{1}">{2}</a>', capfirst(obj._meta.verbose_name), obj.get_absolute_url(), str(obj))
|
|
|
except AttributeError:
|
|
|
return format_html('<strong>{0}</strong>: {1}', capfirst(obj._meta.verbose_name), str(obj))
|