|
@@ -595,6 +595,89 @@ class InterfaceCreateView(MultiplePermis
|
|
|
interface has been created.
|
|
|
|
|
|
The URL in this case will be set to entity's details page.
|
|
|
"""
|
|
|
|
|
|
return reverse("entity", args=(self.object.entity.pk,))
|
|
|
|
|
|
|
|
|
class InterfaceUpdateView(MultiplePermissionsRequiredMixin, UpdateView):
|
|
|
"""
|
|
|
View for updating an existing interface.
|
|
|
"""
|
|
|
|
|
|
model = Interface
|
|
|
form_class = InterfaceForm
|
|
|
template_name_suffix = "_update_form"
|
|
|
|
|
|
# Required permissions.
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.change_interface",),
|
|
|
}
|
|
|
|
|
|
# Raise authorisation denied exception for unmet permissions.
|
|
|
raise_exception = True
|
|
|
|
|
|
def get_form(self, form_class):
|
|
|
"""
|
|
|
Returns an instance of form that can be used by the view.
|
|
|
|
|
|
The method will limit the entities that can be selected for the
|
|
|
interface to the ones that belong to the same project as the currently
|
|
|
set entity.
|
|
|
"""
|
|
|
|
|
|
form = super(InterfaceUpdateView, self).get_form(form_class)
|
|
|
|
|
|
# Limit the entities to same project.
|
|
|
form.fields["entity"].queryset = Entity.objects.filter(project=self.object.entity.project)
|
|
|
|
|
|
return form
|
|
|
|
|
|
def get_success_url(self):
|
|
|
"""
|
|
|
Returns the URL to which the user should be redirected after an
|
|
|
interface has been updated.
|
|
|
|
|
|
The URL in this case will be set to entity's details page.
|
|
|
"""
|
|
|
|
|
|
return reverse("entity", args=(self.object.entity.pk,))
|
|
|
|
|
|
|
|
|
class InterfaceDeleteView(MultiplePermissionsRequiredMixin, DeleteView):
|
|
|
"""
|
|
|
View for deleting an interface.
|
|
|
"""
|
|
|
|
|
|
model = Interface
|
|
|
|
|
|
# Required permissions.
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.delete_interface",),
|
|
|
}
|
|
|
|
|
|
# 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
|
|
|
interface deletion.
|
|
|
"""
|
|
|
|
|
|
messages.success(self.request, "Interface %s has been removed." % self.get_object().name, extra_tags="alert alert-success")
|
|
|
|
|
|
return super(InterfaceDeleteView, self).post(*args, **kwargs)
|
|
|
|
|
|
def delete(self, *args, **kwargs):
|
|
|
"""
|
|
|
Deletes the object. This method is overridden in order to obtain the
|
|
|
entity ID for success URL.
|
|
|
|
|
|
@TODO: Fix this once Django 1.6 comes out with fix from ticket 19044.
|
|
|
"""
|
|
|
|
|
|
self.success_url = reverse("entity", args=(self.get_object().entity.id,))
|
|
|
|
|
|
return super(InterfaceDeleteView, self).delete(*args, **kwargs)
|
|
|
|