Changeset - b9fabc69b505
[Not reviewed]
default
0 4 0
Branko Majic (branko) - 11 years ago 2013-07-13 21:13:50
branko@majic.rs
CONNT-4: Implemented delete view for entities, and integrated it with the rest of application.
4 files changed with 69 insertions and 7 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/conntrackt/entity_detail.html
Show inline comments
 
@@ -8,7 +8,16 @@
 
{% with project=entity.project location=entity.location %}
 

	
 
{% if entity %}
 
<h1>{{entity.name}}</h1>
 
<div class="row">
 
  <h1 class="span12">{{entity.name}}</h1>
 
</div>
 
<hr>
 
<div class="row">
 
  <div class="span12">
 
    {% html_link "Remove" "entity_delete" entity.id class="btn btn-primary" %}
 
  </div>
 
</div>
 
<hr>
 
<dl>
 
  <dt>Project</dt><dd>{% html_link project.name 'project'  project.id  %}</dd>
 
  <dt>Location</dt><dd>{{location.name}}</dd>
conntrackt/templates/conntrackt/location_widget.html
Show inline comments
 
{% load conntrackt_tags %}
 
  <table class="table table-striped">
 
    <tr><td><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></tr>
 
    <tr>
 
      <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>
 
    </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></tr>
 
    <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-remove"></i>' 'entity_delete' entity.id class="btn btn-link"  %}</td>
 
    </tr>
 
{% endfor %}
 
    {% with project_id=project.id|slugify location_id=location.id|slugify %}
 
    <tr><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></tr>
 
    <tr>
 
      <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>
 
    </tr>
 
    {% endwith %}
 
  </table>
 

	
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
 
from .views import EntityCreateView, 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 deleting an entity.
 
    url(r'^entity/(?P<pk>\d+)/remove/$', EntityDeleteView.as_view(), name="entity_delete"),
 

	
 
    # View for rendering iptables rules for a specific entity.
 
    url(r'^entity/(?P<pk>\d+)/iptables/$', entity_iptables, name="entity_iptables"),
conntrackt/views.py
Show inline comments
 
@@ -5,7 +5,7 @@ from zipfile import ZipFile, ZIP_DEFLATE
 
# Django imports.
 
from django.contrib.auth.decorators import permission_required
 
from django.contrib import messages
 
from django.core.urlresolvers import reverse_lazy
 
from django.core.urlresolvers import reverse, reverse_lazy
 
from django.http import HttpResponse
 
from django.shortcuts import render_to_response, get_object_or_404
 
from django.views.generic import TemplateView, DetailView, CreateView, UpdateView, DeleteView
 
@@ -86,7 +86,7 @@ class ProjectView(MultiplePermissionsReq
 

	
 
        # Add the (location, entities) tuple for each location that has entities
 
        # belonging to the related project.
 
        for location in Location.objects.filter(entity__project=self.object).distinct():
 
        for location in Location.objects.filter(entity__project=self.object).distinct().order_by("name"):
 
            entities = Entity.objects.filter(project=self.object, location=location)
 
            location_entities.append((location, entities))
 

	
 
@@ -473,3 +473,42 @@ class EntityCreateView(MultiplePermissio
 
        initial["location"] = self.request.GET.get("location", None)
 

	
 
        return initial
 

	
 

	
 
class EntityDeleteView(MultiplePermissionsRequiredMixin, DeleteView):
 
    """
 
    View for deleting an entity.
 
    """
 

	
 
    model = Entity
 

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

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

	
 
    def post(self, *args, **kwargs):
 
        """
 
        Add a success message that will be displayed to the user to confirm the
 
        entity deletion.
 
        """
 

	
 
        messages.success(self.request, "Entity %s has been removed." % self.get_object().name, extra_tags="alert alert-success")
 

	
 
        return super(EntityDeleteView, self).post(*args, **kwargs)
 

	
 

	
 
    def delete(self, *args, **kwargs):
 
        """
 
        Deletes the object. This method is overridden in order to obtain the
 
        project ID for success URL.
 

	
 
        @TODO: Fix this once Django 1.6 comes out with fix from ticket 19044.
 
        """
 

	
 
        self.success_url = reverse("project", args=(self.get_object().project.id,))
 

	
 
        return super(EntityDeleteView, self).delete(*args, **kwargs)
0 comments (0 inline, 0 general)