Commit 85ae443d by Oláh István Gergely

views: add remove_trait to NodeDetailView

parent 3706a11a
...@@ -457,6 +457,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -457,6 +457,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return self.__set_status(request) return self.__set_status(request)
if request.POST.get('new_trait'): if request.POST.get('new_trait'):
return self.__add_trait(request) return self.__add_trait(request)
if request.POST.get('to_remove'):
return self.__remove_trait(request)
def __set_name(self, request): def __set_name(self, request):
self.object = self.get_object() self.object = self.get_object()
...@@ -525,6 +527,22 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -525,6 +527,22 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return redirect(reverse_lazy("dashboard.views.node-detail", return redirect(reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.object.pk})) kwargs={'pk': self.object.pk}))
def __remove_trait(self, request):
try:
to_remove = request.POST.get('to_remove')
self.object = self.get_object()
self.object.tags.remove(to_remove)
message = u"Success"
except: # note this won't really happen
message = u"Not success"
if request.is_ajax():
return HttpResponse(
json.dumps({'message': message}),
content_type="application=json"
)
class GroupDetailView(CheckedDetailView): class GroupDetailView(CheckedDetailView):
template_name = "dashboard/group-detail.html" template_name = "dashboard/group-detail.html"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment