Changeset - e8434f637f9f
[Not reviewed]
default
1 3 0
Branko Majic (branko) - 11 years ago 2013-03-24 13:32:48
branko@majic.rs
Removed the line stripper middleware since it interfered with regular template lookups. Added some custom code to remove all blank lines from iptables rendering instead.
4 files changed with 8 insertions and 82 deletions:
0 comments (0 inline, 0 general)
conntrackt/stripper.py
Show inline comments
 
deleted file
conntrackt/templates/conntrackt/entity_iptables.html
Show inline comments
 
@@ -5,12 +5,14 @@
 
{% for interface in entity.interface_set.all %}
 
  {% for communication in interface.destination_set.all %}
 
    {% ifchanged communication.description %}
 

	
 
      {% if communication.description %}
 
# {{communication.description}}
 
      {% else  %}
 
# Communications without desecription.
 
      {% endif %}
 
    {% endifchanged %}
 
{% iptables communication %}
 
  {% endfor %}
 
{% endfor %}
 
:FORWARD ACCEPT [0:0]
conntrackt/views.py
Show inline comments
 
# For generating ZIP files.
 
from StringIO import StringIO
 
from zipfile import ZipFile, ZIP_DEFLATED
 
import re
 

	
 
# Django-specific imports.
 
from django.http import HttpResponse
 
from django.shortcuts import render_to_response, get_object_or_404
 
from django.views.generic import TemplateView, DetailView
 

	
 
@@ -96,12 +97,17 @@ class IptablesView(DetailView):
 
                                                                content_type='text/plain', **kwargs)
 

	
 
        # Add the Content-Disposition information for the browser, telling the
 
        # browser to download the file with suggested filename.
 
        response['Content-Disposition']="attachment; filename=%s-iptables.conf" % self.object.name.lower().replace(" ", "_")
 

	
 
        # Render the response, and remove the blank lines from the template.
 
        response.render()
 
        response.content = re.sub('^\s*\n', '', response.content)
 
        response.content = re.sub('\n\s*\n', '\n', response.content)
 

	
 
        # Return the modified response.
 
        return response
 

	
 
def get_project_iptables(request, project_id, location_id = None):
 
    """
 
    Custom view for obtaining iptables for all entities of a project or project
projtest/projtest/settings.py
Show inline comments
 
@@ -78,13 +78,12 @@ STATICFILES_FINDERS = (
 

	
 
# Make this unique, and don't share it with anybody.
 
SECRET_KEY = '%s-x^wskhxu#5%o)0ck71g7o@7p18has!9_#(h(f@j@$97pcaw'
 

	
 
# List of callables that know how to import templates from various sources.
 
TEMPLATE_LOADERS = (
 
    'conntrackt.stripper.Loader',
 
    'django.template.loaders.filesystem.Loader',
 
    'django.template.loaders.app_directories.Loader',
 
#     'django.template.loaders.eggs.Loader',
 
)
 

	
 
MIDDLEWARE_CLASSES = (
 
@@ -92,13 +91,12 @@ MIDDLEWARE_CLASSES = (
 
    'django.contrib.sessions.middleware.SessionMiddleware',
 
    'django.middleware.csrf.CsrfViewMiddleware',
 
    'django.contrib.auth.middleware.AuthenticationMiddleware',
 
    'django.contrib.messages.middleware.MessageMiddleware',
 
    # Uncomment the next line for simple clickjacking protection:
 
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 
    'conntrackt.stripper.StripperMiddleware'
 
)
 

	
 
ROOT_URLCONF = 'projtest.urls'
 

	
 
# Python dotted path to the WSGI application used by Django's runserver.
 
WSGI_APPLICATION = 'projtest.wsgi.application'
0 comments (0 inline, 0 general)