Skip to content

Commit

Permalink
Fix reference to self.get_object() in RuleToggle
Browse files Browse the repository at this point in the history
(cherry picked from commit c7f2668)
  • Loading branch information
kfdm committed Sep 4, 2018
1 parent 5ae26dd commit df6e079
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from django.utils.translation import ugettext as _
from django.views.generic import DetailView, ListView, UpdateView, View
from django.views.generic.base import ContextMixin, RedirectView, TemplateView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import DeleteView, FormView
from prometheus_client import Gauge, generate_latest
from promgen import (celery, discovery, forms, models, plugins, prometheus,
Expand Down Expand Up @@ -319,7 +320,9 @@ def get_success_url(self):
return self.object.content_object.get_absolute_url()


class RuleToggle(PromgenPermissionMixin, View):
class RuleToggle(PromgenPermissionMixin, SingleObjectMixin, View):
model = models.Rule

def get_permission_denied_message(self):
return 'Unable to toggle rule %s. User lacks permission' % self.object

Expand All @@ -334,10 +337,9 @@ def get_permission_required(self):
yield '{}.change_{}'.format(tgt.app_label, tgt.model_name)

def post(self, request, pk):
rule = get_object_or_404(models.Rule, id=pk)
rule.enabled = not rule.enabled
rule.save()
return JsonResponse({'redirect': rule.content_object.get_absolute_url()})
self.object.enabled = not self.object.enabled
self.object.save()
return JsonResponse({'redirect': self.object.content_object.get_absolute_url()})


class HostDelete(LoginRequiredMixin, DeleteView):
Expand Down

0 comments on commit df6e079

Please sign in to comment.