|
@@ -4,9 +4,11 @@ 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.http import HttpResponse
|
|
|
from django.shortcuts import render_to_response, get_object_or_404
|
|
|
from django.views.generic import TemplateView, DetailView, CreateView
|
|
|
from django.views.generic import TemplateView, DetailView, CreateView, UpdateView, DeleteView
|
|
|
|
|
|
# Third-party application imports.
|
|
|
from braces.views import MultiplePermissionsRequiredMixin
|
|
@@ -237,7 +239,8 @@ class ProjectCreateView(MultiplePermissi
|
|
|
"""
|
|
|
|
|
|
model = Project
|
|
|
|
|
|
template_name_suffix = "_create_form"
|
|
|
|
|
|
# Required permissions.
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.add_project",),
|
|
@@ -260,3 +263,61 @@ class ProjectCreateView(MultiplePermissi
|
|
|
|
|
|
return form
|
|
|
|
|
|
|
|
|
class ProjectUpdateView(MultiplePermissionsRequiredMixin, UpdateView):
|
|
|
"""
|
|
|
View for modifying an existing project.
|
|
|
"""
|
|
|
|
|
|
model = Project
|
|
|
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.
|
|
|
"""
|
|
|
|
|
|
model = Project
|
|
|
|
|
|
# Required permissions.
|
|
|
permissions = {
|
|
|
"all": ("conntrackt.delete_project",),
|
|
|
}
|
|
|
|
|
|
# Raise authorisation denied exception for unmet permissions.
|
|
|
raise_exception = True
|
|
|
|
|
|
success_url = reverse_lazy("index")
|
|
|
|
|
|
def post(self, *args, **kwargs):
|
|
|
"""
|
|
|
Add a success message that will be displayed to the user to confirm the
|
|
|
project deletion.
|
|
|
"""
|
|
|
|
|
|
messages.success(self.request, "Project %s has been removed." % self.get_object().name, extra_tags="alert alert-success")
|
|
|
|
|
|
return super(ProjectDeleteView, self).post(*args, **kwargs)
|