File diff 9b889983cd7b → 49f356923784
conntrackt/views.py
Show inline comments
 
@@ -13,13 +13,13 @@ from django.views.generic import Templat
 
# Third-party application imports.
 
from braces.views import MultiplePermissionsRequiredMixin, SetHeadlineMixin
 

	
 
# Application imports.
 
from .forms import ProjectForm, LocationForm, EntityForm, InterfaceForm, CommunicationForm
 
from .models import Project, Entity, Location, Interface, Communication
 
from .utils import generate_entity_iptables
 
from .utils import generate_entity_iptables, generate_project_diagram
 

	
 

	
 
class IndexView(MultiplePermissionsRequiredMixin, TemplateView):
 
    """
 
    Custom view used for rendering the index page.
 
    """
 
@@ -877,6 +877,41 @@ class CommunicationDeleteView(SetHeadlin
 
    def get_headline(self):
 
        """
 
        Set headline based on communication.
 
        """
 

	
 
        return "Delete communication %s" % self.object
 

	
 

	
 
@permission_required("conntrackt.view", raise_exception=True)
 
def project_diagram(request, pk):
 
    """
 
    Custom view that returns response containing diagram of project
 
    communications.
 

	
 
    The diagram will include coloured entities, with directional lines
 
    connecting the source and destination end entities.
 

	
 
    The output format is SVG.
 

	
 
    Arguments:
 

	
 
        request - Request object.
 

	
 
        pk - Project ID for which the diagram should be generated.
 

	
 
    Returns:
 

	
 
        Response object that contains the project diagram rendered as SVG.
 
    """
 

	
 
    # Fetch the project.
 
    project = get_object_or_404(Project, pk=pk)
 

	
 
    # Generate the diagram.
 
    content = generate_project_diagram(project).create_svg()
 

	
 
    # Set the mime type.
 
    response = HttpResponse(content, mimetype='image/svg+xml')
 

	
 
    # Return the response object.
 
    return response