Skip to content

Commit

Permalink
Merge pull request #601 from decryptus/master
Browse files Browse the repository at this point in the history
Missed custom check plugins list in many views
  • Loading branch information
frankh authored Jun 7, 2018
2 parents bae1719 + 82ca56a commit 4e4ca0a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 27 deletions.
88 changes: 64 additions & 24 deletions cabot/cabotapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.validators import URLValidator
from django.db import transaction
Expand Down Expand Up @@ -54,6 +55,7 @@ def subscriptions(request):
'services': services,
'users': users,
'duty_officers': get_duty_officers(),
'custom_check_types': get_custom_check_plugins(),
})


Expand Down Expand Up @@ -94,7 +96,35 @@ def duplicate_jenkins_check(request, pk):
return HttpResponseRedirect(reverse('update-jenkins-check', kwargs={'pk': npk}))


class StatusCheckResultDetailView(LoginRequiredMixin, DetailView):
class BaseCommonView(object):
def render_to_response(self, context, *args, **kwargs):
if context is None:
context = {}
context['custom_check_types'] = get_custom_check_plugins()
return super(BaseCommonView, self).render_to_response(context, *args, **kwargs)


class CommonCreateView(BaseCommonView, CreateView):
pass


class CommonUpdateView(BaseCommonView, UpdateView):
pass


class CommonDeleteView(BaseCommonView, DeleteView):
pass


class CommonDetailView(BaseCommonView, DetailView):
pass


class CommonListView(BaseCommonView, ListView):
pass


class StatusCheckResultDetailView(LoginRequiredMixin, CommonDetailView):
model = StatusCheckResult
context_object_name = 'result'

Expand Down Expand Up @@ -415,7 +445,7 @@ def get_report(self):
return checks


class CheckCreateView(LoginRequiredMixin, CreateView):
class CheckCreateView(LoginRequiredMixin, CommonCreateView):
template_name = 'cabotapp/statuscheck_form.html'

def form_valid(self, form):
Expand Down Expand Up @@ -457,7 +487,7 @@ def get_success_url(self):
return reverse('checks')


class CheckUpdateView(LoginRequiredMixin, UpdateView):
class CheckUpdateView(LoginRequiredMixin, CommonUpdateView):
template_name = 'cabotapp/statuscheck_form.html'

def get_success_url(self):
Expand Down Expand Up @@ -512,36 +542,46 @@ def form_valid(self, form):
return super(JenkinsCheckUpdateView, self).form_valid(form)


class StatusCheckListView(LoginRequiredMixin, ListView):
class StatusCheckListView(LoginRequiredMixin, CommonListView):
model = StatusCheck

def render_to_response(self, context, *args, **kwargs):
context = super(StatusCheckListView, self).get_context_data(**kwargs)
if context is None:
context = {}
context['custom_check_types'] = get_custom_check_plugins()
context['checks'] = StatusCheck.objects.all().order_by('name').prefetch_related('service_set', 'instance_set')
return super(StatusCheckListView, self).render_to_response(context, *args, **kwargs)


class StatusCheckDeleteView(LoginRequiredMixin, DeleteView):
class StatusCheckDeleteView(LoginRequiredMixin, CommonDeleteView):
model = StatusCheck
success_url = reverse_lazy('checks')
context_object_name = 'check'
template_name = 'cabotapp/statuscheck_confirm_delete.html'


class StatusCheckDetailView(LoginRequiredMixin, DetailView):
class StatusCheckDetailView(LoginRequiredMixin, CommonDetailView):
model = StatusCheck
context_object_name = 'check'
template_name = 'cabotapp/statuscheck_detail.html'

def render_to_response(self, context, *args, **kwargs):
if context is None:
context = {}
context['custom_check_types'] = get_custom_check_plugins()
context['checkresults'] = self.object.statuscheckresult_set.order_by(
'-time_complete')[:100]
checkresult_list = self.object.statuscheckresult_set.order_by(
'-time_complete').all()
paginator = Paginator(checkresult_list, 25)

page = self.request.GET.get('page')
try:
checkresults = paginator.page(page)
except PageNotAnInteger:
checkresults = paginator.page(1)
except EmptyPage:
checkresults = paginator.page(paginator.num_pages)

context['checkresults'] = checkresults

return super(StatusCheckDetailView, self).render_to_response(context, *args, **kwargs)


Expand Down Expand Up @@ -581,6 +621,7 @@ def get(self, request, pk, alerttype):
return render(request, self.template.template.name, {
'form': form,
'alert_preferences': profile.user_data(),
'custom_check_types': get_custom_check_plugins(),
})

def post(self, request, pk, alerttype):
Expand Down Expand Up @@ -634,7 +675,8 @@ def get(self, request, plugin_name):
'form': form,
'plugins': AlertPlugin.objects.all(),
'plugin_name': plugin_name,
'alert_test_form': alert_test_form
'alert_test_form': alert_test_form,
'custom_check_types': get_custom_check_plugins()
})

def post(self, request, plugin_name):
Expand Down Expand Up @@ -798,15 +840,15 @@ class GeneralSettingsForm(forms.Form):
enabled = forms.BooleanField(label='Enabled', required=False)


class InstanceListView(LoginRequiredMixin, ListView):
class InstanceListView(LoginRequiredMixin, CommonListView):
model = Instance
context_object_name = 'instances'

def get_queryset(self):
return Instance.objects.all().order_by('name').prefetch_related('status_checks')


class ServiceListView(LoginRequiredMixin, ListView):
class ServiceListView(LoginRequiredMixin, CommonListView):
model = Service
context_object_name = 'services'

Expand All @@ -826,14 +868,13 @@ def get_context_data(self, **kwargs):
.order_by(Lower('name')).prefetch_related('status_checks')
return context

class InstanceDetailView(LoginRequiredMixin, DetailView):
class InstanceDetailView(LoginRequiredMixin, CommonDetailView):
model = Instance
context_object_name = 'instance'

def get_context_data(self, **kwargs):
context = super(InstanceDetailView, self).get_context_data(**kwargs)
date_from = date.today() - relativedelta(day=1)
context['custom_check_types'] = get_custom_check_plugins()
context['report_form'] = StatusCheckReportForm(initial={
'checks': self.object.status_checks.all(),
'service': self.object,
Expand All @@ -843,14 +884,13 @@ def get_context_data(self, **kwargs):
return context


class ServiceDetailView(LoginRequiredMixin, DetailView):
class ServiceDetailView(LoginRequiredMixin, CommonDetailView):
model = Service
context_object_name = 'service'

def get_context_data(self, **kwargs):
context = super(ServiceDetailView, self).get_context_data(**kwargs)
date_from = date.today() - relativedelta(day=1)
context['custom_check_types'] = get_custom_check_plugins()
context['report_form'] = StatusCheckReportForm(initial={
'alerts': self.object.alerts.all(),
'checks': self.object.status_checks.all(),
Expand All @@ -861,7 +901,7 @@ def get_context_data(self, **kwargs):
return context


class InstanceCreateView(LoginRequiredMixin, CreateView):
class InstanceCreateView(LoginRequiredMixin, CommonCreateView):
model = Instance
form_class = InstanceForm

Expand Down Expand Up @@ -916,7 +956,7 @@ def remove_acknowledgement(request, pk):
return HttpResponseRedirect(reverse('service', kwargs={'pk': pk}))


class ServiceCreateView(LoginRequiredMixin, CreateView):
class ServiceCreateView(LoginRequiredMixin, CommonCreateView):
model = Service
form_class = ServiceForm

Expand All @@ -927,37 +967,37 @@ def get_success_url(self):
return reverse('service', kwargs={'pk': self.object.id})


class InstanceUpdateView(LoginRequiredMixin, UpdateView):
class InstanceUpdateView(LoginRequiredMixin, CommonUpdateView):
model = Instance
form_class = InstanceForm

def get_success_url(self):
return reverse('instance', kwargs={'pk': self.object.id})


class ServiceUpdateView(LoginRequiredMixin, UpdateView):
class ServiceUpdateView(LoginRequiredMixin, CommonUpdateView):
model = Service
form_class = ServiceForm

def get_success_url(self):
return reverse('service', kwargs={'pk': self.object.id})


class ServiceDeleteView(LoginRequiredMixin, DeleteView):
class ServiceDeleteView(LoginRequiredMixin, CommonDeleteView):
model = Service
success_url = reverse_lazy('services')
context_object_name = 'service'
template_name = 'cabotapp/service_confirm_delete.html'


class InstanceDeleteView(LoginRequiredMixin, DeleteView):
class InstanceDeleteView(LoginRequiredMixin, CommonDeleteView):
model = Instance
success_url = reverse_lazy('instances')
context_object_name = 'instance'
template_name = 'cabotapp/instance_confirm_delete.html'


class ShiftListView(LoginRequiredMixin, ListView):
class ShiftListView(LoginRequiredMixin, CommonListView):
model = Shift
context_object_name = 'shifts'

Expand Down
2 changes: 1 addition & 1 deletion cabot/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<!-- Custom check plugins buttons-->
{% for checktype in custom_check_types %}
<li>
<a href="{% url checktype.creation_url %}?service={{ service.id }}&instance={{ instance.id }}" class="" title="Add new {{checktype.check_name|capfirst}} check"><i class="glyphicon glyphicon-transfer"></i> {{checktype.check_name|capfirst}} check</a>
<a href="{% url checktype.creation_url %}?service={{ service.id }}&instance={{ instance.id }}" class="" title="Add new {{checktype.check_name|capfirst}} check"><i class="glyphicon {{checktype.icon_class|default:"glyphicon-ok"}}"></i> {{checktype.check_name|capfirst}} check</a>
</li>
{% endfor %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion cabot/templates/cabotapp/_statuscheck_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row">
<div class="col-xs-12">
<div class="col-xs-1"><h3><i class="{% if checks_type == "All" %}fa fa-cog{% else %}glyphicon glyphicon-{% if checks_type == "Http" %}arrow-up{% elif checks_type == "Jenkins" %}ok{% elif checks_type == "ICMP" %}transfer{% else %}signal{% endif %}{% endif %}"></i></h3></div>
<div class="col-xs-3"><h3>{{ checks_type }} checks</h3></div>
<div class="col-xs-3"><h3>{{ checks_type|capfirst }} checks</h3></div>
<div class="col text-right">
<h3>
&nbsp;{% if checks_type == "All" or checks_type == "Graphite" %}
Expand Down
23 changes: 22 additions & 1 deletion cabot/templates/cabotapp/statuscheck_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,28 @@ <h2>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-1"><h3><i class="fa fa-list"></i></h3></div>
<div class="col-xs-11"><h3>Check results</h3></div>
<div class="col-xs-11">
<h3 class="pull-left">Check results</h3>

{% if checkresults and checkresults.paginator.num_pages > 1 %}
<ul class="pagination pagination-sm pull-right">
{% if checkresults.has_previous %}
<li class="page-item"><a class="page-link" href="?page=1">&laquo;</a></li>
<li class="page-item"><a class="page-link" href="?page={{ checkresults.previous_page_number }}">{{ checkresults.previous_page_number }}</a></li>
{% else %}
<li class="page-item disabled"><a class="page-link" href="#">&laquo;</a></li>
{% endif %}
<li class="page-item active"><a class="page-link">{{ checkresults.number }}</a></li>
{% if checkresults.has_next %}
<li class="page-item"><a class="page-link" href="?page={{ checkresults.next_page_number }}">{{ checkresults.next_page_number }}</a></li>
<li class="page-item"><a class="page-link" href="?page={{ checkresults.paginator.num_pages }}">&raquo;</a></li>
{% else %}
<li class="page-item disabled"><a class="page-link" href="#">&raquo;</a></li>
{% endif %}
</ul>
{% endif %}

</div>
</div>
<div class="col-xs-12">
{% if not checkresults %}
Expand Down

0 comments on commit 4e4ca0a

Please sign in to comment.