# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2019 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
from django.contrib import admin
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
from geonode_logstash.models import CentralizedServer
from geonode_logstash.logstash import LogstashDispatcher
[docs]
csrf_protect_m = method_decorator(csrf_protect)
@admin.register(CentralizedServer)
[docs]
class CentralizedServerAdmin(admin.ModelAdmin):
[docs]
list_display = (
'host', 'port', 'interval', 'last_successful_deliver',
'next_scheduled_deliver', 'last_failed_deliver'
)
[docs]
list_filter = ('host', )
[docs]
readonly_fields = [
'last_successful_deliver', 'next_scheduled_deliver', 'last_failed_deliver'
]
[docs]
def _test_connection(self, host, port):
ld = LogstashDispatcher()
ld.test_dispatch(host, port)
@csrf_protect_m
[docs]
def has_add_permission(self, request):
# Avoid adding more than one record
base_add_permission = super(CentralizedServerAdmin, self).has_add_permission(request)
if base_add_permission:
if CentralizedServer.objects.count():
return False
return True