|
@@ -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)
|