|
@@ -11,13 +11,13 @@ from django.shortcuts import render_to_r
|
|
|
from django.views.generic import TemplateView, DetailView, CreateView, UpdateView, DeleteView
|
|
|
|
|
|
# Third-party application imports.
|
|
|
from braces.views import MultiplePermissionsRequiredMixin
|
|
|
|
|
|
# Application imports.
|
|
|
from .forms import EntityForm, InterfaceForm, CommunicationForm
|
|
|
from .forms import EntityForm, InterfaceForm, CommunicationForm, ProjectForm
|
|
|
from .models import Project, Entity, Location, Interface, Communication
|
|
|
from .utils import generate_entity_iptables
|
|
|
|
|
|
|
|
|
class IndexView(MultiplePermissionsRequiredMixin, TemplateView):
|
|
|
"""
|
|
@@ -250,67 +250,41 @@ def project_iptables(request, project_id
|
|
|
class ProjectCreateView(MultiplePermissionsRequiredMixin, CreateView):
|
|
|
"""
|
|
|
View for creating a new project.
|
|
|
"""
|
|
|
|
|
|
model = Project
|
|
|
form_class = ProjectForm
|
|
|
template_name_suffix = "_create_form"
|
|
|
|
|
|
# Required permissions.
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.add_project",),
|
|
|
}
|
|
|
|
|
|
# Raise authorisation denied exception for unmet permissions.
|
|
|
raise_exception = True
|
|
|
|
|
|
def get_form(self, form_class):
|
|
|
"""
|
|
|
Implements an override for the default form constructed for the create
|
|
|
view that includes some better styling of input widgets.
|
|
|
"""
|
|
|
|
|
|
form = super(ProjectCreateView, self).get_form(form_class)
|
|
|
form.fields["name"].widget.attrs["class"] = "span6"
|
|
|
form.fields["name"].widget.attrs["placeholder"] = "New Project"
|
|
|
form.fields["description"].widget.attrs["class"] = "span6"
|
|
|
form.fields["description"].widget.attrs["placeholder"] = "Description for new project."
|
|
|
|
|
|
return form
|
|
|
|
|
|
|
|
|
class ProjectUpdateView(MultiplePermissionsRequiredMixin, UpdateView):
|
|
|
"""
|
|
|
View for modifying an existing project.
|
|
|
"""
|
|
|
|
|
|
model = Project
|
|
|
form_class = ProjectForm
|
|
|
template_name_suffix = "_update_form"
|
|
|
|
|
|
# Required permissions.
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.change_project",),
|
|
|
}
|
|
|
|
|
|
# Raise authorisation denied exception for unmet permissions.
|
|
|
raise_exception = True
|
|
|
|
|
|
def get_form(self, form_class):
|
|
|
"""
|
|
|
Implements an override for the default form constructed for the create
|
|
|
view that includes some better styling of input widgets.
|
|
|
"""
|
|
|
|
|
|
form = super(ProjectUpdateView, self).get_form(form_class)
|
|
|
form.fields["name"].widget.attrs["class"] = "span6"
|
|
|
form.fields["name"].widget.attrs["placeholder"] = "Project name"
|
|
|
form.fields["description"].widget.attrs["class"] = "span6"
|
|
|
form.fields["description"].widget.attrs["placeholder"] = "Description for project."
|
|
|
|
|
|
return form
|
|
|
|
|
|
|
|
|
class ProjectDeleteView(MultiplePermissionsRequiredMixin, DeleteView):
|
|
|
"""
|
|
|
View for deleting a project.
|
|
|
"""
|
|
|
|