diff --git a/conntrackt/templates/conntrackt/location_widget.html b/conntrackt/templates/conntrackt/location_widget.html --- a/conntrackt/templates/conntrackt/location_widget.html +++ b/conntrackt/templates/conntrackt/location_widget.html @@ -10,13 +10,13 @@ {% html_link entity.name 'entity' entity.id class="btn btn-link" %} {% html_link '' 'entity_iptables' entity.id class="btn btn-link" %} - {% html_link '' 'entity_update' entity.id class="btn btn-link" %} - {% html_link '' 'entity_delete' entity.id class="btn btn-link" %} + {% html_link '' 'entity_update' entity.id class="btn btn-link" get="next="|add:request.path %} + {% html_link '' 'entity_delete' entity.id class="btn btn-link" get="next="|add:request.path %} {% endfor %} {% with project_id=project.id|slugify location_id=location.id|slugify %} - {% html_link "Add entity" "entity_create" class="btn btn-primary btn-mini" get="project="|add:project_id|add:"&location="|add:location_id %} + {% html_link "Add entity" "entity_create" class="btn btn-primary btn-mini" get="project="|add:project_id|add:"&location="|add:location_id|add:"&next="|add:request.path %} diff --git a/conntrackt/templates/conntrackt/project_detail.html b/conntrackt/templates/conntrackt/project_detail.html --- a/conntrackt/templates/conntrackt/project_detail.html +++ b/conntrackt/templates/conntrackt/project_detail.html @@ -23,8 +23,8 @@ {% html_link "Edit" "project_update" project.id class="btn btn-primary" %} {% html_link "Remove" "project_delete" project.id class="btn btn-primary" %} {% with project_id=project.id|slugify %} - {% html_link "Add entity" "entity_create" class="btn btn-primary" get="project="|add:project_id %} - {% html_link "Add communication" "communication_create" class="btn btn-primary" get="project="|add:project_id %} + {% html_link "Add entity" "entity_create" class="btn btn-primary" get="project="|add:project_id|add:"&next="|add:request.path %} + {% html_link "Add communication" "communication_create" class="btn btn-primary" get="project="|add:project_id|add:"&next="|add:request.path %} {% endwith %} diff --git a/conntrackt/views.py b/conntrackt/views.py --- a/conntrackt/views.py +++ b/conntrackt/views.py @@ -269,7 +269,7 @@ def project_iptables(request, project_id return response -class ProjectCreateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): +class ProjectCreateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): """ View for creating a new project. """ @@ -288,7 +288,7 @@ class ProjectCreateView(SetHeadlineMixin raise_exception = True -class ProjectUpdateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): +class ProjectUpdateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): """ View for modifying an existing project. """ @@ -313,7 +313,7 @@ class ProjectUpdateView(SetHeadlineMixin return "Update project %s" % self.object.name -class ProjectDeleteView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): +class ProjectDeleteView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): """ View for deleting a project. """ @@ -349,7 +349,7 @@ class ProjectDeleteView(SetHeadlineMixin return "Delete project %s" % self.object.name -class LocationCreateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): +class LocationCreateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): """ View for creating a new location. """ @@ -370,7 +370,7 @@ class LocationCreateView(SetHeadlineMixi success_url = reverse_lazy("index") -class LocationUpdateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): +class LocationUpdateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): """ View for modifying an existing location. """ @@ -397,7 +397,7 @@ class LocationUpdateView(SetHeadlineMixi return "Update location %s" % self.object.name -class LocationDeleteView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): +class LocationDeleteView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): """ View for deleting a location. """ @@ -433,7 +433,7 @@ class LocationDeleteView(SetHeadlineMixi return "Delete location %s" % self.object.name -class EntityCreateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): +class EntityCreateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): """ View for creating a new entity. """ @@ -489,7 +489,7 @@ class EntityCreateView(SetHeadlineMixin, return initial -class EntityUpdateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): +class EntityUpdateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): """ View for updating an existing entity. """ @@ -514,7 +514,7 @@ class EntityUpdateView(SetHeadlineMixin, return "Update entity %s" % self.object.name -class EntityDeleteView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): +class EntityDeleteView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): """ View for deleting an entity. """ @@ -560,7 +560,7 @@ class EntityDeleteView(SetHeadlineMixin, return "Delete entity %s" % self.object.name -class InterfaceCreateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): +class InterfaceCreateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): """ View for creating a new interface. """ @@ -619,7 +619,7 @@ class InterfaceCreateView(SetHeadlineMix return reverse("entity", args=(self.object.entity.pk,)) -class InterfaceUpdateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): +class InterfaceUpdateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): """ View for updating an existing interface. """ @@ -670,7 +670,7 @@ class InterfaceUpdateView(SetHeadlineMix return "Update interface %s" % self.object.name -class InterfaceDeleteView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): +class InterfaceDeleteView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): """ View for deleting an interface. """ @@ -716,7 +716,7 @@ class InterfaceDeleteView(SetHeadlineMix return "Delete interface %s" % self.object.name -class CommunicationCreateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): +class CommunicationCreateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, CreateView): """ View for creating a new communication. """ @@ -798,10 +798,17 @@ class CommunicationCreateView(SetHeadlin to project page to which the communication belongs. """ - return self.request.GET.get("next", reverse("project", args=(self.object.source.entity.project.pk,))) + # We must set the success URL to something first. + self.success_url = reverse("project", args=(self.object.source.entity.project.pk,)) + + # This will override the URL if parameter "next" was provided (from + # RedirectToNextMixin). + success_url = super(CommunicationCreateView, self).get_success_url() + + return success_url -class CommunicationUpdateView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): +class CommunicationUpdateView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, UpdateView): """ View for updating an existing communication. """ @@ -856,7 +863,7 @@ class CommunicationUpdateView(SetHeadlin return "Update communication %s" % self.object -class CommunicationDeleteView(SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): +class CommunicationDeleteView(RedirectToNextMixin, SetHeadlineMixin, MultiplePermissionsRequiredMixin, DeleteView): """ View for deleting an communication. """