Changeset - 26c0c45a8480
[Not reviewed]
default
0 3 0
Branko Majic (branko) - 11 years ago 2013-07-09 23:33:28
branko@majic.rs
CONNT-7: Modified the index view to show listing of projects and entities in two columns. Updated the index test accordingly.
3 files changed with 78 insertions and 17 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/conntrackt/index.html
Show inline comments
 
@@ -4,30 +4,64 @@
 
{% load conntrackt_tags %}
 

	
 
{% block content %}
 

	
 
<div class="row">
 
  <h1 class="span12">Welcome to Conntrackt</h1>
 
</div>
 

	
 
<div class="row">
 
    <div class="span12">Below you may find the list of projects that are available to you. Clicking on the project will take you to the summary page for that particular project. Clicking on an entity inside of a project will take you to the summary page of an entity.</div>
 
</div>
 

	
 
<hr>
 

	
 
<div class="row">
 
  <div class="span12">
 
    {% html_link "Add project" "project_create" class="btn btn-primary" %}
 
  </div>
 
</div>
 

	
 
<hr>
 

	
 
<div class="row">
 
{% if projects %}
 
  {% for project in projects %}
 
  <div class="span4">
 
    <div class="well">{% include "conntrackt/project_widget.html" %}</div>
 

	
 
  <div class="span6">
 
    <h2>Projects</h2>
 
    <div class="well">
 
    {% if projects %}
 
      <table class="table table-striped">
 
        {% for project in projects %}
 
          <tr>
 
            <td style="width:99%">{% html_link project.name "project" project.id class="btn btn-link" %}</td>
 
            <td>{% html_link '<i class="icon-list"></i>' "project_iptables" project.id class="btn btn-link" %}</td>
 
            <td>{% html_link '<i class="icon-edit"></i>' "project_update" project.id class="btn btn-link" %}</td>
 
            <td>{% html_link '<i class="icon-remove"></i>' "project_delete" project.id class="btn btn-link" %}</td>
 
          </tr>
 
        {% endfor %}
 
      </table>
 
    {% else %}
 
      There are no projects defined.
 
    {% endif %}
 
    </div>     
 
  </div>
 
  {% endfor %}
 
{% else %}
 
  <div class="span12">Currently there are no projects defined in the database. Use the administration pages in order to add a new project.</div>
 
{% endif %}
 

	
 
  <div class="span6">
 
    <h2>Locations</h2>
 
    <div class="well">
 
      {% if locations %}
 
        <table class="table table-striped">
 
          {% for location in locations %}
 
            <tr>
 
              <td style="width:99%">{{location.name}}</td>
 
            </tr>
 
          {% endfor %}
 
        </table>
 
      {% else %}
 
        There are no locations defined.
 
      {% endif %}
 
    </div>
 
  </div>
 

	
 
</div>
 

	
 
{% endblock %}
 

	
conntrackt/tests/test_views.py
Show inline comments
 
@@ -9,7 +9,7 @@ from django.test.client import Client
 
from django.contrib.auth.models import User, Permission
 

	
 
# Application imports
 
from conntrackt.models import Project
 
from conntrackt.models import Project, Location
 

	
 

	
 
class ViewTest(TestCase):
 
@@ -65,7 +65,19 @@ class IndexViewTest(ViewTest):
 
        self.client.login(username="fullperms", password="fullperms")
 
        response = self.client.get(reverse("index"))
 

	
 
        self.assertContains(response, "Currently there are no projects defined in the database. Use the administration pages in order to add a new project.")
 
        self.assertContains(response, "There are no projects defined.")
 

	
 
    def test_no_locations(self):
 
        """
 
        Tests the index view when no locations are defined.
 
        """
 

	
 
        Location.objects.all().delete()
 

	
 
        self.client.login(username="fullperms", password="fullperms")
 
        response = self.client.get(reverse("index"))
 

	
 
        self.assertContains(response, "There are no locations defined.")
 

	
 
    def test_projects_available(self):
 
        """
 
@@ -80,6 +92,19 @@ class IndexViewTest(ViewTest):
 
        self.assertContains(response, "Test Project 1")
 
        self.assertContains(response, "Test Project 2")
 

	
 
    def test_locations_available(self):
 
        """
 
        Tests if locations are show or not.
 
        """
 

	
 
        self.client.login(username="fullperms", password="fullperms")
 

	
 
        response = self.client.get(reverse("index"))
 

	
 
        self.assertQuerysetEqual(response.context["locations"], ["<Location: Test Location 1>", "<Location: Test Location 2>"])
 
        self.assertContains(response, "Test Location 1")
 
        self.assertContains(response, "Test Location 2")
 

	
 

	
 
class ProjectViewTest(ViewTest):
 

	
conntrackt/views.py
Show inline comments
 
@@ -27,7 +27,7 @@ class IndexView(MultiplePermissionsRequi
 

	
 
    # Required permissions.
 
    permissions = {
 
        "all": ("conntrackt.view", "conntrackt.view",),
 
        "all": ("conntrackt.view",),
 
        }
 
    # Raise authorisation denied exception for unmet permissions.
 
    raise_exception = True
 
@@ -44,9 +44,11 @@ class IndexView(MultiplePermissionsRequi
 
        # Set the context using the parent class.
 
        context = super(IndexView, self).get_context_data(**kwargs)
 

	
 
        # Store information about all projcts in context. Optimise database
 
        # access for the view.
 
        context['projects'] = Project.objects.all().prefetch_related('entity_set').order_by('name')
 
        # Store information about all projcts in context.
 
        context['projects'] = Project.objects.all().order_by('name')
 

	
 
        # Store information about all locations in context.
 
        context['locations'] = Location.objects.all().order_by('name')
 

	
 
        return context
 

	
 
@@ -59,7 +61,7 @@ class ProjectView(MultiplePermissionsReq
 
    model = Project
 

	
 
    permissions = {
 
        "all": ("conntrackt.view", "conntrackt.view",)
 
        "all": ("conntrackt.view",),
 
        }
 
    # Raise authorisation denied exception for unmet permissions.
 
    raise_exception = True
 
@@ -108,7 +110,7 @@ class EntityView(MultiplePermissionsRequ
 

	
 
    # Required permissions.
 
    permissions = {
 
        "all": ("conntrackt.view",)
 
        "all": ("conntrackt.view",),
 
        }
 
    # Raise authorisation denied exception for unmet permissions.
 
    raise_exception = True
0 comments (0 inline, 0 general)