Add 'restart datasync' button to datasync changes list page.
This commit is contained in:
parent
6b9727d7cb
commit
b78b49d79e
|
@ -55,14 +55,15 @@ class TailboneAuthorizationPolicy(object):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
def add_permission_group(config, key, label=None):
|
def add_permission_group(config, key, label=None, overwrite=True):
|
||||||
"""
|
"""
|
||||||
Add a permission group to the app configuration.
|
Add a permission group to the app configuration.
|
||||||
"""
|
"""
|
||||||
def action():
|
def action():
|
||||||
perms = config.get_settings().get('tailbone_permissions', {})
|
perms = config.get_settings().get('tailbone_permissions', {})
|
||||||
group = perms.setdefault(key, {'key': key})
|
if key not in perms or overwrite:
|
||||||
group['label'] = label or prettify(key)
|
group = perms.setdefault(key, {'key': key})
|
||||||
|
group['label'] = label or prettify(key)
|
||||||
config.add_settings({'tailbone_permissions': perms})
|
config.add_settings({'tailbone_permissions': perms})
|
||||||
config.action(None, action)
|
config.action(None, action)
|
||||||
|
|
||||||
|
|
25
tailbone/templates/datasync/changes/index.mako
Normal file
25
tailbone/templates/datasync/changes/index.mako
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
## -*- coding: utf-8 -*-
|
||||||
|
<%inherit file="/master/index.mako" />
|
||||||
|
|
||||||
|
<%def name="head_tags()">
|
||||||
|
${parent.head_tags()}
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
$('form[name="restart-datasync"]').submit(function() {
|
||||||
|
$(this).find('button')
|
||||||
|
.button('option', 'label', "Restarting DataSync...")
|
||||||
|
.button('disable');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="grid_tools()">
|
||||||
|
${h.form(url('datasync.restart'), name='restart-datasync')}
|
||||||
|
<button type="submit">Restart DataSync Daemon</button>
|
||||||
|
${h.end_form()}
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
${parent.body()}
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2015 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,20 +24,29 @@
|
||||||
DataSync Views
|
DataSync Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import logging
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
from rattail.config import parse_list
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
from tailbone.views import MasterView
|
from tailbone.views import MasterView
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DataSyncChangeView(MasterView):
|
class DataSyncChangeView(MasterView):
|
||||||
"""
|
"""
|
||||||
Master view for the DataSyncChange model.
|
Master view for the DataSyncChange model.
|
||||||
"""
|
"""
|
||||||
model_class = model.DataSyncChange
|
model_class = model.DataSyncChange
|
||||||
model_title = "DataSync Change"
|
model_title = "DataSync Change"
|
||||||
|
url_prefix = '/datasync/changes'
|
||||||
|
permission_prefix = 'datasync'
|
||||||
|
|
||||||
creatable = False
|
creatable = False
|
||||||
viewable = False
|
viewable = False
|
||||||
|
@ -58,6 +67,27 @@ class DataSyncChangeView(MasterView):
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
|
def restart(self):
|
||||||
|
# TODO: Add better validation (e.g. CSRF) here?
|
||||||
|
if self.request.method == 'POST':
|
||||||
|
cmd = parse_list(self.rattail_config.require('tailbone', 'datasync.restart'))
|
||||||
|
log.debug("attempting datasync restart with command: {}".format(cmd))
|
||||||
|
result = subprocess.call(cmd)
|
||||||
|
if result == 0:
|
||||||
|
self.request.session.flash("DataSync daemon has been restarted.")
|
||||||
|
else:
|
||||||
|
self.request.session.flash("DataSync daemon could not be restarted; result was: {}".format(result), 'error')
|
||||||
|
return self.redirect(self.request.route_url('datasyncchanges'))
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
|
|
||||||
|
config.add_tailbone_permission_group('datasync', label="DataSync")
|
||||||
|
|
||||||
|
# restart daemon
|
||||||
|
config.add_route('datasync.restart', '/datasync/restart')
|
||||||
|
config.add_view(DataSyncChangeView, attr='restart', route_name='datasync.restart',
|
||||||
|
permission='datasync.restart')
|
||||||
|
config.add_tailbone_permission('datasync', 'datasync.restart', label="Restart DataSync Daemon")
|
||||||
|
|
||||||
DataSyncChangeView.defaults(config)
|
DataSyncChangeView.defaults(config)
|
||||||
|
|
|
@ -608,7 +608,7 @@ class MasterView(View):
|
||||||
model_title = cls.get_model_title()
|
model_title = cls.get_model_title()
|
||||||
model_title_plural = cls.get_model_title_plural()
|
model_title_plural = cls.get_model_title_plural()
|
||||||
|
|
||||||
config.add_tailbone_permission_group(permission_prefix, model_title_plural)
|
config.add_tailbone_permission_group(permission_prefix, model_title_plural, overwrite=False)
|
||||||
|
|
||||||
# list/search
|
# list/search
|
||||||
config.add_route(route_prefix, '{0}/'.format(url_prefix))
|
config.add_route(route_prefix, '{0}/'.format(url_prefix))
|
||||||
|
|
Loading…
Reference in a new issue