Changeset - 5deeefd8d0fc
[Not reviewed]
default
0 5 1
Branko Majic (branko) - 11 years ago 2013-07-14 13:05:33
branko@majic.rs
CONNT-4: Added support for updating entity information.
6 files changed with 109 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/conntrackt/entity_detail.html
Show inline comments
 
@@ -11,9 +11,18 @@
 
<div class="row">
 
  <h1 class="span12">{{entity.name}}</h1>
 
</div>
 
<hr>
 

	
 
{% if entity.description %}
 
<div class="row">
 
  <div class="span12">
 
    {{entity.description}}
 
  </div>
 
</div>
 
<hr>
 
{% endif %}
 
<div class="row">
 
  <div class="span12">
 
    {% html_link "Edit" "entity_update" entity.id class="btn btn-primary" %}
 
    {% html_link "Remove" "entity_delete" entity.id class="btn btn-primary" %}
 
  </div>
 
</div>
conntrackt/templates/conntrackt/entity_update_form.html
Show inline comments
 
new file 100644
 
{% extends "conntrackt/base.html" %}
 

	
 
{# For html_link #}
 
{% load conntrackt_tags %}
 
{# For Bootstrapped forms #}
 
{% load crispy_forms_tags %}
 

	
 
{% block content %}
 
<div class="row">
 
  <h1 class="span12">Edit entity {{entity.name}}</h1>
 
</div>
 
<div class="row">
 
  <div class="span6">
 
    <form action="" method="post">
 
      <div class="controls controls-row">
 
      {% csrf_token %}
 
      {{ form | crispy }}
 
      </div>
 
      <div class="controls">
 
        <button type="submit" class="btn btn-primary">Update</button>
 
      </div>
 
    </form>
 
  </div>
 
</div>
 
{% endblock content %}
conntrackt/templates/conntrackt/location_widget.html
Show inline comments
 
@@ -4,11 +4,13 @@
 
      <td style="width:99%"><strong>{{location.name}}</strong></td>
 
      <td>{% html_link '<i class="icon-book"></i>' 'project_location_iptables' project.id location.id class="btn btn-link" %}</td>
 
      <td></td>
 
      <td></td>
 
    </tr>
 
{% for entity in entities %}
 
    <tr>
 
      <td>{% html_link entity.name 'entity' entity.id class="btn btn-link" %}</td>
 
      <td>{% html_link '<i class="icon-list"></i>' 'entity_iptables' entity.id class="btn btn-link" %}</td>
 
      <td>{% html_link '<i class="icon-edit"></i>' 'entity_update' entity.id class="btn btn-link"  %}</td>
 
      <td>{% html_link '<i class="icon-remove"></i>' 'entity_delete' entity.id class="btn btn-link"  %}</td>
 
    </tr>
 
{% endfor %}
 
@@ -17,6 +19,7 @@
 
      <td>{% html_link "Add entity" "entity_create" class="btn btn-primary btn-mini" get="project="|add:project_id|add:"&location="|add:location_id %}</td>
 
      <td></td>
 
      <td></td>
 
      <td></td>
 
    </tr>
 
    {% endwith %}
 
  </table>
conntrackt/tests/test_views.py
Show inline comments
 
@@ -929,3 +929,53 @@ class EntityDeleteViewTest(TestCase):
 
                                    follow=True)
 

	
 
        self.assertEqual(response.context["request"].META["PATH_INFO"], reverse("project", args=(1,)))
 

	
 

	
 
class EntityUpdateViewTest(TestCase):
 

	
 
    fixtures = ['test-data.json']
 

	
 
    def setUp(self):
 
        # Set-up web client.
 
        self.client = Client()
 

	
 
        # Set-up users with different view permissions.
 
        self.user = {}
 
        self.user["fullperms"] = User.objects.create_user("fullperms", "fullperms@example.com", "fullperms")
 
        self.user["fullperms"].user_permissions.add(Permission.objects.get(codename="change_entity"))
 
        self.user["noperms"] = User.objects.create_user("noperms", "noperms@example.com", "noperms")
 

	
 
    def test_permission_denied(self):
 
        """
 
        Tests if permission will be denied for client without sufficient privileges.
 
        """
 

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

	
 
        response = self.client.get(reverse("entity_update", args=(1,)))
 

	
 
        self.assertContains(response, "You have insufficient privileges to access this resource. Please contact your local system administrator if you believe you should have been granted access.", status_code=403)
 

	
 
    def test_permission_granted(self):
 
        """
 
        Tests if permission will be granted for user with correct privileges.
 
        """
 

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

	
 
        response = self.client.get(reverse("entity_update", args=(1,)))
 

	
 
        self.assertEqual(response.status_code, 200)
 

	
 
    def test_content(self):
 
        """
 
        Tests if the form comes pre-populated with proper content.
 
        """
 

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

	
 
        response = self.client.get(reverse("entity_update", args=(1,)))
 

	
 
        self.assertContains(response, ">Edit entity Test Entity 1<")
 
        self.assertContains(response, 'value="Test Entity 1"')
 
        self.assertContains(response, "This is a test entity 1.")
conntrackt/urls.py
Show inline comments
 
@@ -6,7 +6,7 @@ from django.contrib.auth.views import lo
 
from .views import IndexView, EntityView, entity_iptables, project_iptables
 
from .views import ProjectView, ProjectCreateView, ProjectUpdateView, ProjectDeleteView
 
from .views import LocationCreateView, LocationUpdateView, LocationDeleteView
 
from .views import EntityCreateView, EntityDeleteView
 
from .views import EntityCreateView, EntityUpdateView, EntityDeleteView
 

	
 

	
 
urlpatterns = patterns(
 
@@ -37,6 +37,8 @@ urlpatterns = patterns(
 
        name='entity'),
 
    # View for creating a new entity.
 
    url(r'^entity/add/$', EntityCreateView.as_view(), name="entity_create"),
 
    # View for updating an existing entity.
 
    url(r'^entity/(?P<pk>\d+)/edit/$', EntityUpdateView.as_view(), name="entity_update"),
 
    # View for deleting an entity.
 
    url(r'^entity/(?P<pk>\d+)/remove/$', EntityDeleteView.as_view(), name="entity_delete"),
 

	
conntrackt/views.py
Show inline comments
 
@@ -475,6 +475,24 @@ class EntityCreateView(MultiplePermissio
 
        return initial
 

	
 

	
 
class EntityUpdateView(MultiplePermissionsRequiredMixin, UpdateView):
 
    """
 
    View for updating an existing entity.
 
    """
 

	
 
    model = Entity
 
    form_class = EntityForm
 
    template_name_suffix = "_update_form"
 

	
 
    # Required permissions.
 
    permissions = {
 
        "all": ("conntrackt.change_entity",),
 
        }
 

	
 
    # Raise authorisation denied exception for unmet permissions.
 
    raise_exception = True
 
    
 

	
 
class EntityDeleteView(MultiplePermissionsRequiredMixin, DeleteView):
 
    """
 
    View for deleting an entity.
0 comments (0 inline, 0 general)